rrudb 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (61) hide show
  1. checksums.yaml +7 -0
  2. data/.yardopts +1 -0
  3. data/LICENSE.txt +22 -0
  4. data/README.md +26 -0
  5. data/examples/example.rb +39 -0
  6. data/ext/rudb/NuDB/include/nudb/CMakeLists.txt +104 -0
  7. data/ext/rudb/NuDB/include/nudb/_experimental/basic_seconds_clock.hpp +200 -0
  8. data/ext/rudb/NuDB/include/nudb/_experimental/chrono_util.hpp +58 -0
  9. data/ext/rudb/NuDB/include/nudb/_experimental/test/fail_file.hpp +343 -0
  10. data/ext/rudb/NuDB/include/nudb/_experimental/test/temp_dir.hpp +73 -0
  11. data/ext/rudb/NuDB/include/nudb/_experimental/test/test_store.hpp +451 -0
  12. data/ext/rudb/NuDB/include/nudb/_experimental/test/xor_shift_engine.hpp +105 -0
  13. data/ext/rudb/NuDB/include/nudb/_experimental/util.hpp +288 -0
  14. data/ext/rudb/NuDB/include/nudb/basic_store.hpp +461 -0
  15. data/ext/rudb/NuDB/include/nudb/concepts.hpp +205 -0
  16. data/ext/rudb/NuDB/include/nudb/context.hpp +144 -0
  17. data/ext/rudb/NuDB/include/nudb/create.hpp +117 -0
  18. data/ext/rudb/NuDB/include/nudb/detail/arena.hpp +296 -0
  19. data/ext/rudb/NuDB/include/nudb/detail/bucket.hpp +473 -0
  20. data/ext/rudb/NuDB/include/nudb/detail/buffer.hpp +86 -0
  21. data/ext/rudb/NuDB/include/nudb/detail/bulkio.hpp +196 -0
  22. data/ext/rudb/NuDB/include/nudb/detail/cache.hpp +236 -0
  23. data/ext/rudb/NuDB/include/nudb/detail/endian.hpp +93 -0
  24. data/ext/rudb/NuDB/include/nudb/detail/field.hpp +265 -0
  25. data/ext/rudb/NuDB/include/nudb/detail/format.hpp +630 -0
  26. data/ext/rudb/NuDB/include/nudb/detail/gentex.hpp +259 -0
  27. data/ext/rudb/NuDB/include/nudb/detail/mutex.hpp +26 -0
  28. data/ext/rudb/NuDB/include/nudb/detail/pool.hpp +243 -0
  29. data/ext/rudb/NuDB/include/nudb/detail/store_base.hpp +45 -0
  30. data/ext/rudb/NuDB/include/nudb/detail/stream.hpp +149 -0
  31. data/ext/rudb/NuDB/include/nudb/detail/xxhash.hpp +328 -0
  32. data/ext/rudb/NuDB/include/nudb/error.hpp +257 -0
  33. data/ext/rudb/NuDB/include/nudb/file.hpp +55 -0
  34. data/ext/rudb/NuDB/include/nudb/impl/basic_store.ipp +785 -0
  35. data/ext/rudb/NuDB/include/nudb/impl/context.ipp +241 -0
  36. data/ext/rudb/NuDB/include/nudb/impl/create.ipp +163 -0
  37. data/ext/rudb/NuDB/include/nudb/impl/error.ipp +175 -0
  38. data/ext/rudb/NuDB/include/nudb/impl/posix_file.ipp +248 -0
  39. data/ext/rudb/NuDB/include/nudb/impl/recover.ipp +209 -0
  40. data/ext/rudb/NuDB/include/nudb/impl/rekey.ipp +248 -0
  41. data/ext/rudb/NuDB/include/nudb/impl/verify.ipp +634 -0
  42. data/ext/rudb/NuDB/include/nudb/impl/visit.ipp +96 -0
  43. data/ext/rudb/NuDB/include/nudb/impl/win32_file.ipp +264 -0
  44. data/ext/rudb/NuDB/include/nudb/native_file.hpp +76 -0
  45. data/ext/rudb/NuDB/include/nudb/nudb.hpp +27 -0
  46. data/ext/rudb/NuDB/include/nudb/posix_file.hpp +228 -0
  47. data/ext/rudb/NuDB/include/nudb/progress.hpp +32 -0
  48. data/ext/rudb/NuDB/include/nudb/recover.hpp +73 -0
  49. data/ext/rudb/NuDB/include/nudb/rekey.hpp +110 -0
  50. data/ext/rudb/NuDB/include/nudb/store.hpp +27 -0
  51. data/ext/rudb/NuDB/include/nudb/type_traits.hpp +63 -0
  52. data/ext/rudb/NuDB/include/nudb/verify.hpp +200 -0
  53. data/ext/rudb/NuDB/include/nudb/version.hpp +21 -0
  54. data/ext/rudb/NuDB/include/nudb/visit.hpp +63 -0
  55. data/ext/rudb/NuDB/include/nudb/win32_file.hpp +246 -0
  56. data/ext/rudb/NuDB/include/nudb/xxhasher.hpp +45 -0
  57. data/ext/rudb/extconf.rb +12 -0
  58. data/ext/rudb/rudb.cpp +234 -0
  59. data/lib/rudb/version.rb +3 -0
  60. data/lib/rudb.rb +1 -0
  61. metadata +104 -0
@@ -0,0 +1,328 @@
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
+ // This is a derivative work based on xxHash 0.6.2, copyright below:
9
+ /*
10
+ xxHash - Extremely Fast Hash algorithm
11
+ Header File
12
+ Copyright (C) 2012-2016, Yann Collet.
13
+
14
+ BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
15
+
16
+ Redistribution and use in source and binary forms, with or without
17
+ modification, are permitted provided that the following conditions are
18
+ met:
19
+
20
+ * Redistributions of source code must retain the above copyright
21
+ notice, this list of conditions and the following disclaimer.
22
+ * Redistributions in binary form must reproduce the above
23
+ copyright notice, this list of conditions and the following disclaimer
24
+ in the documentation and/or other materials provided with the
25
+ distribution.
26
+
27
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
28
+ "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
29
+ LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
30
+ A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
31
+ OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
32
+ SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
33
+ LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
34
+ DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
35
+ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
36
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
37
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38
+
39
+ You can contact the author at :
40
+ - xxHash source repository : https://github.com/Cyan4973/xxHash
41
+ */
42
+
43
+ #ifndef NUDB_DETAIL_XXHASH_HPP
44
+ #define NUDB_DETAIL_XXHASH_HPP
45
+
46
+ #include <nudb/detail/endian.hpp>
47
+ #include <cstdint>
48
+ #include <cstdlib>
49
+ #include <cstring>
50
+
51
+ namespace nudb {
52
+ namespace detail {
53
+
54
+ #define NUDB_GCC_VERSION (__GNUC__ * 100 + __GNUC_MINOR__)
55
+
56
+ // minGW _rotl gives poor performance
57
+ #if defined(_MSC_VER)
58
+ # define NUDB_XXH_rotl64(x,r) _rotl64(x,r)
59
+ #else
60
+ # define NUDB_XXH_rotl64(x,r) ((x << r) | (x >> (64 - r)))
61
+ #endif
62
+
63
+ #if defined(_MSC_VER)
64
+ # define NUDB_XXH_swap32 _byteswap_ulong
65
+ #elif NUDB_GCC_VERSION >= 403
66
+ # define NUDB_XXH_swap32 __builtin_bswap32
67
+ #endif
68
+
69
+ #if defined(_MSC_VER)
70
+ # define NUDB_XXH_swap64 _byteswap_uint64
71
+ #elif NUDB_GCC_VERSION >= 403
72
+ # define NUDB_XXH_swap64 __builtin_bswap64
73
+ #endif
74
+
75
+ #ifndef NUDB_XXH_swap32
76
+ inline
77
+ std::uint32_t
78
+ NUDB_XXH_swap32(std::uint32_t x)
79
+ {
80
+ return ((x << 24) & 0xff000000 ) |
81
+ ((x << 8) & 0x00ff0000 ) |
82
+ ((x >> 8) & 0x0000ff00 ) |
83
+ ((x >> 24) & 0x000000ff );
84
+ }
85
+ #endif
86
+
87
+ #ifndef NUDB_XXH_swap64
88
+ inline
89
+ std::uint64_t
90
+ NUDB_XXH_swap64(std::uint64_t x)
91
+ {
92
+ return ((x << 56) & 0xff00000000000000ULL) |
93
+ ((x << 40) & 0x00ff000000000000ULL) |
94
+ ((x << 24) & 0x0000ff0000000000ULL) |
95
+ ((x << 8) & 0x000000ff00000000ULL) |
96
+ ((x >> 8) & 0x00000000ff000000ULL) |
97
+ ((x >> 24) & 0x0000000000ff0000ULL) |
98
+ ((x >> 40) & 0x000000000000ff00ULL) |
99
+ ((x >> 56) & 0x00000000000000ffULL);
100
+ }
101
+ #endif
102
+
103
+ static std::uint64_t constexpr prime64_1 = 11400714785074694791ULL;
104
+ static std::uint64_t constexpr prime64_2 = 14029467366897019727ULL;
105
+ static std::uint64_t constexpr prime64_3 = 1609587929392839161ULL;
106
+ static std::uint64_t constexpr prime64_4 = 9650029242287828579ULL;
107
+ static std::uint64_t constexpr prime64_5 = 2870177450012600261ULL;
108
+
109
+ // Portable and safe solution. Generally efficient.
110
+ // see : http://stackoverflow.com/a/32095106/646947
111
+
112
+ inline
113
+ std::uint32_t
114
+ XXH_read32(void const* p)
115
+ {
116
+ std::uint32_t v;
117
+ memcpy(&v, p, sizeof(v));
118
+ return v;
119
+ }
120
+
121
+ inline
122
+ std::uint64_t
123
+ XXH_read64(void const* p)
124
+ {
125
+ std::uint64_t v;
126
+ memcpy(&v, p, sizeof(v));
127
+ return v;
128
+ }
129
+
130
+ // little endian, aligned
131
+ inline
132
+ std::uint32_t
133
+ XXH_readLE32_align(void const* p, std::true_type, std::true_type)
134
+ {
135
+ return *reinterpret_cast<std::uint32_t const*>(p);
136
+ }
137
+
138
+ // little endian, unaligned
139
+ inline
140
+ std::uint32_t
141
+ XXH_readLE32_align(void const* p, std::true_type, std::false_type)
142
+ {
143
+ return XXH_read32(p);
144
+ }
145
+
146
+ // big endian, aligned
147
+ inline
148
+ std::uint32_t
149
+ XXH_readLE32_align(void const* p, std::false_type, std::true_type)
150
+ {
151
+ return NUDB_XXH_swap32(
152
+ *reinterpret_cast<std::uint32_t const*>(p));
153
+ }
154
+
155
+ // big endian, unaligned
156
+ inline
157
+ std::uint32_t
158
+ XXH_readLE32_align(void const* p, std::false_type, std::false_type)
159
+ {
160
+ return NUDB_XXH_swap32(XXH_read32(p));
161
+ }
162
+
163
+ // little endian, aligned
164
+ inline
165
+ std::uint64_t
166
+ XXH_readLE64_align(void const* p, std::true_type, std::true_type)
167
+ {
168
+ return *reinterpret_cast<std::uint64_t const*>(p);
169
+ }
170
+
171
+ // little endian, unaligned
172
+ inline
173
+ std::uint64_t
174
+ XXH_readLE64_align(void const* p, std::true_type, std::false_type)
175
+ {
176
+ return XXH_read64(p);
177
+ }
178
+
179
+ // big endian, aligned
180
+ inline
181
+ std::uint64_t
182
+ XXH_readLE64_align(void const* p, std::false_type, std::true_type)
183
+ {
184
+ return NUDB_XXH_swap64(
185
+ *reinterpret_cast<std::uint64_t const*>(p));
186
+ }
187
+
188
+ // big endian, unaligned
189
+ inline
190
+ std::uint64_t
191
+ XXH_readLE64_align(void const* p, std::false_type, std::false_type)
192
+ {
193
+ return NUDB_XXH_swap64(XXH_read64(p));
194
+ }
195
+
196
+ inline
197
+ std::uint64_t
198
+ XXH64_round(std::uint64_t acc, std::uint64_t input)
199
+ {
200
+ acc += input * prime64_2;
201
+ acc = NUDB_XXH_rotl64(acc, 31);
202
+ acc *= prime64_1;
203
+ return acc;
204
+ }
205
+
206
+ inline
207
+ std::uint64_t
208
+ XXH64_mergeRound(std::uint64_t acc, std::uint64_t val)
209
+ {
210
+ val = XXH64_round(0, val);
211
+ acc ^= val;
212
+ acc = acc * prime64_1 + prime64_4;
213
+ return acc;
214
+ }
215
+
216
+ template<bool LittleEndian, bool Aligned>
217
+ std::uint64_t
218
+ XXH64_endian_align(
219
+ void const* input, std::size_t len, std::uint64_t seed,
220
+ std::integral_constant<bool, LittleEndian> endian,
221
+ std::integral_constant<bool, Aligned> align)
222
+ {
223
+ const std::uint8_t* p = (const std::uint8_t*)input;
224
+ const std::uint8_t* const bEnd = p + len;
225
+ std::uint64_t h64;
226
+ auto const XXH_get32bits =
227
+ [](void const* p)
228
+ {
229
+ return XXH_readLE32_align(p,
230
+ decltype(endian){}, decltype(align){});
231
+ };
232
+ auto const XXH_get64bits =
233
+ [](void const* p)
234
+ {
235
+ return XXH_readLE64_align(p,
236
+ decltype(endian){}, decltype(align){});
237
+ };
238
+ if(len>=32)
239
+ {
240
+ const std::uint8_t* const limit = bEnd - 32;
241
+ std::uint64_t v1 = seed + prime64_1 + prime64_2;
242
+ std::uint64_t v2 = seed + prime64_2;
243
+ std::uint64_t v3 = seed + 0;
244
+ std::uint64_t v4 = seed - prime64_1;
245
+
246
+ do
247
+ {
248
+ v1 = XXH64_round(v1, XXH_get64bits(p)); p+=8;
249
+ v2 = XXH64_round(v2, XXH_get64bits(p)); p+=8;
250
+ v3 = XXH64_round(v3, XXH_get64bits(p)); p+=8;
251
+ v4 = XXH64_round(v4, XXH_get64bits(p)); p+=8;
252
+ }
253
+ while(p<=limit);
254
+
255
+ h64 = NUDB_XXH_rotl64(v1, 1) +
256
+ NUDB_XXH_rotl64(v2, 7) +
257
+ NUDB_XXH_rotl64(v3, 12) +
258
+ NUDB_XXH_rotl64(v4, 18);
259
+ h64 = XXH64_mergeRound(h64, v1);
260
+ h64 = XXH64_mergeRound(h64, v2);
261
+ h64 = XXH64_mergeRound(h64, v3);
262
+ h64 = XXH64_mergeRound(h64, v4);
263
+ }
264
+ else
265
+ {
266
+ h64 = seed + prime64_5;
267
+ }
268
+ h64 += len;
269
+ while(p + 8 <= bEnd)
270
+ {
271
+ std::uint64_t const k1 = XXH64_round(0, XXH_get64bits(p));
272
+ h64 ^= k1;
273
+ h64 = NUDB_XXH_rotl64(h64,27) * prime64_1 + prime64_4;
274
+ p+=8;
275
+ }
276
+ if(p+4<=bEnd)
277
+ {
278
+ h64 ^= (std::uint64_t)(XXH_get32bits(p)) * prime64_1;
279
+ h64 = NUDB_XXH_rotl64(h64, 23) * prime64_2 + prime64_3;
280
+ p+=4;
281
+ }
282
+ while(p<bEnd)
283
+ {
284
+ h64 ^= (*p) * prime64_5;
285
+ h64 = NUDB_XXH_rotl64(h64, 11) * prime64_1;
286
+ p++;
287
+ }
288
+ h64 ^= h64 >> 33;
289
+ h64 *= prime64_2;
290
+ h64 ^= h64 >> 29;
291
+ h64 *= prime64_3;
292
+ h64 ^= h64 >> 32;
293
+ return h64;
294
+ }
295
+
296
+ /* Calculate the 64-bit hash of a block of memory.
297
+
298
+ @param data A pointer to the buffer to compute the hash on.
299
+ The buffer may be unaligned.
300
+
301
+ @note This function runs faster on 64-bits systems, but slower
302
+ on 32-bits systems (see benchmark).
303
+
304
+ @param bytes The size of the buffer in bytes.
305
+
306
+ @param seed A value which may be used to permute the output.
307
+ Using a different seed with the same input will produce a
308
+ different value.
309
+
310
+ @return The 64-bit hash of the input data.
311
+ */
312
+ template<class = void>
313
+ std::uint64_t
314
+ XXH64(void const* data, size_t bytes, std::uint64_t seed)
315
+ {
316
+ // Use faster algorithm if aligned
317
+ if((reinterpret_cast<std::uintptr_t>(data) & 7) == 0)
318
+ return XXH64_endian_align(data, bytes, seed,
319
+ is_little_endian{}, std::false_type{});
320
+ return XXH64_endian_align(data, bytes, seed,
321
+ is_little_endian{}, std::true_type{});
322
+ }
323
+
324
+ } // detail
325
+ } // nudb
326
+
327
+ #endif
328
+
@@ -0,0 +1,257 @@
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_ERROR_HPP
9
+ #define NUDB_ERROR_HPP
10
+
11
+ #include <boost/system/system_error.hpp>
12
+ #include <boost/system/error_code.hpp>
13
+
14
+ namespace nudb {
15
+
16
+ /// The type of system-specific error code returned by the implementation
17
+ #if GENERATING_DOCS
18
+ class error_code{};
19
+
20
+ #else
21
+ using boost::system::error_code;
22
+
23
+ #endif
24
+
25
+ /// The type of cross-platform error code used by the implementation
26
+ #if GENERATING_DOCS
27
+ class error_condition{};
28
+
29
+ #else
30
+ using boost::system::error_condition;
31
+
32
+ #endif
33
+
34
+ /// The type of system-specific exception used when throwing
35
+ #if GENERATING_DOCS
36
+ class system_error{};
37
+
38
+ #else
39
+ using boost::system::system_error;
40
+
41
+ #endif
42
+
43
+ /// Returns the category used for system-specific error codes
44
+ #if GENERATING_DOCS
45
+ error_category const&
46
+ system_category();
47
+
48
+ #else
49
+ using boost::system::system_category;
50
+
51
+ #endif
52
+
53
+ /// Returns the category used for cross-platform error codes
54
+ #if GENERATING_DOCS
55
+ error_category const&
56
+ generic_category();
57
+
58
+ #else
59
+ using boost::system::generic_category;
60
+
61
+ #endif
62
+
63
+ /// The base class used for error categories
64
+ #if GENERATING_DOCS
65
+ class error_category{};
66
+
67
+ #else
68
+ using boost::system::error_category;
69
+
70
+ #endif
71
+
72
+ /// The set of constants used for cross-platform error codes
73
+ #if GENERATING_DOCS
74
+ enum errc{};
75
+
76
+ #else
77
+ namespace errc = boost::system::errc;
78
+
79
+ #endif
80
+
81
+ /// Database error codes.
82
+ enum class error
83
+ {
84
+ /** The specified key was not found.
85
+
86
+ Returned when @ref basic_store::fetch does not
87
+ find the specified key.
88
+ */
89
+ key_not_found,
90
+
91
+ /** The specified key already exists.
92
+
93
+ Returned when @ref basic_store::insert finds
94
+ the specified key already in the database.
95
+ */
96
+ key_exists,
97
+
98
+ /** A file read returned less data than expected.
99
+
100
+ This can be caused by premature application
101
+ termination during a commit cycle.
102
+ */
103
+ short_read,
104
+
105
+ /** A log file is present.
106
+
107
+ Indicates that the database needs to have the
108
+ associated log file applied to perform a recovery.
109
+ This error is returned by functions such as @ref rekey.
110
+ */
111
+ log_file_exists,
112
+
113
+ /** No key file exists.
114
+
115
+ This error is returned by the recover process when
116
+ there is no valid key file. It happens when a
117
+ @ref rekey operation prematurely terminates. A
118
+ database without a key file cannot be opened. To
119
+ fix this error, it is necessary for an invocation of
120
+ @ref rekey to complete successfully.
121
+ */
122
+ no_key_file,
123
+
124
+ /// Too many buckets in key file
125
+ too_many_buckets,
126
+
127
+ /// Not a data file
128
+ not_data_file,
129
+
130
+ /// Not a key file
131
+ not_key_file,
132
+
133
+ /// Not a log file
134
+ not_log_file,
135
+
136
+ /// Different version
137
+ different_version,
138
+
139
+ /// Invalid key size
140
+ invalid_key_size,
141
+
142
+ /// Invalid block size
143
+ invalid_block_size,
144
+
145
+ /// Short key file
146
+ short_key_file,
147
+
148
+ /// Short bucket
149
+ short_bucket,
150
+
151
+ /// Short spill
152
+ short_spill,
153
+
154
+ /// Short record
155
+ short_data_record,
156
+
157
+ /// Short value
158
+ short_value,
159
+
160
+ /// Hash mismatch
161
+ hash_mismatch,
162
+
163
+ /// Invalid load factor
164
+ invalid_load_factor,
165
+
166
+ /// Invalid capacity
167
+ invalid_capacity,
168
+
169
+ /// Invalid bucket count
170
+ invalid_bucket_count,
171
+
172
+ /// Invalid bucket size
173
+ invalid_bucket_size,
174
+
175
+ /// The data file header was incomplete
176
+ incomplete_data_file_header,
177
+
178
+ /// The key file header was incomplete
179
+ incomplete_key_file_header,
180
+
181
+ /// Invalid log record
182
+ invalid_log_record,
183
+
184
+ /// Invalid spill in log record
185
+ invalid_log_spill,
186
+
187
+ /// Invalid offset in log record
188
+ invalid_log_offset,
189
+
190
+ /// Invalid index in log record
191
+ invalid_log_index,
192
+
193
+ /// Invalid size in spill
194
+ invalid_spill_size,
195
+
196
+ /// UID mismatch
197
+ uid_mismatch,
198
+
199
+ /// appnum mismatch
200
+ appnum_mismatch,
201
+
202
+ /// key size mismatch
203
+ key_size_mismatch,
204
+
205
+ /// salt mismatch
206
+ salt_mismatch,
207
+
208
+ /// pepper mismatch
209
+ pepper_mismatch,
210
+
211
+ /// block size mismatch
212
+ block_size_mismatch,
213
+
214
+ /// orphaned value
215
+ orphaned_value,
216
+
217
+ /// missing value
218
+ missing_value,
219
+
220
+ /// size mismatch
221
+ size_mismatch,
222
+
223
+ /// duplicate value
224
+ duplicate_value
225
+ };
226
+
227
+ /// Returns the error category used for database error codes.
228
+ error_category const&
229
+ nudb_category();
230
+
231
+ /** Returns a database error code.
232
+
233
+ This function is used by the implementation to convert
234
+ @ref error values into @ref error_code objects.
235
+ */
236
+ inline
237
+ error_code
238
+ make_error_code(error ev)
239
+ {
240
+ return error_code{static_cast<int>(ev), nudb_category()};
241
+ }
242
+
243
+ } // nudb
244
+
245
+ namespace boost {
246
+ namespace system {
247
+ template<>
248
+ struct is_error_code_enum<nudb::error>
249
+ {
250
+ static bool const value = true;
251
+ };
252
+ } // system
253
+ } // boost
254
+
255
+ #include <nudb/impl/error.ipp>
256
+
257
+ #endif
@@ -0,0 +1,55 @@
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_FILE_HPP
9
+ #define NUDB_FILE_HPP
10
+
11
+ #include <boost/core/ignore_unused.hpp>
12
+ #include <cstddef>
13
+ #include <string>
14
+
15
+ namespace nudb {
16
+
17
+ /// The type used to hold paths to files
18
+ using path_type = std::string;
19
+
20
+ /** Returns the best guess at the volume's block size.
21
+
22
+ @param path A path to a file on the device. The file does
23
+ not need to exist.
24
+ */
25
+ inline
26
+ std::size_t
27
+ block_size(path_type const& path)
28
+ {
29
+ boost::ignore_unused(path);
30
+ // A reasonable default for many SSD devices
31
+ return 4096;
32
+ }
33
+
34
+ /** File create and open modes.
35
+
36
+ These are used by @ref native_file.
37
+ */
38
+ enum class file_mode
39
+ {
40
+ /// Open the file for sequential reads
41
+ scan,
42
+
43
+ /// Open the file for random reads
44
+ read,
45
+
46
+ /// Open the file for random reads and appending writes
47
+ append,
48
+
49
+ /// Open the file for random reads and writes
50
+ write
51
+ };
52
+
53
+ } // nudb
54
+
55
+ #endif