/* This file is part of limb https://lila.oss/limb
* Copyright (C) 2023 Olivier Brunel jjk@jjacky.com */
/* SPDX-License-Identifier: GPL-2.0-only */
#ifndef LIMB_INTERNAL_HMAP_H
#define LIMB_INTERNAL_HMAP_H
#include <errno.h>
#include <limb/hmap.h>
#include <limb/gccattributes.h>
#define MINSIZE 8
#define MAXSIZE ((u32) -1 / 2 + 1)
/* IMPORTANT: the stralloc hmap->sa is *NOT* used as expected in here. Indeed,
* we determine the *exact* size we want allocated and ask for it.
*
* Then, sa.a is turned into our mask, i.e. the number of elements - 1
* Similarly, sa.len is used as counter of used elements, but those aren't used
* in order and every element (even empty/zero ones) should be considered in
* use by the hmap.
*/
/* keep in sync w/ fullitem in grow.c */
struct item {
u32 key;
u8 data[];
};
#define DLEN(hmap) (hmap->ilen - sizeof(u32))
#define ITEM(i,hmap) (void *) (hmap->sa.s + (i) * hmap->ilen)
struct item *lookup(u32 key, hmap *hmap) gccattr_hidden;
int grow(size_t n, hmap *hmap) gccattr_hidden;
#endif /* LIMB_INTERNAL_HMAP_H */