feat: add initial Map class with hash table, subscript, and count support

Implement the core Map data structure in Wren, including the ObjMap type with
hash table storage, native methods for instantiation, subscript get/set, and
count. Add Map class declaration to core.wren with a basic toString stub.
Introduce MapEntry struct and hash table growth logic with configurable load
factor. Add test files for map creation, count tracking, key type support
(including null, bool, num, string, range, and class keys), and growth
behavior. Refactor list capacity constants into shared MIN_CAPACITY and
GROW_FACTOR macros. Change object equality operators to use wrenValuesSame
instead of wrenValuesEqual.
This commit is contained in:
Bob Nystrom
2015-01-25 06:27:35 +00:00
parent 3f0aceeffa
commit 5c33ecc04f
11 changed files with 541 additions and 54 deletions
+12
View File
@@ -0,0 +1,12 @@
var map = new Map
IO.print(map.count) // expect: 0
map["one"] = "value"
IO.print(map.count) // expect: 1
map["two"] = "value"
IO.print(map.count) // expect: 2
map["three"] = "value"
IO.print(map.count) // expect: 3
// Adding existing key does not increase count.
map["two"] = "new value"
IO.print(map.count) // expect: 3