core: Allow non-string hash keys.
This merely allows adding non-string keys to a hash table and puts them non-string keys in bucket 0. Efficiency is lost. TODO: calculate a proper hash. * src/hash.c (hash_): Allow non-string keys in bucket 0. * tests/hash.test: Add a test. Co-authored-by: Timothy Sample <samplet@ngyro.com>
This commit is contained in:
parent
0a905d54d7
commit
9a5de02f42
10
src/hash.c
10
src/hash.c
|
@ -46,13 +46,9 @@ hashq_ (struct scm *x, long size)
|
|||
int
|
||||
hash_ (struct scm *x, long size)
|
||||
{
|
||||
if (x->type != TSTRING)
|
||||
{
|
||||
eputs ("hash_ failed, not a string:");
|
||||
display_error_ (x);
|
||||
assert_msg (0, "0");
|
||||
}
|
||||
return hash_cstring (cell_bytes (x->string), size);
|
||||
if (x->type == TSTRING)
|
||||
return hash_cstring (cell_bytes (x->string), size);
|
||||
return 0;
|
||||
}
|
||||
|
||||
struct scm *
|
||||
|
|
|
@ -80,4 +80,11 @@ exec ${MES-bin/mes} --no-auto-compile -L ${0%/*} -L module -C module -e '(tests
|
|||
(= (assoc-ref a "second") 2)
|
||||
(= (assoc-ref a "third") 3)))))
|
||||
|
||||
(pass-if "integer keys"
|
||||
(let ((t (make-hash-table)))
|
||||
(hash-set! t 21 'a)
|
||||
(hash-set! t 42 'b)
|
||||
(and (eq? (hash-ref t 42) 'b)
|
||||
(eq? (hash-ref t 21) 'a))))
|
||||
|
||||
(result 'report)
|
||||
|
|
Loading…
Reference in New Issue