-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathn_hash_int.h
67 lines (50 loc) · 1.66 KB
/
n_hash_int.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
/*
TRURLib, hash table
Copyright (C) 1999, 2000 Pawel A. Gajda ([email protected])
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
Module is based on:
**
** public domain code by Jerry Coffin.
**
** Tested with Visual C 1.0 and Borland C 3.1.
** Compiles without warnings, and seems like it should be pretty
** portable.
*/
#include <string.h>
#include <stdlib.h>
#include "trurl_internal.h"
#include "nhash.h"
#include "nmalloc.h"
#define USE_HASHSTRING_GLIBC_DB 0
#define USE_HASHSTRING_CDB 1
/*
** A hash table consists of an array of these buckets. Each bucket
** holds a copy of the key, a pointer to the data associated with the
** key, and a pointer to the next bucket that collided with this one,
** if there was one.
*/
struct hash_bucket {
void *data;
char *key;
struct hash_bucket *next;
char _buf[0];
};
struct trurl_hash_table {
uint16_t _refcnt;
uint16_t flags;
size_t size;
struct hash_bucket **table;
size_t items;
void (*free_fn) (void *);
unsigned int (*hash_fn) (const char*);
tn_alloc *na;
};
int n_hash_dohash(const tn_hash *ht, const char *s, int *slen);
#define n_hash_nextslotv(key, klen) (klen + (int)key[klen - 1])
struct hash_bucket *n_hash_get_bucket(const tn_hash *ht,
const char *key, int klen, unsigned val);
int n_hash_exists_ex(const tn_hash *ht, const char *key, int *klen,
unsigned *khash);