yappi / _yhashtab.h

/*
*    An Adaptive Hash Table
*    Sumer Cip 2010
*/

#include "_ystatic.h"

#ifndef YHASHTAB_H
#define YHASHTAB_H

#define HSIZE(n) (1<<n)
#define HMASK(n) (HSIZE(n)-1)
#define SWAP(a, b) (((a) ^= (b)), ((b) ^= (a)), ((a) ^= (b)))
#define HHASH(ht, a) ((a = (a ^ 61) ^ (a >> 16)), \
                      (a = a + (a << 3)), (a = a ^ (a >> 4)),  (a = a * 0x27d4eb2d), \
                      (a = a ^ (a >> 15)), ((unsigned int)(a & ht->mask)))
//#define HHASH(ht, a) ((unsigned int)(a & ht->mask))
#define HLOADFACTOR 0.75

struct _hitem {
    int key;
    uintptr_t val;
    int free; // for recycling.
    struct _hitem *next;
};
typedef struct _hitem _hitem;

typedef struct {
    int realsize;
    int logsize;
    int count;
    int mask;
    int freecount;
    _hitem ** _table;
} _htab;

_htab *htcreate(int logsize);
void htdestroy(_htab *ht);
_hitem *hfind(_htab *ht, int key);
int hadd(_htab *ht, int key, uintptr_t val);
void henum(_htab *ht, int (*fn) (_hitem *item, void *arg), void *arg);
int hcount(_htab *ht);
void hfree(_htab *ht, _hitem *item);

#endif
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.