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 support
2+
3+# Hash literal
4+h = {}
5+h["one"] = 1
6+h["two"] = 2
7+h["three"] = 3
8+puts h["two"] # 2
9+puts h.length # 3
10+
11+# Iteration
12+h.each do |k, v|
13+ puts k
14+end
15+
16+# keys
17+puts h.keys.length # 3
18+
19+# has_key?
20+if h.has_key?("two")
21+ puts "found"
22+end
23+
24+# delete
25+h.delete("two")
26+puts h.length # 2