/*
 * Created by jiaqiang.ye@lnxall.com
 *
 * Integer and pointer hash, with string as keys
 *
 * 2022/05/27
 */

#ifndef LNXALL_HASH_H
#define LNXALL_HASH_H 1

#ifdef __cplusplus
extern "C" {
#endif

#define HASH_INTPTR_ERROR_OK            0
#define HASH_INTPTR_ERROR_ARGS          -1
#define HASH_INTPTR_ERROR_NOTFOUND      -2
#define HASH_INTPTR_ERROR_MEMORY        -3

typedef void * lnxhash_t;

int lnxhash_addint(lnxhash_t * a_hash,
	const void * as_key, unsigned int as_len, int a_val);

int lnxhash_addptr(lnxhash_t * a_hash,
	const void * as_key, unsigned int as_len, void * p_val);

int lnxhash_findint(lnxhash_t a_hash,
	const void * as_key, unsigned int as_len, int * a_val);

int lnxhash_findptr(lnxhash_t a_hash,
	const void * as_key, unsigned int as_len, void * * p_val);

int lnxhash_remove(lnxhash_t * a_hash,
	const void * as_key, unsigned int as_len);

int lnxhash_count(lnxhash_t a_hash);

struct lnxhash_iteri {
	const void * keystr;
	unsigned int keylen;
	int i_val;
	void * p_val;
};

int lnxhash_iter(lnxhash_t * a_hash,
	int (* iter_func)(const struct lnxhash_iteri *, int, void *), void * what);

void lnxhash_removeall(lnxhash_t * a_hash);

#ifdef __cplusplus
};
#endif
#endif
