WHEN 45
PROCcore_prepare_args("h*", "assoc")
=FNcore_assoc(args%(0), args%)
+ DATA dissoc, 46
+ WHEN 46
+ PROCcore_prepare_args("h*", "dissoc")
+ WHILE NOT FNis_empty(args%)
+ args%(0) = FNhashmap_remove(args%(0), FNunbox_string(FNfirst(args%)))
+ args% = FNrest(args%)
+ ENDWHILE
+ =args%(0)
DATA get, 47
WHEN 47
IF FNis_nil(FNfirst(args%)) THEN =FNnil
WHEN 49
PROCcore_prepare_args("h", "keys")
=FNhashmap_keys(args%(0))
+ DATA vals, 50
+ WHEN 50
+ PROCcore_prepare_args("h", "vals")
+ =FNhashmap_vals(args%(0))
DATA "", -1
ENDCASE
ERROR &40E809F1, "Call to non-existent core function"
=FNhashmap_alloc_node(Z%(map%,0)>>16, FNhashmap_set(Z%(map%,1), key$, val%), Z%(map%,2))
ENDIF
+DEF FNhashmap_remove(map%, key$)
+ LOCAL child%
+ IF FNis_empty_hashmap(map%) THEN =map%
+ IF FNtype_of(map%) = &0A THEN
+ IF S$(Z%(map%,1)) = key$ THEN =FNempty_hashmap
+ ENDIF
+ IF FNkey_bit(key$, Z%(map%,0) >> 16) THEN
+ child% = FNhashmap_remove(Z%(map%,2), key$)
+ IF FNis_empty_hashmap(child%) THEN =Z%(map%,1)
+ =FNhashmap_alloc_node(Z%(map%,0)>>16, Z%(map%,1), child%)
+ ELSE
+ child% = FNhashmap_remove(Z%(map%,1), key$)
+ IF FNis_empty_hashmap(child%) THEN =Z%(map%,2)
+ =FNhashmap_alloc_node(Z%(map%,0)>>16, child%, Z%(map%,2))
+ ENDIF
+
+
DEF FNhashmap_get(map%, key$)
IF NOT FNis_hashmap(map%) THEN ERROR &40E80918, "Can't get item from a non-hashmap"
IF FNis_empty_hashmap(map%) THEN =FNnil
ENDIF
=FNhashmap_keys1(Z%(map%,2), FNhashmap_keys1(Z%(map%,1), acc%))
+DEF FNhashmap_vals(map%)
+=FNhashmap_vals1(map%, FNempty)
+
+DEF FNhashmap_vals1(map%, acc%)
+ REM PROChashmap_dump(map%)
+ IF FNis_empty_hashmap(map%) THEN =acc%
+ IF FNtype_of(map%) = &0A THEN
+ =FNalloc_pair(Z%(map%,2), acc%)
+ ENDIF
+=FNhashmap_vals1(Z%(map%,2), FNhashmap_vals1(Z%(map%,1), acc%))
+
DEF PROChashmap_dump(map%)
IF FNis_empty_hashmap(map%) THEN
PRINT "[empty]"