diff --git a/include/mes/builtins.h b/include/mes/builtins.h index fed49aef..9b21b641 100644 --- a/include/mes/builtins.h +++ b/include/mes/builtins.h @@ -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); diff --git a/src/builtins.c b/src/builtins.c index e50214aa..2010f320 100644 --- a/src/builtins.c +++ b/src/builtins.c @@ -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); diff --git a/src/hash.c b/src/hash.c index 7e9187de..0d6b5e65 100644 --- a/src/hash.c +++ b/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 *