X-Git-Url: http://git.chise.org/gitweb/?a=blobdiff_plain;f=src%2Felhash.c;h=b53f7a0bf76f5bdf1a389b9f18c8096be006eebd;hb=280624d95d3fd2fdee5e852a92cdb7457736cba8;hp=e956a2fa15a74873528f56650348c35fca6aa529;hpb=77dcef404dc78635f6ffa8f71a803d2bc7cc8921;p=chise%2Fxemacs-chise.git- diff --git a/src/elhash.c b/src/elhash.c index e956a2f..b53f7a0 100644 --- a/src/elhash.c +++ b/src/elhash.c @@ -47,7 +47,7 @@ struct Lisp_Hash_Table size_t rehash_count; double rehash_size; double rehash_threshold; - size_t golden; + size_t golden_ratio; hash_table_hash_function_t hash_function; hash_table_test_function_t test_function; hentry *hentries; @@ -66,7 +66,7 @@ typedef struct Lisp_Hash_Table Lisp_Hash_Table; #define HASH_CODE(key, ht) \ (((((ht)->hash_function ? (ht)->hash_function (key) : LISP_HASH (key)) \ - * (ht)->golden) \ + * (ht)->golden_ratio) \ % (ht)->size)) #define KEYS_EQUAL_P(key1, key2, testfun) \ @@ -364,11 +364,28 @@ finalize_hash_table (void *header, int for_disksave) } } +static const struct lrecord_description hentry_description_1[] = { + { XD_LISP_OBJECT, offsetof(hentry, key), 2 }, + { XD_END } +}; + +static const struct struct_description hentry_description = { + sizeof(hentry), + hentry_description_1 +}; + +static const struct lrecord_description hash_table_description[] = { + { XD_SIZE_T, offsetof(Lisp_Hash_Table, size) }, + { XD_STRUCT_PTR, offsetof(Lisp_Hash_Table, hentries), XD_INDIRECT(0), &hentry_description }, + { XD_END } +}; + DEFINE_LRECORD_IMPLEMENTATION ("hash-table", hash_table, mark_hash_table, print_hash_table, finalize_hash_table, /* #### Implement hash_table_hash()! */ hash_table_equal, 0, + hash_table_description, Lisp_Hash_Table); static Lisp_Hash_Table * @@ -399,7 +416,7 @@ compute_hash_table_derived_values (Lisp_Hash_Table *ht) { ht->rehash_count = (size_t) ((double) ht->size * hash_table_rehash_threshold (ht)); - ht->golden = (size_t) + ht->golden_ratio = (size_t) ((double) ht->size * (.6180339887 / (double) sizeof (Lisp_Object))); } @@ -411,7 +428,7 @@ make_general_lisp_hash_table (size_t size, double rehash_threshold) { Lisp_Object hash_table; - Lisp_Hash_Table *ht = alloc_lcrecord_type (Lisp_Hash_Table, lrecord_hash_table); + Lisp_Hash_Table *ht = alloc_lcrecord_type (Lisp_Hash_Table, &lrecord_hash_table); ht->type = type; ht->rehash_size = rehash_size; @@ -832,7 +849,7 @@ The keys and values will not themselves be copied. (hash_table)) { CONST Lisp_Hash_Table *ht_old = xhash_table (hash_table); - Lisp_Hash_Table *ht = alloc_lcrecord_type (Lisp_Hash_Table, lrecord_hash_table); + Lisp_Hash_Table *ht = alloc_lcrecord_type (Lisp_Hash_Table, &lrecord_hash_table); copy_lcrecord (ht, ht_old);