-
Notifications
You must be signed in to change notification settings - Fork 32
/
Copy pathHashTable.h
93 lines (69 loc) · 1.99 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
/*
* This file is part of the BTCCollider distribution (https://github.com/JeanLucPons/BTCCollider).
* Copyright (c) 2020 Jean Luc PONS.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef HASHTABLEH
#define HASHTABLEH
#include <string>
#define HASH_SIZE 65536
union hash160_s {
uint8_t i8[20];
uint16_t i16[10];
uint32_t i32[5];
uint64_t i64[3];
};
typedef union hash160_s hash160_t;
typedef struct ENTRY {
hash160_t start;
hash160_t end;
} ENTRY;
typedef struct {
uint32_t nbItem;
uint32_t maxItem;
ENTRY **items;
} HASH_ENTRY;
#define NO_COLLISION 0
#define COLLISION 1
#define FALSE_COLLISION 2
class HashTable {
public:
HashTable();
void SetParam(int n,int nbFull,uint16_t colMask);
int AddHash(hash160_t *start, hash160_t *end);
void SaveTable(FILE *f);
void LoadTable(FILE *f);
std::string GetHashStr(hash160_t *h);
void PrintTable(int limit=0);
int GetNbItem();
int getCollisionSize(hash160_t *h1, hash160_t *h2);
void getCollision(hash160_t *a, hash160_t *b, hash160_t *e);
void Reset();
bool hashCollide(hash160_t *h1, hash160_t *h2);
int compareHash(hash160_t *h1, hash160_t *h2);
bool compare(HashTable *ht);
uint16_t getHash(hash160_t *h);
ENTRY *CreateEntry(hash160_t *h1, hash160_t *h2);
double GetSizeMB();
private:
HASH_ENTRY E[HASH_SIZE];
int cSize;
int nbFull;
int totalItem;
uint16_t colMask;
hash160_t a;
hash160_t b;
hash160_t e;
};
#endif // HASHTABLEH