Commit f43f48b6
f43f48b6b12fMerged
Yukihiro "Matz" Matsumoto <[email protected]> · 8 months ago · 3 files · +1 added · ~2 modified
Description
Add Hash support (string keys, integer values)
Built-in sp_StrIntHash with chained hash table:
- Insertion-order linked list for Ruby-compatible each iteration
- Operations: new, []=, [], length, has_key?, delete, each
- GC-integrated with finalizer for cleanup
- h.keys.length optimized to h.length
Test: examples/bm_hash.rb — literal creation, set/get, iteration, has_key?, delete. Output matches Ruby.
All regressions pass.
Co-Authored-By: Claude Opus 4.6 (1M context) [email protected]
Details
- Commit
- f43f48b6b12f
- Parent
- 4be27959fa4c
examples/bm_hash.rbaddedView file
1+
# Test Hash support2+
3+
# Hash literal4+
h = {}5+
h["one"] = 16+
h["two"] = 27+
h["three"] = 38+
puts h["two"] # 29+
puts h.length # 310+
11+
# Iteration12+
h.each do |k, v|13+
puts k14+
end15+
16+
# keys17+
puts h.keys.length # 318+
19+
# has_key?20+
if h.has_key?("two")21+
puts "found"22+
end23+
24+
# delete25+
h.delete("two")26+
puts h.length # 2src/codegen.cmodifiedView file
Loading diff…
src/codegen.hmodifiedView file
Loading diff…