Github User Fetcher 1.0.0
C Application with Server and GUI
Loading...
Searching...
No Matches
duk_util_hashprime.c File Reference
#include "duk_internal.h"

Go to the source code of this file.

Macros

#define DUK__HASH_SIZE_RATIO   1177 /* floor(1.15 * (1 << 10)) */
 

Functions

DUK_INTERNAL duk_uint32_t duk_util_get_hash_prime (duk_uint32_t size)
 

Variables

DUK_LOCAL const duk_int8_t duk__hash_size_corrections []
 
DUK_INTERNAL duk_uint8_t duk_util_probe_steps [32]
 

Macro Definition Documentation

◆ DUK__HASH_SIZE_RATIO

#define DUK__HASH_SIZE_RATIO   1177 /* floor(1.15 * (1 << 10)) */

Function Documentation

◆ duk_util_get_hash_prime()

DUK_INTERNAL duk_uint32_t duk_util_get_hash_prime ( duk_uint32_t size)

Definition at line 45 of file duktape-1.8.0/src-separate/duk_util_hashprime.c.

45 {
46 const duk_int8_t *p = duk__hash_size_corrections;
47 duk_uint32_t curr;
48
49 curr = (duk_uint32_t) *p++;
50 for (;;) {
52 if (t < 0) {
53 /* may happen if size is very close to 2^32-1 */
54 break;
55 }
56
57 /* prediction: portable variant using doubles if 64-bit values not available */
58#ifdef DUK_USE_64BIT_OPS
59 curr = (duk_uint32_t) ((((duk_uint64_t) curr) * ((duk_uint64_t) DUK__HASH_SIZE_RATIO)) >> 10);
60#else
61 /* 32-bit x 11-bit = 43-bit, fits accurately into a double */
62 curr = (duk_uint32_t) DUK_FLOOR(((double) curr) * ((double) DUK__HASH_SIZE_RATIO) / 1024.0);
63#endif
64
65 /* correction */
66 curr += t;
67
68 DUK_DDD(DUK_DDDPRINT("size=%ld, curr=%ld", (long) size, (long) curr));
69
70 if (curr >= size) {
71 return curr;
72 }
73 }
74 return 0;
75}
DUK_LOCAL const duk_int8_t duk__hash_size_corrections[]

References duk__hash_size_corrections, DUK__HASH_SIZE_RATIO, DUK_DDD, DUK_DDDPRINT, and DUK_FLOOR.

Variable Documentation

◆ duk__hash_size_corrections

DUK_LOCAL const duk_int8_t duk__hash_size_corrections[]
Initial value:
= {
17,
4, 3, 4, 1, 4, 1, 1, 2, 2, 2, 2, 1, 6, 6, 9, 5, 1, 2, 2, 5, 1, 3, 3, 3,
5, 4, 4, 2, 4, 8, 3, 4, 23, 2, 4, 7, 8, 11, 2, 12, 15, 10, 1, 1, 5, 1, 5,
8, 9, 17, 14, 10, 7, 5, 2, 46, 21, 1, 9, 9, 4, 4, 10, 23, 36, 6, 20, 29,
18, 6, 19, 21, 16, 11, 5, 5, 48, 9, 1, 39, 14, 8, 4, 29, 9, 1, 15, 48, 12,
22, 6, 15, 27, 4, 2, 17, 28, 8, 9, 4, 5, 8, 3, 3, 8, 37, 11, 15, 8, 30,
43, 6, 33, 41, 5, 20, 32, 41, 38, 24, 77, 14, 19, 11, 4, 35, 18, 19, 41,
10, 23, 16, 9, 2,
-1
}

Definition at line 25 of file duktape-1.8.0/src-separate/duk_util_hashprime.c.

25 {
26 17, /* minimum prime */
27 4, 3, 4, 1, 4, 1, 1, 2, 2, 2, 2, 1, 6, 6, 9, 5, 1, 2, 2, 5, 1, 3, 3, 3,
28 5, 4, 4, 2, 4, 8, 3, 4, 23, 2, 4, 7, 8, 11, 2, 12, 15, 10, 1, 1, 5, 1, 5,
29 8, 9, 17, 14, 10, 7, 5, 2, 46, 21, 1, 9, 9, 4, 4, 10, 23, 36, 6, 20, 29,
30 18, 6, 19, 21, 16, 11, 5, 5, 48, 9, 1, 39, 14, 8, 4, 29, 9, 1, 15, 48, 12,
31 22, 6, 15, 27, 4, 2, 17, 28, 8, 9, 4, 5, 8, 3, 3, 8, 37, 11, 15, 8, 30,
32 43, 6, 33, 41, 5, 20, 32, 41, 38, 24, 77, 14, 19, 11, 4, 35, 18, 19, 41,
33 10, 23, 16, 9, 2,
34 -1
35};

Referenced by duk_util_get_hash_prime().

◆ duk_util_probe_steps

DUK_INTERNAL duk_uint8_t duk_util_probe_steps[32]
Initial value:
= {
2, 3, 5, 7, 11, 13, 19, 31, 41, 47, 59, 67, 73, 79, 89, 101, 103, 107,
109, 127, 137, 139, 149, 157, 163, 167, 173, 181, 191, 193, 197, 199
}

Definition at line 40 of file duktape-1.8.0/src-separate/duk_util_hashprime.c.

40 {
41 2, 3, 5, 7, 11, 13, 19, 31, 41, 47, 59, 67, 73, 79, 89, 101, 103, 107,
42 109, 127, 137, 139, 149, 157, 163, 167, 173, 181, 191, 193, 197, 199
43};