Remove hashtable
FossilOrigin-Name: 67c14216600680678ab5dc15b2b1edaef586067c22b784b4bcea6b4221883d50
This commit is contained in:
parent
e45c8234e8
commit
7259232e13
1 changed files with 0 additions and 65 deletions
65
src/tools.h
65
src/tools.h
|
@ -317,71 +317,6 @@ template <class T> struct vector {
|
|||
} else \
|
||||
for (int i = (v).length() - 1; i >= 0; i--)
|
||||
|
||||
template <class T> struct hashtable {
|
||||
struct chain {
|
||||
chain *next;
|
||||
const char *key;
|
||||
T data;
|
||||
};
|
||||
|
||||
int size;
|
||||
int numelems;
|
||||
chain **table;
|
||||
pool *parent;
|
||||
chain *enumc;
|
||||
|
||||
hashtable()
|
||||
{
|
||||
this->size = 1 << 10;
|
||||
this->parent = gp();
|
||||
numelems = 0;
|
||||
table = (chain **)parent->alloc(size * sizeof(T));
|
||||
for (int i = 0; i < size; i++)
|
||||
table[i] = NULL;
|
||||
};
|
||||
|
||||
hashtable(hashtable<T> &v);
|
||||
void operator=(hashtable<T> &v);
|
||||
|
||||
T *
|
||||
access(const char *key, T *data = NULL)
|
||||
{
|
||||
unsigned int h = 5381;
|
||||
for (int i = 0, k; k = key[i]; i++)
|
||||
h = ((h << 5) + h) ^ k; // bernstein k=33 xor
|
||||
h = h & (size - 1); // primes not much of an advantage
|
||||
for (chain *c = table[h]; c; c = c->next) {
|
||||
char ch;
|
||||
for (const char *p1 = key, *p2 = c->key;
|
||||
(ch = *p1++) == *p2++;)
|
||||
if (!ch) // if(strcmp(key,c->key)==0)
|
||||
{
|
||||
T *d = &c->data;
|
||||
if (data)
|
||||
c->data = *data;
|
||||
return d;
|
||||
}
|
||||
}
|
||||
if (data) {
|
||||
chain *c = (chain *)parent->alloc(sizeof(chain));
|
||||
c->data = *data;
|
||||
c->key = key;
|
||||
c->next = table[h];
|
||||
table[h] = c;
|
||||
numelems++;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
};
|
||||
|
||||
#define enumerate(ht, t, e, b) \
|
||||
loopi(ht->size) for (ht->enumc = ht->table[i]; ht->enumc; \
|
||||
ht->enumc = ht->enumc->next) \
|
||||
{ \
|
||||
t e = &ht->enumc->data; \
|
||||
b; \
|
||||
}
|
||||
|
||||
inline char *
|
||||
newstring(const char *s)
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue