10
10
11
11
Insertion-ordered hash table suitable for embedding via FFI.
12
12
13
- Drop-in replacement for ` st_hash ` originally written by Peter Moore @ UCB and
14
- used in [ Ruby] 's [ implementation] [ st.c ] of the [ ` Hash ` ] [ hash ] core class.
13
+ Status: Work in progress.
14
+
15
+ Strudel was conceived as a drop-in replacement for ` st_hash ` , a hash map
16
+ implemented in C originally written by Peter Moore @ UCB and used in [ Ruby] 's
17
+ [ implementation] [ st.c ] of the [ ` Hash ` ] [ hash ] core class.
18
+
19
+ This crate is an exercise in implementing an insertion-ordered hash map in Rust
20
+ that cannot use the built-in ` Hasher ` infrastructure. The implementation uses
21
+ [ Ruby's ` Hash ` backend] [ sthash-notes ] and [ Python's dict] [ pydict-notes ] as prior
22
+ art.
15
23
16
24
` StHashMap ` is designed to implement the ` st_hash ` C API and be FFI-friendly.
17
25
@@ -47,6 +55,32 @@ All features are enabled by default.
47
55
- ** capi-specialized-init** - Enables additional ` st_init_table ` C APIs with
48
56
known ` st_hash_type ` s for tables with numeric and string keys.
49
57
58
+ ## Building Ruby with Strudel
59
+
60
+ Strudel exports most of the symbols implemented by ` st.c ` in MRI 2.6.3. The
61
+ [ included patch] ( strudelify-mri.patch ) and some
62
+ [ ` configure ` arguments] ( build.sh ) can build the bootstrapping phase of MRI 2.6.3
63
+ with Strudel as the hash backend.
64
+
65
+ To build ` miniruby ` with Strudel, run:
66
+
67
+ ``` sh
68
+ ./build.sh
69
+ ```
70
+
71
+ The resulting Ruby is in ` ./build/ruby-strudel-build-root/miniruby ` . ` miniruby `
72
+ can run simple scripts involving ` Hash ` , for example:
73
+
74
+ ``` console
75
+ $ ./build/ruby-strudel-build-root/miniruby -e ' h = {}' -e ' 1000.times { |i| h[i] = i }' -e ' puts h.length'
76
+ 1000
77
+ ```
78
+
79
+ ` miniruby ` successfully executes the benchmarks in [ ` benches ` ] ( benches ) .
80
+
81
+ NOTE: Strudel cannot build a full Ruby due to bugs in the implementation of the
82
+ ` st_hash ` API.
83
+
50
84
## License
51
85
52
86
` strudel ` is licensed under the [ MIT License] ( LICENSE ) (c) Ryan Lopopolo.
@@ -67,6 +101,9 @@ The `st_hash` implementation in Ruby includes the following notice:
67
101
[ ruby ] : https://github.com/ruby/ruby
68
102
[ st.c ] : https://github.com/ruby/ruby/blob/v2_6_3/st.c
69
103
[ hash ] : https://ruby-doc.org/core-2.6.3/Hash.html
104
+ [ sthash-notes ] : https://github.com/ruby/ruby/blob/v2_6_3/st.c#L1-L101
105
+ [ pydict-notes] :
106
+ https://github.com/python/cpython/blob/v3.8.4/Objects/dictobject.c#L1-L110
70
107
[ `hashmap` ] : https://doc.rust-lang.org/std/collections/struct.HashMap.html
71
108
[ `vec` ] : https://doc.rust-lang.org/std/vec/struct.Vec.html
72
109
[ `libc` ] : https://crates.io/crates/libc
0 commit comments