Mercurial > hg > xemacs-beta
comparison src/elhash.c @ 438:84b14dcb0985 r21-2-27
Import from CVS: tag r21-2-27
author | cvs |
---|---|
date | Mon, 13 Aug 2007 11:32:25 +0200 |
parents | 9d177e8d4150 |
children | 8de8e3f6228a |
comparison
equal
deleted
inserted
replaced
437:e2a4e8b94b82 | 438:84b14dcb0985 |
---|---|
411 /************************************************************************/ | 411 /************************************************************************/ |
412 /* Creation of Hash Tables */ | 412 /* Creation of Hash Tables */ |
413 /************************************************************************/ | 413 /************************************************************************/ |
414 | 414 |
415 /* Creation of hash tables, without error-checking. */ | 415 /* Creation of hash tables, without error-checking. */ |
416 static double | |
417 hash_table_rehash_threshold (Lisp_Hash_Table *ht) | |
418 { | |
419 return | |
420 ht->rehash_threshold > 0.0 ? ht->rehash_threshold : | |
421 ht->size > 4096 && !ht->test_function ? 0.7 : 0.6; | |
422 } | |
423 | |
424 static void | 416 static void |
425 compute_hash_table_derived_values (Lisp_Hash_Table *ht) | 417 compute_hash_table_derived_values (Lisp_Hash_Table *ht) |
426 { | 418 { |
427 ht->rehash_count = (size_t) | 419 ht->rehash_count = (size_t) |
428 ((double) ht->size * hash_table_rehash_threshold (ht)); | 420 ((double) ht->size * ht->rehash_threshold); |
429 ht->golden_ratio = (size_t) | 421 ht->golden_ratio = (size_t) |
430 ((double) ht->size * (.6180339887 / (double) sizeof (Lisp_Object))); | 422 ((double) ht->size * (.6180339887 / (double) sizeof (Lisp_Object))); |
431 } | 423 } |
432 | 424 |
433 Lisp_Object | 425 Lisp_Object |
438 enum hash_table_weakness weakness) | 430 enum hash_table_weakness weakness) |
439 { | 431 { |
440 Lisp_Object hash_table; | 432 Lisp_Object hash_table; |
441 Lisp_Hash_Table *ht = alloc_lcrecord_type (Lisp_Hash_Table, &lrecord_hash_table); | 433 Lisp_Hash_Table *ht = alloc_lcrecord_type (Lisp_Hash_Table, &lrecord_hash_table); |
442 | 434 |
443 ht->rehash_size = rehash_size; | |
444 ht->rehash_threshold = rehash_threshold; | |
445 ht->weakness = weakness; | |
446 | |
447 switch (test) | 435 switch (test) |
448 { | 436 { |
449 case HASH_TABLE_EQ: | 437 case HASH_TABLE_EQ: |
450 ht->test_function = 0; | 438 ht->test_function = 0; |
451 ht->hash_function = 0; | 439 ht->hash_function = 0; |
463 | 451 |
464 default: | 452 default: |
465 abort (); | 453 abort (); |
466 } | 454 } |
467 | 455 |
468 if (ht->rehash_size <= 0.0) | 456 ht->weakness = weakness; |
469 ht->rehash_size = HASH_TABLE_DEFAULT_REHASH_SIZE; | 457 |
458 ht->rehash_size = | |
459 rehash_size > 1.0 ? rehash_size : HASH_TABLE_DEFAULT_REHASH_SIZE; | |
460 | |
461 ht->rehash_threshold = | |
462 rehash_threshold > 0.0 ? rehash_threshold : | |
463 size > 4096 && !ht->test_function ? 0.7 : 0.6; | |
464 | |
470 if (size < HASH_TABLE_MIN_SIZE) | 465 if (size < HASH_TABLE_MIN_SIZE) |
471 size = HASH_TABLE_MIN_SIZE; | 466 size = HASH_TABLE_MIN_SIZE; |
472 if (rehash_threshold < 0.0) | 467 ht->size = hash_table_size ((size_t) (((double) size / ht->rehash_threshold) |
473 rehash_threshold = 0.75; | 468 + 1.0)); |
474 ht->size = | |
475 hash_table_size ((size_t) ((double) size / hash_table_rehash_threshold (ht)) + 1); | |
476 ht->count = 0; | 469 ht->count = 0; |
470 | |
477 compute_hash_table_derived_values (ht); | 471 compute_hash_table_derived_values (ht); |
478 | 472 |
479 /* We leave room for one never-occupied sentinel hentry at the end. */ | 473 /* We leave room for one never-occupied sentinel hentry at the end. */ |
480 ht->hentries = xnew_array (hentry, ht->size + 1); | 474 ht->hentries = xnew_array (hentry, ht->size + 1); |
481 | 475 |
498 Lisp_Object | 492 Lisp_Object |
499 make_lisp_hash_table (size_t size, | 493 make_lisp_hash_table (size_t size, |
500 enum hash_table_weakness weakness, | 494 enum hash_table_weakness weakness, |
501 enum hash_table_test test) | 495 enum hash_table_test test) |
502 { | 496 { |
503 return make_general_lisp_hash_table | 497 return make_general_lisp_hash_table (test, size, -1.0, -1.0, weakness); |
504 (test, size, HASH_TABLE_DEFAULT_REHASH_SIZE, -1.0, weakness); | |
505 } | 498 } |
506 | 499 |
507 /* Pretty reading of hash tables. | 500 /* Pretty reading of hash tables. |
508 | 501 |
509 Here we use the existing structures mechanism (which is, | 502 Here we use the existing structures mechanism (which is, |
1088 This is a float between 0.0 and 1.0; the maximum `load factor' of HASH-TABLE, | 1081 This is a float between 0.0 and 1.0; the maximum `load factor' of HASH-TABLE, |
1089 beyond which the HASH-TABLE is enlarged by rehashing. | 1082 beyond which the HASH-TABLE is enlarged by rehashing. |
1090 */ | 1083 */ |
1091 (hash_table)) | 1084 (hash_table)) |
1092 { | 1085 { |
1093 return make_float (hash_table_rehash_threshold (xhash_table (hash_table))); | 1086 return make_float (xhash_table (hash_table)->rehash_threshold); |
1094 } | 1087 } |
1095 | 1088 |
1096 DEFUN ("hash-table-weakness", Fhash_table_weakness, 1, 1, 0, /* | 1089 DEFUN ("hash-table-weakness", Fhash_table_weakness, 1, 1, 0, /* |
1097 Return the weakness of HASH-TABLE. | 1090 Return the weakness of HASH-TABLE. |
1098 This can be one of `nil', `t', `key' or `value'. | 1091 This can be one of `nil', `t', `key' or `value'. |