rrudb 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.yardopts +1 -0
- data/LICENSE.txt +22 -0
- data/README.md +26 -0
- data/examples/example.rb +39 -0
- data/ext/rudb/NuDB/include/nudb/CMakeLists.txt +104 -0
- data/ext/rudb/NuDB/include/nudb/_experimental/basic_seconds_clock.hpp +200 -0
- data/ext/rudb/NuDB/include/nudb/_experimental/chrono_util.hpp +58 -0
- data/ext/rudb/NuDB/include/nudb/_experimental/test/fail_file.hpp +343 -0
- data/ext/rudb/NuDB/include/nudb/_experimental/test/temp_dir.hpp +73 -0
- data/ext/rudb/NuDB/include/nudb/_experimental/test/test_store.hpp +451 -0
- data/ext/rudb/NuDB/include/nudb/_experimental/test/xor_shift_engine.hpp +105 -0
- data/ext/rudb/NuDB/include/nudb/_experimental/util.hpp +288 -0
- data/ext/rudb/NuDB/include/nudb/basic_store.hpp +461 -0
- data/ext/rudb/NuDB/include/nudb/concepts.hpp +205 -0
- data/ext/rudb/NuDB/include/nudb/context.hpp +144 -0
- data/ext/rudb/NuDB/include/nudb/create.hpp +117 -0
- data/ext/rudb/NuDB/include/nudb/detail/arena.hpp +296 -0
- data/ext/rudb/NuDB/include/nudb/detail/bucket.hpp +473 -0
- data/ext/rudb/NuDB/include/nudb/detail/buffer.hpp +86 -0
- data/ext/rudb/NuDB/include/nudb/detail/bulkio.hpp +196 -0
- data/ext/rudb/NuDB/include/nudb/detail/cache.hpp +236 -0
- data/ext/rudb/NuDB/include/nudb/detail/endian.hpp +93 -0
- data/ext/rudb/NuDB/include/nudb/detail/field.hpp +265 -0
- data/ext/rudb/NuDB/include/nudb/detail/format.hpp +630 -0
- data/ext/rudb/NuDB/include/nudb/detail/gentex.hpp +259 -0
- data/ext/rudb/NuDB/include/nudb/detail/mutex.hpp +26 -0
- data/ext/rudb/NuDB/include/nudb/detail/pool.hpp +243 -0
- data/ext/rudb/NuDB/include/nudb/detail/store_base.hpp +45 -0
- data/ext/rudb/NuDB/include/nudb/detail/stream.hpp +149 -0
- data/ext/rudb/NuDB/include/nudb/detail/xxhash.hpp +328 -0
- data/ext/rudb/NuDB/include/nudb/error.hpp +257 -0
- data/ext/rudb/NuDB/include/nudb/file.hpp +55 -0
- data/ext/rudb/NuDB/include/nudb/impl/basic_store.ipp +785 -0
- data/ext/rudb/NuDB/include/nudb/impl/context.ipp +241 -0
- data/ext/rudb/NuDB/include/nudb/impl/create.ipp +163 -0
- data/ext/rudb/NuDB/include/nudb/impl/error.ipp +175 -0
- data/ext/rudb/NuDB/include/nudb/impl/posix_file.ipp +248 -0
- data/ext/rudb/NuDB/include/nudb/impl/recover.ipp +209 -0
- data/ext/rudb/NuDB/include/nudb/impl/rekey.ipp +248 -0
- data/ext/rudb/NuDB/include/nudb/impl/verify.ipp +634 -0
- data/ext/rudb/NuDB/include/nudb/impl/visit.ipp +96 -0
- data/ext/rudb/NuDB/include/nudb/impl/win32_file.ipp +264 -0
- data/ext/rudb/NuDB/include/nudb/native_file.hpp +76 -0
- data/ext/rudb/NuDB/include/nudb/nudb.hpp +27 -0
- data/ext/rudb/NuDB/include/nudb/posix_file.hpp +228 -0
- data/ext/rudb/NuDB/include/nudb/progress.hpp +32 -0
- data/ext/rudb/NuDB/include/nudb/recover.hpp +73 -0
- data/ext/rudb/NuDB/include/nudb/rekey.hpp +110 -0
- data/ext/rudb/NuDB/include/nudb/store.hpp +27 -0
- data/ext/rudb/NuDB/include/nudb/type_traits.hpp +63 -0
- data/ext/rudb/NuDB/include/nudb/verify.hpp +200 -0
- data/ext/rudb/NuDB/include/nudb/version.hpp +21 -0
- data/ext/rudb/NuDB/include/nudb/visit.hpp +63 -0
- data/ext/rudb/NuDB/include/nudb/win32_file.hpp +246 -0
- data/ext/rudb/NuDB/include/nudb/xxhasher.hpp +45 -0
- data/ext/rudb/extconf.rb +12 -0
- data/ext/rudb/rudb.cpp +234 -0
- data/lib/rudb/version.rb +3 -0
- data/lib/rudb.rb +1 -0
- metadata +104 -0
@@ -0,0 +1,265 @@
|
|
1
|
+
//
|
2
|
+
// Copyright (c) 2015-2016 Vinnie Falco (vinnie dot falco at gmail dot com)
|
3
|
+
//
|
4
|
+
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
5
|
+
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
6
|
+
//
|
7
|
+
|
8
|
+
#ifndef NUDB_FIELD_HPP
|
9
|
+
#define NUDB_FIELD_HPP
|
10
|
+
|
11
|
+
#include <nudb/detail/stream.hpp>
|
12
|
+
#include <boost/assert.hpp>
|
13
|
+
#include <cstddef>
|
14
|
+
#include <cstdint>
|
15
|
+
#include <limits>
|
16
|
+
#include <stdexcept>
|
17
|
+
#include <type_traits>
|
18
|
+
|
19
|
+
namespace nudb {
|
20
|
+
namespace detail {
|
21
|
+
|
22
|
+
// A 24-bit integer
|
23
|
+
struct uint24_t;
|
24
|
+
|
25
|
+
// A 48-bit integer
|
26
|
+
struct uint48_t;
|
27
|
+
|
28
|
+
// These metafunctions describe the binary format of fields on disk
|
29
|
+
|
30
|
+
template<class T>
|
31
|
+
struct field;
|
32
|
+
|
33
|
+
template<>
|
34
|
+
struct field<std::uint8_t>
|
35
|
+
{
|
36
|
+
static std::size_t constexpr size = 1;
|
37
|
+
static std::uint64_t constexpr max = 0xff;
|
38
|
+
};
|
39
|
+
|
40
|
+
template<>
|
41
|
+
struct field<std::uint16_t>
|
42
|
+
{
|
43
|
+
static std::size_t constexpr size = 2;
|
44
|
+
static std::uint64_t constexpr max = 0xffff;
|
45
|
+
};
|
46
|
+
|
47
|
+
template<>
|
48
|
+
struct field<uint24_t>
|
49
|
+
{
|
50
|
+
static std::size_t constexpr size = 3;
|
51
|
+
static std::uint64_t constexpr max = 0xffffff;
|
52
|
+
};
|
53
|
+
|
54
|
+
template<>
|
55
|
+
struct field<std::uint32_t>
|
56
|
+
{
|
57
|
+
static std::size_t constexpr size = 4;
|
58
|
+
static std::uint64_t constexpr max = 0xffffffff;
|
59
|
+
};
|
60
|
+
|
61
|
+
template<>
|
62
|
+
struct field<uint48_t>
|
63
|
+
{
|
64
|
+
static std::size_t constexpr size = 6;
|
65
|
+
static std::uint64_t constexpr max = 0x0000ffffffffffff;
|
66
|
+
};
|
67
|
+
|
68
|
+
template<>
|
69
|
+
struct field<std::uint64_t>
|
70
|
+
{
|
71
|
+
static std::size_t constexpr size = 8;
|
72
|
+
static std::uint64_t constexpr max = 0xffffffffffffffff;
|
73
|
+
};
|
74
|
+
|
75
|
+
// read field from memory
|
76
|
+
|
77
|
+
template<class T, class U, typename std::enable_if<
|
78
|
+
std::is_same<T, std::uint8_t>::value>::type* = nullptr>
|
79
|
+
void
|
80
|
+
readp(void const* v, U& u)
|
81
|
+
{
|
82
|
+
auto p = reinterpret_cast<std::uint8_t const*>(v);
|
83
|
+
u = *p;
|
84
|
+
}
|
85
|
+
|
86
|
+
template<class T, class U, typename std::enable_if<
|
87
|
+
std::is_same<T, std::uint16_t>::value>::type* = nullptr>
|
88
|
+
void
|
89
|
+
readp(void const* v, U& u)
|
90
|
+
{
|
91
|
+
auto p = reinterpret_cast<std::uint8_t const*>(v);
|
92
|
+
T t;
|
93
|
+
t = T(*p++)<< 8;
|
94
|
+
t = T(*p ) | t;
|
95
|
+
u = t;
|
96
|
+
}
|
97
|
+
|
98
|
+
template<class T, class U, typename std::enable_if<
|
99
|
+
std::is_same<T, uint24_t>::value>::type* = nullptr>
|
100
|
+
void
|
101
|
+
readp(void const* v, U& u)
|
102
|
+
{
|
103
|
+
auto p = reinterpret_cast<std::uint8_t const*>(v);
|
104
|
+
std::uint32_t t;
|
105
|
+
t = std::uint32_t(*p++)<<16;
|
106
|
+
t = (std::uint32_t(*p++)<< 8) | t;
|
107
|
+
t = std::uint32_t(*p ) | t;
|
108
|
+
u = t;
|
109
|
+
}
|
110
|
+
|
111
|
+
template<class T, class U, typename std::enable_if<
|
112
|
+
std::is_same<T, std::uint32_t>::value>::type* = nullptr>
|
113
|
+
void
|
114
|
+
readp(void const* v, U& u)
|
115
|
+
{
|
116
|
+
auto const* p = reinterpret_cast<std::uint8_t const*>(v);
|
117
|
+
T t;
|
118
|
+
t = T(*p++)<<24;
|
119
|
+
t = (T(*p++)<<16) | t;
|
120
|
+
t = (T(*p++)<< 8) | t;
|
121
|
+
t = T(*p ) | t;
|
122
|
+
u = t;
|
123
|
+
}
|
124
|
+
|
125
|
+
template<class T, class U, typename std::enable_if<
|
126
|
+
std::is_same<T, uint48_t>::value>::type* = nullptr>
|
127
|
+
void
|
128
|
+
readp(void const* v, U& u)
|
129
|
+
{
|
130
|
+
auto p = reinterpret_cast<std::uint8_t const*>(v);
|
131
|
+
std::uint64_t t;
|
132
|
+
t = (std::uint64_t(*p++)<<40);
|
133
|
+
t = (std::uint64_t(*p++)<<32) | t;
|
134
|
+
t = (std::uint64_t(*p++)<<24) | t;
|
135
|
+
t = (std::uint64_t(*p++)<<16) | t;
|
136
|
+
t = (std::uint64_t(*p++)<< 8) | t;
|
137
|
+
t = std::uint64_t(*p ) | t;
|
138
|
+
u = t;
|
139
|
+
}
|
140
|
+
|
141
|
+
template<class T, class U, typename std::enable_if<
|
142
|
+
std::is_same<T, std::uint64_t>::value>::type* = nullptr>
|
143
|
+
void
|
144
|
+
readp(void const* v, U& u)
|
145
|
+
{
|
146
|
+
auto p = reinterpret_cast<std::uint8_t const*>(v);
|
147
|
+
T t;
|
148
|
+
t = T(*p++)<<56;
|
149
|
+
t = (T(*p++)<<48) | t;
|
150
|
+
t = (T(*p++)<<40) | t;
|
151
|
+
t = (T(*p++)<<32) | t;
|
152
|
+
t = (T(*p++)<<24) | t;
|
153
|
+
t = (T(*p++)<<16) | t;
|
154
|
+
t = (T(*p++)<< 8) | t;
|
155
|
+
t = T(*p ) | t;
|
156
|
+
u = t;
|
157
|
+
}
|
158
|
+
|
159
|
+
// read field from istream
|
160
|
+
|
161
|
+
template<class T, class U>
|
162
|
+
void
|
163
|
+
read(istream& is, U& u)
|
164
|
+
{
|
165
|
+
readp<T>(is.data(field<T>::size), u);
|
166
|
+
}
|
167
|
+
|
168
|
+
inline
|
169
|
+
void
|
170
|
+
read_size48(istream& is, std::size_t& u)
|
171
|
+
{
|
172
|
+
std::uint64_t v;
|
173
|
+
read<uint48_t>(is, v);
|
174
|
+
BOOST_ASSERT(v <= std::numeric_limits<std::uint32_t>::max());
|
175
|
+
u = static_cast<std::uint32_t>(v);
|
176
|
+
}
|
177
|
+
|
178
|
+
// write field to ostream
|
179
|
+
|
180
|
+
template<class T, class U, typename std::enable_if<
|
181
|
+
std::is_same<T, std::uint8_t>::value>::type* = nullptr>
|
182
|
+
void
|
183
|
+
write(ostream& os, U u)
|
184
|
+
{
|
185
|
+
BOOST_ASSERT(u <= field<T>::max);
|
186
|
+
std::uint8_t* p = os.data(field<T>::size);
|
187
|
+
*p = static_cast<std::uint8_t>(u);
|
188
|
+
}
|
189
|
+
|
190
|
+
template<class T, class U, typename std::enable_if<
|
191
|
+
std::is_same<T, std::uint16_t>::value>::type* = nullptr>
|
192
|
+
void
|
193
|
+
write(ostream& os, U u)
|
194
|
+
{
|
195
|
+
BOOST_ASSERT(u <= field<T>::max);
|
196
|
+
auto const t = static_cast<T>(u);
|
197
|
+
std::uint8_t* p = os.data(field<T>::size);
|
198
|
+
*p++ = (t>> 8)&0xff;
|
199
|
+
*p = t &0xff;
|
200
|
+
}
|
201
|
+
|
202
|
+
template<class T, class U, typename std::enable_if<
|
203
|
+
std::is_same<T, uint24_t>::value>::type* = nullptr>
|
204
|
+
void
|
205
|
+
write(ostream& os, U u)
|
206
|
+
{
|
207
|
+
BOOST_ASSERT(u <= field<T>::max);
|
208
|
+
auto const t = static_cast<std::uint32_t>(u);
|
209
|
+
std::uint8_t* p = os.data(field<T>::size);
|
210
|
+
*p++ = (t>>16)&0xff;
|
211
|
+
*p++ = (t>> 8)&0xff;
|
212
|
+
*p = t &0xff;
|
213
|
+
}
|
214
|
+
|
215
|
+
template<class T, class U, typename std::enable_if<
|
216
|
+
std::is_same<T, std::uint32_t>::value>::type* = nullptr>
|
217
|
+
void
|
218
|
+
write(ostream& os, U u)
|
219
|
+
{
|
220
|
+
BOOST_ASSERT(u <= field<T>::max);
|
221
|
+
auto const t = static_cast<T>(u);
|
222
|
+
std::uint8_t* p = os.data(field<T>::size);
|
223
|
+
*p++ = (t>>24)&0xff;
|
224
|
+
*p++ = (t>>16)&0xff;
|
225
|
+
*p++ = (t>> 8)&0xff;
|
226
|
+
*p = t &0xff;
|
227
|
+
}
|
228
|
+
|
229
|
+
template<class T, class U, typename std::enable_if<
|
230
|
+
std::is_same<T, uint48_t>::value>::type* = nullptr>
|
231
|
+
void
|
232
|
+
write(ostream& os, U u)
|
233
|
+
{
|
234
|
+
BOOST_ASSERT(u <= field<T>::max);
|
235
|
+
auto const t = static_cast<std::uint64_t>(u);
|
236
|
+
std::uint8_t* p = os.data(field<T>::size);
|
237
|
+
*p++ = (t>>40)&0xff;
|
238
|
+
*p++ = (t>>32)&0xff;
|
239
|
+
*p++ = (t>>24)&0xff;
|
240
|
+
*p++ = (t>>16)&0xff;
|
241
|
+
*p++ = (t>> 8)&0xff;
|
242
|
+
*p = t &0xff;
|
243
|
+
}
|
244
|
+
|
245
|
+
template<class T, class U, typename std::enable_if<
|
246
|
+
std::is_same<T, std::uint64_t>::value>::type* = nullptr>
|
247
|
+
void
|
248
|
+
write(ostream& os, U u)
|
249
|
+
{
|
250
|
+
auto const t = static_cast<T>(u);
|
251
|
+
std::uint8_t* p = os.data(field<T>::size);
|
252
|
+
*p++ = (t>>56)&0xff;
|
253
|
+
*p++ = (t>>48)&0xff;
|
254
|
+
*p++ = (t>>40)&0xff;
|
255
|
+
*p++ = (t>>32)&0xff;
|
256
|
+
*p++ = (t>>24)&0xff;
|
257
|
+
*p++ = (t>>16)&0xff;
|
258
|
+
*p++ = (t>> 8)&0xff;
|
259
|
+
*p = t &0xff;
|
260
|
+
}
|
261
|
+
|
262
|
+
} // detail
|
263
|
+
} // nudb
|
264
|
+
|
265
|
+
#endif
|