-
Notifications
You must be signed in to change notification settings - Fork 9
/
HashTable.h
85 lines (66 loc) · 1.95 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
#ifndef HASHTABLEH
#define HASHTABLEH
#include <string>
#include <vector>
#include "SECPK1/Point.h"
#include "Constants.h"
#ifdef WIN64
#include <Windows.h>
#endif
#define HASH_SIZE_BIT 18
#define HASH_SIZE (1<<HASH_SIZE_BIT)
#define HASH_MASK (HASH_SIZE-1)
#define ADD_OK 0
#define ADD_DUPLICATE 1
#define ADD_COLLISION 2
union int256_s {
uint8_t i8[32];
uint16_t i16[16];
uint32_t i32[8];
uint64_t i64[4];
};
typedef union int256_s int256_t;
#define safe_free(x) if(x) {free(x);x=NULL;}
typedef struct {
int256_t x; // Position of kangaroo (256bit LSB)
int256_t d; // Travelled distance (b255..b0 distance)
uint32_t kType; // Kangaroo type
} ENTRY;
typedef struct {
uint32_t nbItem;
uint32_t maxItem;
ENTRY **items;
} HASH_ENTRY;
class HashTable {
public:
HashTable();
int Add(Int *x,Int *d, uint32_t type);
int Add(int256_t *x,int256_t *d, uint32_t type);
int Add(uint64_t h,ENTRY *e);
uint64_t GetNbItem();
void Reset();
std::string GetSizeInfo();
void PrintInfo();
void SaveTable(FILE *f);
void SaveTable(FILE* f,uint32_t from,uint32_t to,bool printPoint=true);
void LoadTable(FILE *f);
void LoadTable(FILE* f,uint32_t from,uint32_t to);
void ReAllocate(uint64_t h,uint32_t add);
void SeekNbItem(FILE* f,bool restorePos = false);
void SeekNbItem(FILE* f,uint32_t from,uint32_t to);
HASH_ENTRY E[HASH_SIZE];
// Collision info
Int kDist;
uint32_t kType;
static void Convert(Int *x,Int *d,int256_t *X,int256_t *D);
static int MergeH(uint32_t h,FILE* f1,FILE* f2,FILE* fd,uint32_t *nbDP,uint32_t* duplicate,
Int* d1,uint32_t* k1,Int* d2,uint32_t* k2);
static void CalcDist(int256_t *d,Int* kDist);
static void toint256t(Int *a, int256_t *b);
static void toInt(int256_t *a, Int *b);
private:
ENTRY *CreateEntry(int256_t *x,int256_t *d, uint32_t kType);
static int compare(int256_t *i1,int256_t *i2);
std::string GetStr(int256_t *i);
};
#endif // HASHTABLEH