SDDS ToolKit Programs and Libraries for C and Python
Loading...
Searching...
No Matches
lookupa.c File Reference

Detailed Description

Jenkins lookup hash functions for 32- and 64-bit machines.

Based on public domain code by Bob Jenkins (December 1996), sourced from http://burtleburtle.net/bob/c/lookupa.c. Customized for elegant for both 32- and 64-bit machines by Yusong Wang (May 2007). Public domain; no warranty.

Definition in file lookupa.c.

#include "standard.h"
#include "lookupa.h"

Go to the source code of this file.

Functions

ub4 lookup (ub1 *k, ub4 length, ub4 level)
 

Function Documentation

◆ lookup()

ub4 lookup ( ub1 * k,
ub4 length,
ub4 level )

Definition at line 102 of file lookupa.c.

105{
106 register ub4 a, b, c, len;
107
108 /* Set up the internal state */
109 len = length;
110 a = b = 0x9e3779b9; /* the golden ratio; an arbitrary value */
111 c = level; /* the previous hash value */
112
113 /*---------------------------------------- handle most of the key */
114 while (len >= 12) {
115 a += (k[0] + ((ub4)k[1] << 8) + ((ub4)k[2] << 16) + ((ub4)k[3] << 24));
116 b += (k[4] + ((ub4)k[5] << 8) + ((ub4)k[6] << 16) + ((ub4)k[7] << 24));
117 c += (k[8] + ((ub4)k[9] << 8) + ((ub4)k[10] << 16) + ((ub4)k[11] << 24));
118 mix(a, b, c);
119 k += 12;
120 len -= 12;
121 }
122
123 /*------------------------------------- handle the last 11 bytes */
124 c += length;
125 switch (len) /* all the case statements fall through */
126 {
127 case 11:
128 c += ((ub4)k[10] << 24);
129 case 10:
130 c += ((ub4)k[9] << 16);
131 case 9:
132 c += ((ub4)k[8] << 8);
133 /* the first byte of c is reserved for the length */
134 case 8:
135 b += ((ub4)k[7] << 24);
136 case 7:
137 b += ((ub4)k[6] << 16);
138 case 6:
139 b += ((ub4)k[5] << 8);
140 case 5:
141 b += k[4];
142 case 4:
143 a += ((ub4)k[3] << 24);
144 case 3:
145 a += ((ub4)k[2] << 16);
146 case 2:
147 a += ((ub4)k[1] << 8);
148 case 1:
149 a += k[0];
150 /* case 0: nothing left to add */
151 }
152 mix(a, b, c);
153 /*-------------------------------------------- report the result */
154 return c;
155}