aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorPaul Eggert2017-02-21 15:31:29 -0800
committerPaul Eggert2017-02-21 15:39:17 -0800
commit7207b63c8e290ddec33908ce8d38be5793388318 (patch)
tree144d55c7556c9514b4e3690f56f3bae35ab736fc /src
parentf2191691d4e814d38369053cdec428ee2142ab18 (diff)
downloademacs-7207b63c8e290ddec33908ce8d38be5793388318.tar.gz
emacs-7207b63c8e290ddec33908ce8d38be5793388318.zip
Hash table threshold is now float, not double
Change default from 0.8 to 0.8125 so it fits in float without rounding glitches. * doc/lispref/hash.texi (Creating Hash): * doc/lispref/objects.texi (Hash Table Type): * etc/NEWS: Document change. * src/fns.c (make_hash_table, maybe_resize_hash_table) (Fmake_hash_table): Threshold is now float, not double. Be consistent about how this is rounded. * src/lisp.h (struct Lisp_Hash_Table.rehash_threshold): Change back to float, now that the other code rounds consistently. (DEFAULT_REHASH_THRESHOLD): Now float 0.8125 instead of double 0.8.
Diffstat (limited to 'src')
-rw-r--r--src/fns.c24
-rw-r--r--src/lisp.h6
2 files changed, 16 insertions, 14 deletions
diff --git a/src/fns.c b/src/fns.c
index 3fed92dfec1..2a6653144bc 100644
--- a/src/fns.c
+++ b/src/fns.c
@@ -3663,8 +3663,8 @@ allocate_hash_table (void)
3663 REHASH_SIZE. 3663 REHASH_SIZE.
3664 3664
3665 REHASH_THRESHOLD must be a float <= 1.0, and > 0. The table will 3665 REHASH_THRESHOLD must be a float <= 1.0, and > 0. The table will
3666 be resized when the ratio of (number of entries in the table) / 3666 be resized when the approximate ratio of table entries to table
3667 (table size) is >= REHASH_THRESHOLD. 3667 size exceeds REHASH_THRESHOLD.
3668 3668
3669 WEAK specifies the weakness of the table. If non-nil, it must be 3669 WEAK specifies the weakness of the table. If non-nil, it must be
3670 one of the symbols `key', `value', `key-or-value', or `key-and-value'. 3670 one of the symbols `key', `value', `key-or-value', or `key-and-value'.
@@ -3676,7 +3676,7 @@ allocate_hash_table (void)
3676Lisp_Object 3676Lisp_Object
3677make_hash_table (struct hash_table_test test, 3677make_hash_table (struct hash_table_test test,
3678 Lisp_Object size, Lisp_Object rehash_size, 3678 Lisp_Object size, Lisp_Object rehash_size,
3679 double rehash_threshold, Lisp_Object weak, 3679 float rehash_threshold, Lisp_Object weak,
3680 bool pure) 3680 bool pure)
3681{ 3681{
3682 struct Lisp_Hash_Table *h; 3682 struct Lisp_Hash_Table *h;
@@ -3690,13 +3690,14 @@ make_hash_table (struct hash_table_test test,
3690 eassert (INTEGERP (size) && XINT (size) >= 0); 3690 eassert (INTEGERP (size) && XINT (size) >= 0);
3691 eassert ((INTEGERP (rehash_size) && XINT (rehash_size) > 0) 3691 eassert ((INTEGERP (rehash_size) && XINT (rehash_size) > 0)
3692 || (FLOATP (rehash_size) && 1 < XFLOAT_DATA (rehash_size))); 3692 || (FLOATP (rehash_size) && 1 < XFLOAT_DATA (rehash_size)));
3693 eassert (0 < rehash_threshold && rehash_threshold <= 1.0); 3693 eassert (0 < rehash_threshold && rehash_threshold <= 1);
3694 3694
3695 if (XFASTINT (size) == 0) 3695 if (XFASTINT (size) == 0)
3696 size = make_number (1); 3696 size = make_number (1);
3697 3697
3698 sz = XFASTINT (size); 3698 sz = XFASTINT (size);
3699 index_float = sz / rehash_threshold; 3699 double threshold = rehash_threshold;
3700 index_float = sz / threshold;
3700 index_size = (index_float < INDEX_SIZE_BOUND + 1 3701 index_size = (index_float < INDEX_SIZE_BOUND + 1
3701 ? next_almost_prime (index_float) 3702 ? next_almost_prime (index_float)
3702 : INDEX_SIZE_BOUND + 1); 3703 : INDEX_SIZE_BOUND + 1);
@@ -3795,7 +3796,8 @@ maybe_resize_hash_table (struct Lisp_Hash_Table *h)
3795 else 3796 else
3796 new_size = INDEX_SIZE_BOUND + 1; 3797 new_size = INDEX_SIZE_BOUND + 1;
3797 } 3798 }
3798 index_float = new_size / h->rehash_threshold; 3799 double threshold = h->rehash_threshold;
3800 index_float = new_size / threshold;
3799 index_size = (index_float < INDEX_SIZE_BOUND + 1 3801 index_size = (index_float < INDEX_SIZE_BOUND + 1
3800 ? next_almost_prime (index_float) 3802 ? next_almost_prime (index_float)
3801 : INDEX_SIZE_BOUND + 1); 3803 : INDEX_SIZE_BOUND + 1);
@@ -4370,8 +4372,8 @@ amount. If it is a float, it must be > 1.0, and the new size is the
4370old size multiplied by that factor. Default is 1.5. 4372old size multiplied by that factor. Default is 1.5.
4371 4373
4372:rehash-threshold THRESHOLD -- THRESHOLD must a float > 0, and <= 1.0. 4374:rehash-threshold THRESHOLD -- THRESHOLD must a float > 0, and <= 1.0.
4373Resize the hash table when the ratio (number of entries / table size) 4375Resize the hash table when the ratio (table entries / table size)
4374is greater than or equal to THRESHOLD. Default is 0.8. 4376exceeds an approximation to THRESHOLD. Default is 0.8125.
4375 4377
4376:weakness WEAK -- WEAK must be one of nil, t, `key', `value', 4378:weakness WEAK -- WEAK must be one of nil, t, `key', `value',
4377`key-or-value', or `key-and-value'. If WEAK is not nil, the table 4379`key-or-value', or `key-and-value'. If WEAK is not nil, the table
@@ -4390,7 +4392,6 @@ usage: (make-hash-table &rest KEYWORD-ARGS) */)
4390 (ptrdiff_t nargs, Lisp_Object *args) 4392 (ptrdiff_t nargs, Lisp_Object *args)
4391{ 4393{
4392 Lisp_Object test, size, rehash_size, weak; 4394 Lisp_Object test, size, rehash_size, weak;
4393 double rehash_threshold;
4394 bool pure; 4395 bool pure;
4395 struct hash_table_test testdesc; 4396 struct hash_table_test testdesc;
4396 ptrdiff_t i; 4397 ptrdiff_t i;
@@ -4445,8 +4446,9 @@ usage: (make-hash-table &rest KEYWORD-ARGS) */)
4445 4446
4446 /* Look for `:rehash-threshold THRESHOLD'. */ 4447 /* Look for `:rehash-threshold THRESHOLD'. */
4447 i = get_key_arg (QCrehash_threshold, nargs, args, used); 4448 i = get_key_arg (QCrehash_threshold, nargs, args, used);
4448 rehash_threshold = (!i ? DEFAULT_REHASH_THRESHOLD 4449 float rehash_threshold = (!i ? DEFAULT_REHASH_THRESHOLD
4449 : FLOATP (args[i]) ? XFLOAT_DATA (args[i]) : 0); 4450 : !FLOATP (args[i]) ? 0
4451 : (float) XFLOAT_DATA (args[i]));
4450 if (! (0 < rehash_threshold && rehash_threshold <= 1)) 4452 if (! (0 < rehash_threshold && rehash_threshold <= 1))
4451 signal_error ("Invalid hash table rehash threshold", args[i]); 4453 signal_error ("Invalid hash table rehash threshold", args[i]);
4452 4454
diff --git a/src/lisp.h b/src/lisp.h
index be42b3354e2..6e0252621a6 100644
--- a/src/lisp.h
+++ b/src/lisp.h
@@ -2004,7 +2004,7 @@ struct Lisp_Hash_Table
2004 2004
2005 /* Resize hash table when number of entries / table size is >= this 2005 /* Resize hash table when number of entries / table size is >= this
2006 ratio. */ 2006 ratio. */
2007 double rehash_threshold; 2007 float rehash_threshold;
2008 2008
2009 /* Vector of keys and values. The key of item I is found at index 2009 /* Vector of keys and values. The key of item I is found at index
2010 2 * I, the value is found at index 2 * I + 1. 2010 2 * I, the value is found at index 2 * I + 1.
@@ -2088,7 +2088,7 @@ enum DEFAULT_HASH_SIZE { DEFAULT_HASH_SIZE = 65 };
2088 value gives the ratio of current entries in the hash table and the 2088 value gives the ratio of current entries in the hash table and the
2089 size of the hash table. */ 2089 size of the hash table. */
2090 2090
2091static double const DEFAULT_REHASH_THRESHOLD = 0.8; 2091static float const DEFAULT_REHASH_THRESHOLD = 0.8125;
2092 2092
2093/* Default factor by which to increase the size of a hash table. */ 2093/* Default factor by which to increase the size of a hash table. */
2094 2094
@@ -3363,7 +3363,7 @@ EMACS_UINT hash_string (char const *, ptrdiff_t);
3363EMACS_UINT sxhash (Lisp_Object, int); 3363EMACS_UINT sxhash (Lisp_Object, int);
3364Lisp_Object make_hash_table (struct hash_table_test test, 3364Lisp_Object make_hash_table (struct hash_table_test test,
3365 Lisp_Object size, Lisp_Object rehash_size, 3365 Lisp_Object size, Lisp_Object rehash_size,
3366 double rehash_threshold, Lisp_Object weak, 3366 float rehash_threshold, Lisp_Object weak,
3367 bool pure); 3367 bool pure);
3368ptrdiff_t hash_lookup (struct Lisp_Hash_Table *, Lisp_Object, EMACS_UINT *); 3368ptrdiff_t hash_lookup (struct Lisp_Hash_Table *, Lisp_Object, EMACS_UINT *);
3369ptrdiff_t hash_put (struct Lisp_Hash_Table *, Lisp_Object, Lisp_Object, 3369ptrdiff_t hash_put (struct Lisp_Hash_Table *, Lisp_Object, Lisp_Object,