64 #include <config_auto.h>
67 #include "allheaders.h"
70 static const l_uint32 MaxTabsize = 50000000;
72 static const l_int32 DefaultInitNItems = 2000;
73 static const l_int32 DefaultMaxOcc = 2;
102 l_hmapCreate(l_int32 ninit,
105 l_uint32 size, tabsize;
108 PROCNAME(
"l_hmapCreate");
110 ninit = L_MAX(ninit, DefaultInitNItems);
111 if (maxocc <= 0) maxocc = DefaultMaxOcc;
113 L_WARNING(
"maxocc = %d; non-optimal value. Set to default = %d\n",
114 procName, maxocc, DefaultMaxOcc);
115 maxocc = DefaultMaxOcc;
117 size = ninit / maxocc;
118 if (size > MaxTabsize) {
119 L_ERROR(
"ninit/maxocc = %d > MaxTabsize = %d\n", procName,
129 return (
L_HASHMAP *)ERROR_PTR(
"hashtab not made", procName, NULL);
153 PROCNAME(
"l_hmapDestroy");
156 L_WARNING(
"ptr address is NULL!\n", procName);
160 if ((hmap = *phmap) == NULL)
163 for (i = 0; i < hmap->
tabsize; i++) {
164 for (hitem = hmap->
hashtab[i]; hitem != NULL; hitem = next) {
211 PROCNAME(
"l_hmapLookup");
214 return (
L_HASHITEM *)ERROR_PTR(
"hmap not defined", procName, NULL);
215 if (op != L_HMAP_CHECK && op != L_HMAP_CREATE)
216 return (
L_HASHITEM *)ERROR_PTR(
"invalid op", procName, NULL);
221 for (hitem = hlist; hitem != NULL; hitem = hitem->
next) {
222 if (key == hitem->
key) {
223 if (op == L_HMAP_CREATE) hitem->
count++;
227 if (op == L_HMAP_CHECK)
return NULL;
241 if (hmap->
ntogo == 0)
267 PROCNAME(
"l_hmapRehash");
270 return ERROR_INT(
"hmap not defined", procName, 1);
275 for (i = 0; i < hmap->
tabsize; i++) {
276 for (hitem = hmap->
hashtab[i]; hitem != NULL; hitem = next) {
278 hitem->
next = hstore;
290 return ERROR_INT(
"hashtab ptr array not made", procName, 1);
295 for (hitem = hstore; hitem != NULL; hitem = next) {
297 index = hitem->
key % tabsize;
struct L_Hashitem ** hashtab
l_ok findNextLargerPrime(l_int32 start, l_uint32 *pprime)
findNextLargerPrime()