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:
parent
ff97c556c0
commit
a35bb1c9eb
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
18
src/hash.c
18
src/hash.c
|
@ -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 *
|
||||
|
|
Loading…
Reference in New Issue