Mercurial > hg > xemacs-beta
comparison src/elhash.c @ 4777:c69aeb86b2a3
Serialise non-default hash table rehash thresholds correctly; use this.
src/ChangeLog addition:
2009-12-17 Aidan Kehoe <kehoea@parhasard.net>
* elhash.c (HASH_TABLE_DEFAULT_REHASH_THRESHOLD):
New macro, giving a default value for a hash table's rehash
threshold given its size and test function.
(print_hash_table): Print the hash table's rehash threshold if it
has a non-default value. Ditto for its rehash size.
(Fmake_hash_table): Supply the keyword arguments in a format
understood by #'function-arglist.
lisp/ChangeLog addition:
2009-12-17 Aidan Kehoe <kehoea@parhasard.net>
* mule/make-coding-system.el
(fixed-width-create-decode-encode-tables):
Use a rehash threshold of 0.999 for this hash table, now that hash
table rehash thresholds are serialised correctly; these hash
tables will never be resized, and it's not even that important
that they are *that* fast, for most of the coding systems they're
used a minority of the time.
author | Aidan Kehoe <kehoea@parhasard.net> |
---|---|
date | Thu, 17 Dec 2009 13:50:45 +0000 |
parents | 80cd90837ac5 |
children | 0081fd36b783 |
comparison
equal
deleted
inserted
replaced
4776:73e8632018ad | 4777:c69aeb86b2a3 |
---|---|
116 (*(EMACS_UINT*)(&((htentry)->value))) = 0) | 116 (*(EMACS_UINT*)(&((htentry)->value))) = 0) |
117 | 117 |
118 #define HASH_TABLE_DEFAULT_SIZE 16 | 118 #define HASH_TABLE_DEFAULT_SIZE 16 |
119 #define HASH_TABLE_DEFAULT_REHASH_SIZE 1.3 | 119 #define HASH_TABLE_DEFAULT_REHASH_SIZE 1.3 |
120 #define HASH_TABLE_MIN_SIZE 10 | 120 #define HASH_TABLE_MIN_SIZE 10 |
121 #define HASH_TABLE_DEFAULT_REHASH_THRESHOLD(size, test_function) \ | |
122 ((size) > 4096 && (test_function) == HASH_TABLE_EQ ? 0.7 : 0.6) | |
121 | 123 |
122 #define HASHCODE(key, ht) \ | 124 #define HASHCODE(key, ht) \ |
123 ((((ht)->hash_function ? (ht)->hash_function (key) : LISP_HASH (key)) \ | 125 ((((ht)->hash_function ? (ht)->hash_function (key) : LISP_HASH (key)) \ |
124 * (ht)->golden_ratio) \ | 126 * (ht)->golden_ratio) \ |
125 % (ht)->size) | 127 % (ht)->size) |
351 static void | 353 static void |
352 print_hash_table (Lisp_Object obj, Lisp_Object printcharfun, | 354 print_hash_table (Lisp_Object obj, Lisp_Object printcharfun, |
353 int UNUSED (escapeflag)) | 355 int UNUSED (escapeflag)) |
354 { | 356 { |
355 Lisp_Hash_Table *ht = XHASH_TABLE (obj); | 357 Lisp_Hash_Table *ht = XHASH_TABLE (obj); |
358 Ascbyte pigbuf[350]; | |
356 | 359 |
357 write_c_string (printcharfun, | 360 write_c_string (printcharfun, |
358 print_readably ? "#s(hash-table" : "#<hash-table"); | 361 print_readably ? "#s(hash-table" : "#<hash-table"); |
359 | 362 |
360 /* These checks have a kludgy look to them, but they are safe. | 363 /* These checks have a kludgy look to them, but they are safe. |
385 (ht->weakness == HASH_TABLE_WEAK ? "key-and-value" : | 388 (ht->weakness == HASH_TABLE_WEAK ? "key-and-value" : |
386 ht->weakness == HASH_TABLE_KEY_WEAK ? "key" : | 389 ht->weakness == HASH_TABLE_KEY_WEAK ? "key" : |
387 ht->weakness == HASH_TABLE_VALUE_WEAK ? "value" : | 390 ht->weakness == HASH_TABLE_VALUE_WEAK ? "value" : |
388 ht->weakness == HASH_TABLE_KEY_VALUE_WEAK ? "key-or-value" : | 391 ht->weakness == HASH_TABLE_KEY_VALUE_WEAK ? "key-or-value" : |
389 "you-d-better-not-see-this")); | 392 "you-d-better-not-see-this")); |
393 } | |
394 | |
395 if (ht->rehash_size != HASH_TABLE_DEFAULT_REHASH_SIZE) | |
396 { | |
397 float_to_string (pigbuf, ht->rehash_size); | |
398 write_fmt_string (printcharfun, " rehash-size %s", pigbuf); | |
399 } | |
400 | |
401 if (ht->rehash_threshold | |
402 != HASH_TABLE_DEFAULT_REHASH_THRESHOLD (ht->size, | |
403 ht->test_function)) | |
404 { | |
405 float_to_string (pigbuf, ht->rehash_threshold); | |
406 write_fmt_string (printcharfun, " rehash-threshold %s", pigbuf); | |
390 } | 407 } |
391 | 408 |
392 if (ht->count) | 409 if (ht->count) |
393 print_hash_table_data (ht, printcharfun); | 410 print_hash_table_data (ht, printcharfun); |
394 | 411 |
589 ht->rehash_size = | 606 ht->rehash_size = |
590 rehash_size > 1.0 ? rehash_size : HASH_TABLE_DEFAULT_REHASH_SIZE; | 607 rehash_size > 1.0 ? rehash_size : HASH_TABLE_DEFAULT_REHASH_SIZE; |
591 | 608 |
592 ht->rehash_threshold = | 609 ht->rehash_threshold = |
593 rehash_threshold > 0.0 ? rehash_threshold : | 610 rehash_threshold > 0.0 ? rehash_threshold : |
594 size > 4096 && !ht->test_function ? 0.7 : 0.6; | 611 HASH_TABLE_DEFAULT_REHASH_THRESHOLD (size, ht->test_function); |
595 | 612 |
596 if (size < HASH_TABLE_MIN_SIZE) | 613 if (size < HASH_TABLE_MIN_SIZE) |
597 size = HASH_TABLE_MIN_SIZE; | 614 size = HASH_TABLE_MIN_SIZE; |
598 ht->size = hash_table_size ((Elemcount) (((double) size / ht->rehash_threshold) | 615 ht->size = hash_table_size ((Elemcount) (((double) size / ht->rehash_threshold) |
599 + 1.0)); | 616 + 1.0)); |
910 } | 927 } |
911 | 928 |
912 DEFUN ("make-hash-table", Fmake_hash_table, 0, MANY, 0, /* | 929 DEFUN ("make-hash-table", Fmake_hash_table, 0, MANY, 0, /* |
913 Return a new empty hash table object. | 930 Return a new empty hash table object. |
914 Use Common Lisp style keywords to specify hash table properties. | 931 Use Common Lisp style keywords to specify hash table properties. |
915 (make-hash-table &key test size rehash-size rehash-threshold weakness) | |
916 | 932 |
917 Keyword :test can be `eq', `eql' (default) or `equal'. | 933 Keyword :test can be `eq', `eql' (default) or `equal'. |
918 Comparison between keys is done using this function. | 934 Comparison between keys is done using this function. |
919 If speed is important, consider using `eq'. | 935 If speed is important, consider using `eq'. |
920 When storing strings in the hash table, you will likely need to use `equal'. | 936 When storing strings in the hash table, you will likely need to use `equal'. |
955 that a key-value pair will be removed only if the value and the key remain | 971 that a key-value pair will be removed only if the value and the key remain |
956 unmarked outside of weak hash tables. The pair will remain in the | 972 unmarked outside of weak hash tables. The pair will remain in the |
957 hash table if the value or key are pointed to by something other than a weak | 973 hash table if the value or key are pointed to by something other than a weak |
958 hash table, even if the other is not. | 974 hash table, even if the other is not. |
959 | 975 |
960 arguments: (&rest ARGS) | 976 arguments: (&key TEST SIZE REHASH-SIZE REHASH-THRESHOLD WEAKNESS) |
961 */ | 977 */ |
962 (int nargs, Lisp_Object *args)) | 978 (int nargs, Lisp_Object *args)) |
963 { | 979 { |
964 int i = 0; | 980 int i = 0; |
965 Lisp_Object test = Qnil; | 981 Lisp_Object test = Qnil; |