-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathgent_list.h
executable file
·141 lines (122 loc) · 2.44 KB
/
gent_list.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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
//
// gent_list.h
// riser
//
// Created by wyt on 13-5-4.
// Copyright (c) 2013年 wyt. All rights reserved.
//
#ifndef riser_gent_list_h
#define riser_gent_list_h
#include "prefine.h"
#include <sys/mman.h>
#include <sys/stat.h>
#define hashsize(n) ((uint64_t)1<<(n))
#define hashmask(n) ((hashsize(n+3))-1)
const uint8_t posnum = 16;
typedef struct hashTable
{
byte table;
uint8_t rel_count[8];
}hashTables;
class HashInter
{
uint8_t posval[8];
uint8_t posvalrev[8];
CommLock hash_lock;
public:
HashInter();
virtual ~HashInter();
private:
uint8_t Position(char *key,int isget=1);
protected:
HashInter *successor;
// byte* tables;
hashTables *tables;
string filename;
int fd;
public:
virtual uint64_t Hash(char *) = 0;
void Set(char *key);
int Get(char *key, int parent);
void Del(char *key);
void Init();
void SetSuccessor(HashInter *s);
};
class SDBMHash : public HashInter
{
public:
SDBMHash(string &path){
filename = path+"sdbm.dat";
successor = NULL;
}
~SDBMHash(){
}
public:
uint64_t Hash(char *str)
{
uint64_t hash = 0;
while (*str)
{
hash = (*str++) + (hash << 6) + (hash << 16) - hash;
}
return (hash & 0x7FFFFFFF) & hashmask(posnum);
}
};
class RSHash : public HashInter
{
public:
RSHash(string &path){
filename = path+"rs.dat";
successor = NULL;
}
~RSHash(){}
uint64_t Hash(char *str)
{
uint64_t b = 378551;
uint64_t a = 63689;
uint64_t hash = 0;
while (*str)
{
hash = hash * a + (*str++);
a *= b;
}
return (hash & 0x7FFFFFFF) & hashmask(posnum);
}
};
class JSHash : public HashInter
{
public:
JSHash(string &path){
filename = path+"js.dat";
successor = NULL;
}
~JSHash(){
}
uint64_t Hash(char *str)
{
uint64_t hash = 1315423911;
while (*str)
{
hash ^= ((hash << 5) + (*str++) + (hash >> 2));
}
return (hash & 0x7FFFFFFF) & hashmask(posnum);
}
};
class GentList
{
static GentList *intance_;
list<HashInter *> hashList;
HashInter *mainHash;
public:
static GentList *Instance();
static void UnInstance();
public:
GentList();
~GentList();
public:
void Init();
void Save(string &k);
int Load(string &k);
void Clear(string &k);
};
#endif