diff options
-rw-r--r-- | ltable.c | 16 |
1 files changed, 14 insertions, 2 deletions
@@ -84,8 +84,6 @@ | |||
84 | #define hashstr(t,str) hashpow2(t, (str)->hash) | 84 | #define hashstr(t,str) hashpow2(t, (str)->hash) |
85 | #define hashboolean(t,p) hashpow2(t, p) | 85 | #define hashboolean(t,p) hashpow2(t, p) |
86 | 86 | ||
87 | #define hashint(t,i) hashpow2(t, i) | ||
88 | |||
89 | 87 | ||
90 | #define hashpointer(t,p) hashmod(t, point2uint(p)) | 88 | #define hashpointer(t,p) hashmod(t, point2uint(p)) |
91 | 89 | ||
@@ -101,6 +99,20 @@ static const Node dummynode_ = { | |||
101 | static const TValue absentkey = {ABSTKEYCONSTANT}; | 99 | static const TValue absentkey = {ABSTKEYCONSTANT}; |
102 | 100 | ||
103 | 101 | ||
102 | /* | ||
103 | ** Hash for integers. To allow a good hash, use the remainder operator | ||
104 | ** ('%'). If integer fits as a non-negative int, compute an int | ||
105 | ** remainder, which is faster. Otherwise, use an unsigned-integer | ||
106 | ** remainder, which uses all bits and ensures a non-negative result. | ||
107 | */ | ||
108 | static Node *hashint (const Table *t, lua_Integer i) { | ||
109 | lua_Unsigned ui = l_castS2U(i); | ||
110 | if (ui <= (unsigned int)INT_MAX) | ||
111 | return hashmod(t, cast_int(ui)); | ||
112 | else | ||
113 | return hashmod(t, ui); | ||
114 | } | ||
115 | |||
104 | 116 | ||
105 | /* | 117 | /* |
106 | ** Hash for floating-point numbers. | 118 | ** Hash for floating-point numbers. |