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 ninit = L_MAX(ninit, DefaultInitNItems);
109 if (maxocc <= 0) maxocc = DefaultMaxOcc;
111 L_WARNING(
"maxocc = %d; non-optimal value. Set to default = %d\n",
112 __func__, maxocc, DefaultMaxOcc);
113 maxocc = DefaultMaxOcc;
115 size = ninit / maxocc;
116 if (size > MaxTabsize) {
117 L_ERROR(
"ninit/maxocc = %d > MaxTabsize = %d\n", __func__,
127 return (
L_HASHMAP *)ERROR_PTR(
"hashtab not made", __func__, NULL);
152 L_WARNING(
"ptr address is NULL!\n", __func__);
156 if ((hmap = *phmap) == NULL)
159 for (i = 0; i < hmap->
tabsize; i++) {
160 for (hitem = hmap->
hashtab[i]; hitem != NULL; hitem = next) {
208 return (
L_HASHITEM *)ERROR_PTR(
"hmap not defined", __func__, NULL);
209 if (op != L_HMAP_CHECK && op != L_HMAP_CREATE)
210 return (
L_HASHITEM *)ERROR_PTR(
"invalid op", __func__, NULL);
215 for (hitem = hlist; hitem != NULL; hitem = hitem->
next) {
216 if (key == hitem->
key) {
217 if (op == L_HMAP_CREATE) hitem->
count++;
221 if (op == L_HMAP_CHECK)
return NULL;
235 if (hmap->
ntogo == 0)
262 return ERROR_INT(
"hmap not defined", __func__, 1);
267 for (i = 0; i < hmap->
tabsize; i++) {
268 for (hitem = hmap->
hashtab[i]; hitem != NULL; hitem = next) {
270 hitem->
next = hstore;
282 return ERROR_INT(
"hashtab ptr array not made", __func__, 1);
287 for (hitem = hstore; hitem != NULL; hitem = next) {
289 index = hitem->
key % tabsize;
struct L_Hashitem ** hashtab
l_ok findNextLargerPrime(l_int32 start, l_uint32 *pprime)
findNextLargerPrime()