-
Notifications
You must be signed in to change notification settings - Fork 61
Expand file tree
/
Copy pathframeofreference.h
More file actions
134 lines (111 loc) · 4.39 KB
/
Copy pathframeofreference.h
File metadata and controls
134 lines (111 loc) · 4.39 KB
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
#ifndef INCLUDE_FRAMEOFREFERENCE_H_
#define INCLUDE_FRAMEOFREFERENCE_H_
#include "common.h"
#include "codecs.h"
#include "util.h"
namespace SIMDCompressionLib {
/**
* Simple implementation of FOR compression using blocks of
* 32 integers.
*
* This implementation is inferior to ForCODEC. Please use
* ForCODEC instead.
*
* FOR does not compress particularly well but it supports
* fast random access.
*/
class FrameOfReference : public IntegerCODEC {
public:
void encodeArray(uint32_t *in, const size_t length, uint32_t *out,
size_t &nvalue) {
*out = static_cast<uint32_t>(
std::min<size_t>(length, std::numeric_limits<uint32_t>::max()));
uint32_t *finalout = compress_length(in, *out, out + 1);
nvalue = finalout - out;
}
const uint32_t *uncompress_length(const uint32_t *in, uint32_t *out,
uint32_t nvalue);
uint32_t *compress_length(const uint32_t *in, uint32_t length, uint32_t *out);
const uint32_t *decodeArray(const uint32_t *in, const size_t, uint32_t *out,
size_t &nvalue) {
nvalue = *in;
in++;
return uncompress_length(in, out, static_cast<uint32_t>(nvalue));
}
// appends the value "value" at the end of the compressed stream. Assumes that
// we have
// the space to do so.
// returns the next (total) size of the compressed output in bytes
// the "currentcompressedsizeinbytes" should be zero when no data has been
// compressed yet
size_t append(uint8_t *inbyte, const size_t currentcompressedsizeinbytes,
uint32_t value);
// append a key.
// Returns the new size of the compressed array *in bytes*
size_t appendToByteArray(uint8_t *in, const size_t bytesize,
uint32_t /*previous_key*/, uint32_t key) {
return append(in, bytesize, key);
}
// Performs a lower bound find in the encoded array.
// Returns the index
size_t findLowerBound(const uint32_t *in, const size_t length, uint32_t key,
uint32_t *presult);
// Returns a decompressed value in an encoded array
uint32_t select(const uint32_t *in, size_t index);
string name() const { return "FrameOfReference"; }
private:
};
/**
* Accelerated implementation of FOR compression using blocks of
* 128 integers. .
*
*
* FOR does not compress particularly well but it supports
* fast random access.
*/
class SIMDFrameOfReference : public IntegerCODEC {
public:
void encodeArray(uint32_t *in, const size_t length, uint32_t *out,
size_t &nvalue) {
*out = static_cast<uint32_t>(
std::min<size_t>(length, std::numeric_limits<uint32_t>::max()));
uint32_t *finalout = simd_compress_length(in, *out, out + 1);
nvalue = finalout - out;
}
const uint32_t *simd_uncompress_length(const uint32_t *in, uint32_t *out,
uint32_t nvalue);
uint32_t *simd_compress_length(const uint32_t *in, uint32_t length,
uint32_t *out);
uint32_t *simd_compress_length_sorted(const uint32_t *in, uint32_t length,
uint32_t *out);
const uint32_t *decodeArray(const uint32_t *in, const size_t, uint32_t *out,
size_t &nvalue) {
nvalue = *in;
in++;
return simd_uncompress_length(in, out, static_cast<uint32_t>(nvalue));
}
// appends the value "value" at the end of the compressed stream. Assumes that
// we have
// the space to do so.
// returns the next (total) size of the compressed output in bytes
// the "currentcompressedsizeinbytes" should be zero when no data has been
// compressed yet
size_t append(uint8_t *inbyte, const size_t currentcompressedsizeinbytes,
uint32_t value);
// append a key.
// Returns the new size of the compressed array *in bytes*
size_t appendToByteArray(uint8_t *in, const size_t bytesize,
uint32_t /* previous_key*/, uint32_t key) {
return append(in, bytesize, key);
}
// Performs a lower bound find in the encoded array.
// Returns the index
size_t findLowerBound(const uint32_t *in, const size_t length, uint32_t key,
uint32_t *presult);
// Returns a decompressed value in an encoded array
uint32_t select(const uint32_t *in, size_t index);
string name() const { return "SIMDFrameOfReference"; }
private:
};
}
#endif /* INCLUDE_FRAMEOFREFERENCE_H_ */