-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathdict.h
86 lines (71 loc) · 2.15 KB
/
dict.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
#ifndef DICT_DICT_H
#define DICT_DICT_H
#include <cstdint>
#include <cstddef>
#include <cstring>
class dictionary_coded_t {
public:
uint64_t * dictionary;
uint32_t dictionary_size;
char *compressed_data;
size_t array_length;// uncompressed length in 64-bit words
uint32_t compressed_data_size;// compressed data in bytes
int bit_width;
dictionary_coded_t() :
dictionary ( NULL),
dictionary_size (0),
compressed_data (NULL),
array_length (0),
compressed_data_size(0),
bit_width (0)
{
}
dictionary_coded_t(const dictionary_coded_t && s) :
dictionary (std::move(s.dictionary)),
dictionary_size (std::move(s.dictionary_size)),
compressed_data (std::move(s.compressed_data)),
array_length (std::move(s.array_length)),
compressed_data_size(std::move(s.compressed_data_size)),
bit_width (std::move(s.bit_width))
{
}
virtual ~dictionary_coded_t() {
delete[] dictionary;
delete[] compressed_data;
init();
}
private:
dictionary_coded_t(const dictionary_coded_t & s) :
dictionary ( NULL),
dictionary_size (0),
compressed_data (NULL),
array_length ( 0),
compressed_data_size(0),
bit_width ( 0)
{
*this = s; // does a deep copy
}
// does a deep copy
dictionary_coded_t& operator=(const dictionary_coded_t & s) {
delete[] dictionary;
delete[] compressed_data;
dictionary = new uint64_t[s.dictionary_size];
memcpy(dictionary,s.dictionary,sizeof(uint64_t)*s.dictionary_size);
dictionary_size = s.dictionary_size;
compressed_data = new char[s.compressed_data_size];
memcpy(compressed_data,s.compressed_data,s.compressed_data_size);
compressed_data_size = s.compressed_data_size;
array_length = s.array_length;
bit_width = s.bit_width;
return *this;
}
void init() {
dictionary = NULL;
compressed_data = NULL;
dictionary_size = 0;
array_length = 0;
compressed_data_size = 0;
bit_width = 0;
}
};
#endif