-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhashtable.h
121 lines (106 loc) · 5.62 KB
/
hashtable.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
#ifndef MEMLINK_HASHTABLE_H
#define MEMLINK_HASHTABLE_H
#include <stdio.h>
#include "mem.h"
#include "common.h"
#include "conn.h"
typedef struct _memlink_hashnode
{
char *key;
DataBlock *data; // DataBlock link
DataBlock *data_tail; // DataBlock link tail
struct _memlink_hashnode *next;
uint32_t used; // used data item
uint32_t all; // all data item;
}HashNode;
typedef struct _memlink_table
{
char name[HASHTABLE_TABLE_NAME_SIZE];
uint8_t listtype; // list type: list/queue/sortlist
uint8_t valuetype; // value type for sortlist
uint16_t valuesize;
uint8_t sortfield; // which sort? 0:value, 1-255:attr[0-254]
uint8_t attrnum; // number of attribute format
uint8_t attrsize; // byte of attribute
uint8_t *attrformat; // attribute format, eg: 3:4:5 => [3, 4, 5]
HashNode **nodes;
struct _memlink_table *next;
}Table;
// table name =>Table + key => Node
typedef struct _memlink_hashtable
{
Table *tables[HASHTABLE_MAX_TABLE];
int table_count;
}HashTable;
int check_table_key(char *name, char *key);
Table* table_create(char *name, int valuesize, uint32_t *attrarray, uint8_t attrnum,
uint8_t listtype, uint8_t valuetype);
void table_clear(Table *tb);
void table_destroy(Table *tb);
uint8_t* table_attrformat(Table *tb);
int table_find_value(Table *tb, char *key, void *value,
HashNode **node, DataBlock **dbk, char **data);
int table_find_value_pos(Table *tb, char *key, void *value,
HashNode **node, DataBlock **dbk);
HashNode* table_find(Table *tb, char *key);
int table_print(Table *tb, char *key);
int table_check(Table *tb, char *key);
int table_create_node(Table *tb, char *key);
int hashnode_check(Table*, HashNode *node);
HashTable* hashtable_create();
void hashtable_destroy(HashTable *ht);
Table* hashtable_find_table(HashTable *ht, char *name);
//Table* hashtable_get_table(HashTable *ht, char *keybuf, char **name, char **key);
int hashtable_create_table(HashTable *ht, char *name, int valuesize,
uint32_t *attrarray, uint8_t attrnum,
uint8_t listtype, uint8_t valuetype);
int hashtable_create_node(HashTable *ht, char *tbname, char *key);
void hashtable_clear_all(HashTable *ht);
uint32_t hashtable_node_hash(char *key, int len);
uint32_t hashtable_table_hash(char *key, int len);
int hashtable_tables(HashTable *ht, char **data);
int hashtable_remove_table(HashTable *ht, char *tbname);
int hashtable_remove_key(HashTable *ht, char *tbname, char *key);
int hashtable_clear_key(HashTable *ht, char *tbname, char *key);
int hashtable_insert(HashTable *ht, char *tbname, char *key, void *value,
uint32_t *attrarray, char attrnum, int pos);
int hashtable_insert_binattr(HashTable *ht, char *tbname, char *key, void *value,
void *attr, int pos);
int hashtable_move(HashTable *ht, char *tbname, char *key, void *value, int pos);
int hashtable_del(HashTable *ht, char *tbname, char *key, void *value);
int hashtable_tag(HashTable *ht, char *tbname, char *key, void *value, uint8_t tag);
int hashtable_attr(HashTable *ht, char *tbname, char *key, void *value,
uint32_t *attrarray, int attrnum);
int hashtable_attr_inc(HashTable *ht, char *tbname, char *key, void *value,
uint32_t *attrarray, int attrnum);
//int hashtable_attr_dec(HashTable *ht, char *tbname, char *key, void *value, uint32_t *attrarray, int attrnum);
int hashtable_range(HashTable *ht, char *tbname, char *key,
uint8_t kind, uint32_t *attrarray, int attrnum,
int frompos, int len, Conn *conn);
int hashtable_clean(HashTable *ht, char *tbname, char *key);
int hashtable_clean_all(HashTable *ht);
int hashtable_stat(HashTable *ht, char *tbname, char *key, HashTableStat *stat);
int hashtable_stat_table(HashTable *ht, char *tbname, HashTableStatSys *stat);
int hashtable_stat_sys(HashTable *ht, HashTableStatSys *stat);
int hashtable_count(HashTable *ht, char *tbname, char *key, uint32_t *attrarray, int attrnum,
int *visible_count, int *tagdel_count);
int hashtable_lpush(HashTable *ht, char *tbname, char *key,
void *value, uint32_t *attrarray, char attrnum);
int hashtable_rpush(HashTable *ht, char *tbname, char *key,
void *value, uint32_t *attrarray, char attrnum);
int hashtable_lpop(HashTable *ht, char *tbname, char *key, int num, Conn *conn);
int hashtable_rpop(HashTable *ht, char *tbname, char *key, int num, Conn *conn);
int hashtable_del_by_attr(HashTable *ht, char *tbname, char *key, uint32_t *attrarray, int attrnum);
// for sortlist
int hashtable_sortlist_mdel(HashTable *ht, char *tbname, char *key,
uint8_t kind, void *valmin, void *valmax,
uint32_t *attrarray, uint8_t attrnum);
int hashtable_sortlist_count(HashTable *ht, char *tbname, char *key,
uint32_t *attrarray, int attrnum,
void* valmin, void *valmax, int *visible_count, int *tagdel_count);
int hashtable_sortlist_range(HashTable *ht, char *tbname, char *key, uint8_t kind,
uint32_t *attrarray, int attrnum, void *valmin,
void *valmax, Conn *conn);
int hashtable_sortlist_insert_binattr(HashTable *ht, char *tbname, char *key, void *value, void *attr);
int hashtable_sortlist_insert(HashTable *ht, char *tbname, char *key, void *value, uint32_t *attrarray, char attrnum);
#endif