Revision d8a852fa xseg/xtypes/xhash.c
b/xseg/xtypes/xhash.c | ||
---|---|---|
222 | 222 |
*/ |
223 | 223 |
|
224 | 224 |
void |
225 |
xhash_init__(xhash_t *xhash, xhashidx size_shift, xhashidx minsize_shift,
|
|
226 |
enum xhash_type type, bool vals) |
|
225 |
xhash_init__(xhash_t *xhash, xhashidx size_shift, xhashidx minsize_shift, |
|
226 |
xhashidx limit, enum xhash_type type, bool vals)
|
|
227 | 227 |
{ |
228 | 228 |
xhashidx nr_items = 1UL << size_shift; |
229 | 229 |
xhashidx *kvs = (xhashidx *) ((char *) xhash + sizeof(struct xhash)); |
... | ... | |
231 | 231 |
|
232 | 232 |
XPTRSET(&xhash->kvs, kvs); |
233 | 233 |
|
234 |
|
|
234 |
|
|
235 | 235 |
if (!vals) { |
236 | 236 |
for (i=0; i < nr_items; i++) |
237 | 237 |
kvs[i] = UNUSED; |
... | ... | |
250 | 250 |
xhash->dummies = xhash->used = 0; |
251 | 251 |
xhash->size_shift = size_shift; |
252 | 252 |
xhash->minsize_shift = minsize_shift; |
253 |
xhash->limit = limit; |
|
253 | 254 |
xhash->type = type; |
254 | 255 |
|
255 | 256 |
ZEROSTAT(xhash->inserts); |
... | ... | |
269 | 270 |
|
270 | 271 |
|
271 | 272 |
xhash_t * |
272 |
xhash_new__(xhashidx size_shift, xhashidx minsize_shift, |
|
273 |
xhash_new__(xhashidx size_shift, xhashidx minsize_shift, xhashidx limit,
|
|
273 | 274 |
enum xhash_type type, bool vals) |
274 | 275 |
{ |
275 | 276 |
struct xhash *xhash; |
... | ... | |
279 | 280 |
return NULL; |
280 | 281 |
} |
281 | 282 |
|
282 |
xhash_init__(xhash, size_shift, minsize_shift, type, vals); |
|
283 |
xhash_init__(xhash, size_shift, minsize_shift, limit, type, vals);
|
|
283 | 284 |
|
284 | 285 |
return xhash; |
285 | 286 |
} |
286 | 287 |
|
287 | 288 |
|
288 | 289 |
xhash_t * |
289 |
xhash_resize__(struct xhash *xhash, xhashidx new_size_shift, bool vals) |
|
290 |
xhash_resize__(struct xhash *xhash, xhashidx new_size_shift, xhashidx new_limit, |
|
291 |
bool vals) |
|
290 | 292 |
{ |
291 |
return xhash_new__(new_size_shift, xhash->minsize_shift, xhash->type, vals); |
|
293 |
return xhash_new__(new_size_shift, xhash->minsize_shift, new_limit, |
|
294 |
xhash->type, vals); |
|
292 | 295 |
} |
293 | 296 |
|
294 | 297 |
int |
... | ... | |
382 | 385 |
} |
383 | 386 |
|
384 | 387 |
xhash_t * |
385 |
xhash_new(xhashidx minsize_shift, enum xhash_type type) |
|
388 |
xhash_new(xhashidx minsize_shift, xhashidx limit, enum xhash_type type)
|
|
386 | 389 |
{ |
387 |
return xhash_new__(minsize_shift, minsize_shift, type, true); |
|
390 |
return xhash_new__(minsize_shift, minsize_shift, limit, type, true);
|
|
388 | 391 |
} |
389 | 392 |
|
390 | 393 |
void xhash_free(struct xhash *xhash) |
... | ... | |
392 | 395 |
xtypes_free(xhash); |
393 | 396 |
} |
394 | 397 |
|
395 |
void xhash_init(struct xhash *xhash, xhashidx minsize_shift, enum xhash_type type) |
|
398 |
void xhash_init(struct xhash *xhash, xhashidx minsize_shift, xhashidx limit, |
|
399 |
enum xhash_type type) |
|
396 | 400 |
{ |
397 |
xhash_init__(xhash, minsize_shift, minsize_shift, type, true); |
|
401 |
xhash_init__(xhash, minsize_shift, minsize_shift, limit, type, true);
|
|
398 | 402 |
} |
399 | 403 |
|
400 | 404 |
/* |
... | ... | |
492 | 496 |
|
493 | 497 |
int xhash_insert(struct xhash *xhash, xhashidx key, xhashidx val) |
494 | 498 |
{ |
499 |
if (xhash->limit && xhash->used >= xhash->limit) |
|
500 |
return -XHASH_ENOSPC; |
|
495 | 501 |
if (grow_check(xhash)) |
496 | 502 |
return -XHASH_ERESIZE; |
497 | 503 |
xhash_insert__(xhash, key, val); |
... | ... | |
517 | 523 |
} |
518 | 524 |
|
519 | 525 |
xhash_t * |
520 |
xhash_resize(xhash_t *xhash, xhashidx new_size_shift, xhash_t *new) |
|
526 |
xhash_resize(xhash_t *xhash, xhashidx new_size_shift, xhashidx new_limit, |
|
527 |
xhash_t *new) |
|
521 | 528 |
{ |
522 | 529 |
//XSEGLOG("Resizing xhash from %llu to %llu", xhash->size_shift, new_size_shift); |
523 | 530 |
xhashidx i; |
524 | 531 |
int f = !!new; |
525 | 532 |
if (!f) |
526 |
new = xhash_new__(new_size_shift, xhash->minsize_shift, xhash->type, true); |
|
533 |
new = xhash_new__(new_size_shift, xhash->minsize_shift, new_limit, |
|
534 |
xhash->type, true); |
|
527 | 535 |
else |
528 |
xhash_init__(new, new_size_shift, xhash->minsize_shift, xhash->type, true); |
|
536 |
xhash_init__(new, new_size_shift, xhash->minsize_shift, new_limit, |
|
537 |
xhash->type, true); |
|
529 | 538 |
|
530 | 539 |
if (!new) |
531 | 540 |
return NULL; |
Also available in: Unified diff