Blame jemalloc/include/jemalloc/internal/ckh.h

Packit Service 724aca
#ifndef JEMALLOC_INTERNAL_CKH_H
Packit Service 724aca
#define JEMALLOC_INTERNAL_CKH_H
Packit Service 724aca
Packit Service 724aca
#include "jemalloc/internal/tsd.h"
Packit Service 724aca
Packit Service 724aca
/* Cuckoo hashing implementation.  Skip to the end for the interface. */
Packit Service 724aca
Packit Service 724aca
/******************************************************************************/
Packit Service 724aca
/* INTERNAL DEFINITIONS -- IGNORE */
Packit Service 724aca
/******************************************************************************/
Packit Service 724aca
Packit Service 724aca
/* Maintain counters used to get an idea of performance. */
Packit Service 724aca
/* #define CKH_COUNT */
Packit Service 724aca
/* Print counter values in ckh_delete() (requires CKH_COUNT). */
Packit Service 724aca
/* #define CKH_VERBOSE */
Packit Service 724aca
Packit Service 724aca
/*
Packit Service 724aca
 * There are 2^LG_CKH_BUCKET_CELLS cells in each hash table bucket.  Try to fit
Packit Service 724aca
 * one bucket per L1 cache line.
Packit Service 724aca
 */
Packit Service 724aca
#define LG_CKH_BUCKET_CELLS (LG_CACHELINE - LG_SIZEOF_PTR - 1)
Packit Service 724aca
Packit Service 724aca
/* Typedefs to allow easy function pointer passing. */
Packit Service 724aca
typedef void ckh_hash_t (const void *, size_t[2]);
Packit Service 724aca
typedef bool ckh_keycomp_t (const void *, const void *);
Packit Service 724aca
Packit Service 724aca
/* Hash table cell. */
Packit Service 724aca
typedef struct {
Packit Service 724aca
	const void *key;
Packit Service 724aca
	const void *data;
Packit Service 724aca
} ckhc_t;
Packit Service 724aca
Packit Service 724aca
/* The hash table itself. */
Packit Service 724aca
typedef struct {
Packit Service 724aca
#ifdef CKH_COUNT
Packit Service 724aca
	/* Counters used to get an idea of performance. */
Packit Service 724aca
	uint64_t ngrows;
Packit Service 724aca
	uint64_t nshrinks;
Packit Service 724aca
	uint64_t nshrinkfails;
Packit Service 724aca
	uint64_t ninserts;
Packit Service 724aca
	uint64_t nrelocs;
Packit Service 724aca
#endif
Packit Service 724aca
Packit Service 724aca
	/* Used for pseudo-random number generation. */
Packit Service 724aca
	uint64_t prng_state;
Packit Service 724aca
Packit Service 724aca
	/* Total number of items. */
Packit Service 724aca
	size_t count;
Packit Service 724aca
Packit Service 724aca
	/*
Packit Service 724aca
	 * Minimum and current number of hash table buckets.  There are
Packit Service 724aca
	 * 2^LG_CKH_BUCKET_CELLS cells per bucket.
Packit Service 724aca
	 */
Packit Service 724aca
	unsigned lg_minbuckets;
Packit Service 724aca
	unsigned lg_curbuckets;
Packit Service 724aca
Packit Service 724aca
	/* Hash and comparison functions. */
Packit Service 724aca
	ckh_hash_t *hash;
Packit Service 724aca
	ckh_keycomp_t *keycomp;
Packit Service 724aca
Packit Service 724aca
	/* Hash table with 2^lg_curbuckets buckets. */
Packit Service 724aca
	ckhc_t *tab;
Packit Service 724aca
} ckh_t;
Packit Service 724aca
Packit Service 724aca
/******************************************************************************/
Packit Service 724aca
/* BEGIN PUBLIC API */
Packit Service 724aca
/******************************************************************************/
Packit Service 724aca
Packit Service 724aca
/* Lifetime management.  Minitems is the initial capacity. */
Packit Service 724aca
bool ckh_new(tsd_t *tsd, ckh_t *ckh, size_t minitems, ckh_hash_t *hash,
Packit Service 724aca
    ckh_keycomp_t *keycomp);
Packit Service 724aca
void ckh_delete(tsd_t *tsd, ckh_t *ckh);
Packit Service 724aca
Packit Service 724aca
/* Get the number of elements in the set. */
Packit Service 724aca
size_t ckh_count(ckh_t *ckh);
Packit Service 724aca
Packit Service 724aca
/*
Packit Service 724aca
 * To iterate over the elements in the table, initialize *tabind to 0 and call
Packit Service 724aca
 * this function until it returns true.  Each call that returns false will
Packit Service 724aca
 * update *key and *data to the next element in the table, assuming the pointers
Packit Service 724aca
 * are non-NULL.
Packit Service 724aca
 */
Packit Service 724aca
bool ckh_iter(ckh_t *ckh, size_t *tabind, void **key, void **data);
Packit Service 724aca
Packit Service 724aca
/*
Packit Service 724aca
 * Basic hash table operations -- insert, removal, lookup.  For ckh_remove and
Packit Service 724aca
 * ckh_search, key or data can be NULL.  The hash-table only stores pointers to
Packit Service 724aca
 * the key and value, and doesn't do any lifetime management.
Packit Service 724aca
 */
Packit Service 724aca
bool ckh_insert(tsd_t *tsd, ckh_t *ckh, const void *key, const void *data);
Packit Service 724aca
bool ckh_remove(tsd_t *tsd, ckh_t *ckh, const void *searchkey, void **key,
Packit Service 724aca
    void **data);
Packit Service 724aca
bool ckh_search(ckh_t *ckh, const void *searchkey, void **key, void **data);
Packit Service 724aca
Packit Service 724aca
/* Some useful hash and comparison functions for strings and pointers. */
Packit Service 724aca
void ckh_string_hash(const void *key, size_t r_hash[2]);
Packit Service 724aca
bool ckh_string_keycomp(const void *k1, const void *k2);
Packit Service 724aca
void ckh_pointer_hash(const void *key, size_t r_hash[2]);
Packit Service 724aca
bool ckh_pointer_keycomp(const void *k1, const void *k2);
Packit Service 724aca
Packit Service 724aca
#endif /* JEMALLOC_INTERNAL_CKH_H */