-
Notifications
You must be signed in to change notification settings - Fork 25
/
hash-table.h
56 lines (48 loc) · 1.19 KB
/
hash-table.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
/* (c) 2008-2016 Mark Hamilton Wright */
#ifndef HASH_TABLE_H
#define HASH_TABLE_H
#include "kmacros.h"
typedef struct {
char *key;
int key_length;
void *item;
} hash_entry_t;
typedef struct {
int size;
hash_entry_t *table;
int occupied;
int tp;
int n_ks;
char **key_space;
int *kp;
int *free_keyspace;
} hash_table_t;
/*
hash_table_t *new_hash_table(int initial_size, int random_seed);
void ht_insert(hash_table_t *ht, char *key, int key_length, void *data);
void ht_delete(hash_table_t *ht, char *key, int key_length);
void *ht_lookup(hash_table_t *ht, char *key, int key_length);
char *ht_nextkey(hash_table_t *ht, int *key_length);
void *ht_nextitem(hash_table_t *ht, char **key, int *key_length);
double ht_collision_ratio(hash_table_t *ht);
void ht_reset(hash_table_t *ht);
void ht_free(hash_table_t *ht);
*/
class HashTable {
public:
HashTable();
HashTable(int initial_size);
HashTable(int initial_size, int random_seed);
~HashTable();
void insert(char *key, void *data);
void *lookup(char *key);
void remove(char *key);
double collision_ratio();
void reset();
char *nextkey();
void *nextitem();
int n_items();
private:
hash_table_t *ht;
};
#endif