diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2015-02-20 12:05:01 -0200 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2015-02-20 12:05:01 -0200 |
| commit | 397ce11996bb1b5a6ef81fdf44252cf58b230937 (patch) | |
| tree | 53d086c60232e526717de58abd96c965417bdad7 | |
| parent | 97f2aa5a443b75f2528a27e6e78fe18f66cb4f87 (diff) | |
| download | lua-397ce11996bb1b5a6ef81fdf44252cf58b230937.tar.gz lua-397ce11996bb1b5a6ef81fdf44252cf58b230937.tar.bz2 lua-397ce11996bb1b5a6ef81fdf44252cf58b230937.zip | |
make 'hashfloat' configurable
| -rw-r--r-- | ltable.c | 16 |
1 files changed, 8 insertions, 8 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: ltable.c,v 2.102 2015/02/13 13:05:34 roberto Exp roberto $ | 2 | ** $Id: ltable.c,v 2.103 2015/02/16 13:15:00 roberto Exp roberto $ |
| 3 | ** Lua tables (hash) | 3 | ** Lua tables (hash) |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -97,7 +97,7 @@ static int numisinteger (lua_Number x, lua_Integer *p) { | |||
| 97 | /* | 97 | /* |
| 98 | ** Hash for floating-point numbers. | 98 | ** Hash for floating-point numbers. |
| 99 | ** The main computation should be just | 99 | ** The main computation should be just |
| 100 | ** n = frepx(n, &i); hash = (n * INT_MAX) + i | 100 | ** n = frepx(n, &i); return (n * INT_MAX) + i |
| 101 | ** but there are some numerical subtleties. | 101 | ** but there are some numerical subtleties. |
| 102 | ** In a two-complement representation, INT_MAX does not has an exact | 102 | ** In a two-complement representation, INT_MAX does not has an exact |
| 103 | ** representation as a float, but INT_MIN does; because the absolute | 103 | ** representation as a float, but INT_MIN does; because the absolute |
| @@ -107,21 +107,21 @@ static int numisinteger (lua_Number x, lua_Integer *p) { | |||
| 107 | ** adding 'i'; the use of '~u' (instead of '-u') avoids problems with | 107 | ** adding 'i'; the use of '~u' (instead of '-u') avoids problems with |
| 108 | ** INT_MIN. | 108 | ** INT_MIN. |
| 109 | */ | 109 | */ |
| 110 | static Node *hashfloat (const Table *t, lua_Number n) { | 110 | #if !defined(l_hashfloat) |
| 111 | static int l_hashfloat (lua_Number n) { | ||
| 111 | int i; | 112 | int i; |
| 112 | lua_Integer ni; | 113 | lua_Integer ni; |
| 113 | n = l_mathop(frexp)(n, &i) * -cast_num(INT_MIN); | 114 | n = l_mathop(frexp)(n, &i) * -cast_num(INT_MIN); |
| 114 | if (!lua_numbertointeger(n, &ni)) { /* is 'n' inf/-inf/NaN? */ | 115 | if (!lua_numbertointeger(n, &ni)) { /* is 'n' inf/-inf/NaN? */ |
| 115 | lua_assert(luai_numisnan(n) || l_mathop(fabs)(n) == HUGE_VAL); | 116 | lua_assert(luai_numisnan(n) || l_mathop(fabs)(n) == HUGE_VAL); |
| 116 | i = 0; | 117 | return 0; |
| 117 | } | 118 | } |
| 118 | else { /* normal case */ | 119 | else { /* normal case */ |
| 119 | unsigned int u = cast(unsigned int, i) + cast(unsigned int, ni); | 120 | unsigned int u = cast(unsigned int, i) + cast(unsigned int, ni); |
| 120 | i = (u <= cast(unsigned int, INT_MAX) ? u : ~u); | 121 | return cast_int(u <= cast(unsigned int, INT_MAX) ? u : ~u); |
| 121 | } | 122 | } |
| 122 | return hashmod(t, i); | ||
| 123 | } | 123 | } |
| 124 | 124 | #endif | |
| 125 | 125 | ||
| 126 | 126 | ||
| 127 | /* | 127 | /* |
| @@ -133,7 +133,7 @@ static Node *mainposition (const Table *t, const TValue *key) { | |||
| 133 | case LUA_TNUMINT: | 133 | case LUA_TNUMINT: |
| 134 | return hashint(t, ivalue(key)); | 134 | return hashint(t, ivalue(key)); |
| 135 | case LUA_TNUMFLT: | 135 | case LUA_TNUMFLT: |
| 136 | return hashfloat(t, fltvalue(key)); | 136 | return hashmod(t, l_hashfloat(fltvalue(key))); |
| 137 | case LUA_TSHRSTR: | 137 | case LUA_TSHRSTR: |
| 138 | return hashstr(t, tsvalue(key)); | 138 | return hashstr(t, tsvalue(key)); |
| 139 | case LUA_TLNGSTR: { | 139 | case LUA_TLNGSTR: { |
