1 // Implement our old naive O
(n
) map because Yeti's hash table
(h_new
()) cannot
2 // be used inside arrays and structs
(we can't get a pointer to hash table
).
3 // This prevents saving pointer to environment in MalFunction for example.
12 return Hash
(keys
=&[], vals=&[])
17 for
(i
= 1; i
<= numberof
(*h.keys
); ++i
) {
18 if
((*h.keys
)(i
) == key
) return
*((*h.vals
)(i
))
23 func hash_has_key
(h
, key
)
25 for
(i
= 1; i
<= numberof
(*h.keys
); ++i
) {
26 if
((*h.keys
)(i
) == key
) return
1
31 func hash_set
(&h, key, val)
33 if
(is_void
(*h.keys
)) {
38 for
(i
= 1; i
<= numberof
(*h.keys
); ++i
) {
39 if
((*h.keys
)(i
) == key
) {
52 func hash_delete
(&h, key)
54 if
(is_void
(*h.keys
) || numberof
(*h.keys
) == 0) return
57 if
(numberof
(k
) == 1) {
64 for
(i
= 1; i
<= numberof
(k
); ++i
) {
69 } else if
(i
== numberof
(k
)) {
73 h.keys
= &grow(k(1:i-1), k(i+1:))
74 h.vals
= &grow(v(1:i-1), v(i+1:))