core: Add hashq_set_handle_x.

* src/hash.c (hash_set_x_): Return handle instead of value.  Update
callers and and use it in ...
(hashq_set_handle_x): New function.
* include/mes/builtins.h: Declare it.
This commit is contained in:
Jan Nieuwenhuizen 2019-11-14 09:14:31 +01:00 committed by Jan (janneke) Nieuwenhuizen
parent 9b1aacdebd
commit ecc883144f
No known key found for this signature in database
GPG Key ID: F3C1A0D9C1D65273
3 changed files with 17 additions and 3 deletions

View File

@ -67,6 +67,7 @@ struct scm *hash (struct scm *x, struct scm *size);
struct scm *hashq_get_handle_ (struct scm *table, struct scm *key, struct scm *dflt);
struct scm *hashq_ref_ (struct scm *table, struct scm *key, struct scm *dflt);
struct scm *hash_ref_ (struct scm *table, struct scm *key, struct scm *dflt);
struct scm *hashq_set_handle_x (struct scm *table, struct scm *key, struct scm *value);
struct scm *hashq_set_x (struct scm *table, struct scm *key, struct scm *value);
struct scm *hash_set_x (struct scm *table, struct scm *key, struct scm *value);
struct scm *hash_table_printer (struct scm *table);

View File

@ -177,6 +177,7 @@ mes_builtins (struct scm *a) /*:((internal)) */
a = init_builtin (builtin_type, "core:hashq-get-handle", 3, &hashq_get_handle_, a);
a = init_builtin (builtin_type, "core:hashq-ref", 3, &hashq_ref_, a);
a = init_builtin (builtin_type, "core:hash-ref", 3, &hash_ref_, a);
a = init_builtin (builtin_type, "hashq-set-handle!", 3, &hashq_set_handle_x, a);
a = init_builtin (builtin_type, "hashq-set!", 3, &hashq_set_x, a);
a = init_builtin (builtin_type, "hash-set!", 3, &hash_set_x, a);
a = init_builtin (builtin_type, "hash-table-printer", 1, &hash_table_printer, a);

View File

@ -117,13 +117,24 @@ hash_set_x_ (struct scm *table, unsigned hash, struct scm *key, struct scm *valu
struct scm *bucket = vector_ref_ (buckets, hash);
if (bucket->type != TPAIR)
bucket = cell_nil;
bucket = acons (key, value, bucket);
struct scm *handle = cons (key, value);
bucket = cons (handle, bucket);
vector_set_x_ (buckets, hash, bucket);
return value;
return handle;
}
struct scm *
hashq_set_x (struct scm *table, struct scm *key, struct scm *value)
{
struct scm *s = struct_ref_ (table, 3);
long size = s->value;
unsigned hash = hashq_ (key, size);
struct scm *handle = hash_set_x_ (table, hash, key, value);
return handle->cdr;
}
struct scm *
hashq_set_handle_x (struct scm *table, struct scm *key, struct scm *value)
{
struct scm *s = struct_ref_ (table, 3);
long size = s->value;
@ -137,7 +148,8 @@ hash_set_x (struct scm *table, struct scm *key, struct scm *value)
struct scm *s = struct_ref_ (table, 3);
long size = s->value;
unsigned hash = hash_ (key, size);
return hash_set_x_ (table, hash, key, value);
struct scm *handle = hash_set_x_ (table, hash, key, value);
return handle->cdr;
}
struct scm *