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,246 @@
|
|
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_DETAIL_WIN32_FILE_HPP
|
9
|
+
#define NUDB_DETAIL_WIN32_FILE_HPP
|
10
|
+
|
11
|
+
#include <nudb/file.hpp>
|
12
|
+
#include <nudb/error.hpp>
|
13
|
+
#include <cstddef>
|
14
|
+
#include <cstdint>
|
15
|
+
#include <string>
|
16
|
+
|
17
|
+
#ifndef NUDB_WIN32_FILE
|
18
|
+
# ifdef _MSC_VER
|
19
|
+
# define NUDB_WIN32_FILE 1
|
20
|
+
# else
|
21
|
+
# define NUDB_WIN32_FILE 0
|
22
|
+
# endif
|
23
|
+
#endif
|
24
|
+
|
25
|
+
#if NUDB_WIN32_FILE
|
26
|
+
#pragma push_macro("NOMINMAX")
|
27
|
+
#pragma push_macro("UNICODE")
|
28
|
+
#pragma push_macro("STRICT")
|
29
|
+
# ifndef NOMINMAX
|
30
|
+
# define NOMINMAX
|
31
|
+
# endif
|
32
|
+
# ifndef UNICODE
|
33
|
+
# define UNICODE
|
34
|
+
# endif
|
35
|
+
# ifndef STRICT
|
36
|
+
# define STRICT
|
37
|
+
# endif
|
38
|
+
# ifndef WIN32_LEAN_AND_MEAN
|
39
|
+
# define WIN32_LEAN_AND_MEAN
|
40
|
+
# endif
|
41
|
+
# include <Windows.h>
|
42
|
+
#pragma pop_macro("STRICT")
|
43
|
+
#pragma pop_macro("UNICODE")
|
44
|
+
#pragma pop_macro("NOMINMAX")
|
45
|
+
#endif
|
46
|
+
|
47
|
+
#if NUDB_WIN32_FILE
|
48
|
+
|
49
|
+
namespace nudb {
|
50
|
+
|
51
|
+
/** A descriptor to a Win32 file.
|
52
|
+
|
53
|
+
This class provides a Win32 implementation of the @b File
|
54
|
+
concept.
|
55
|
+
*/
|
56
|
+
class win32_file
|
57
|
+
{
|
58
|
+
HANDLE hf_ = INVALID_HANDLE_VALUE;
|
59
|
+
|
60
|
+
public:
|
61
|
+
/// Constructor
|
62
|
+
win32_file() = default;
|
63
|
+
|
64
|
+
/// Copy constructor (disallowed)
|
65
|
+
win32_file(win32_file const&) = delete;
|
66
|
+
|
67
|
+
// Copy assignment (disallowed)
|
68
|
+
win32_file& operator=(win32_file const&) = delete;
|
69
|
+
|
70
|
+
/** Destructor.
|
71
|
+
|
72
|
+
If open, the file is closed.
|
73
|
+
*/
|
74
|
+
~win32_file();
|
75
|
+
|
76
|
+
/** Move constructor.
|
77
|
+
|
78
|
+
@note The state of the moved-from object is as if default constructed.
|
79
|
+
*/
|
80
|
+
win32_file(win32_file&&);
|
81
|
+
|
82
|
+
/** Move assignment.
|
83
|
+
|
84
|
+
@note The state of the moved-from object is as if default constructed.
|
85
|
+
*/
|
86
|
+
win32_file&
|
87
|
+
operator=(win32_file&& other);
|
88
|
+
|
89
|
+
/// Returns `true` if the file is open.
|
90
|
+
bool
|
91
|
+
is_open() const
|
92
|
+
{
|
93
|
+
return hf_ != INVALID_HANDLE_VALUE;
|
94
|
+
}
|
95
|
+
|
96
|
+
/// Close the file if it is open.
|
97
|
+
void
|
98
|
+
close();
|
99
|
+
|
100
|
+
/** Create a new file.
|
101
|
+
|
102
|
+
After the file is created, it is opened as if by `open(mode, path, ec)`.
|
103
|
+
|
104
|
+
@par Requirements
|
105
|
+
|
106
|
+
The file must not already exist, or else `errc::file_exists`
|
107
|
+
is returned.
|
108
|
+
|
109
|
+
@param mode The open mode, which must be a valid @ref file_mode.
|
110
|
+
|
111
|
+
@param path The path of the file to create.
|
112
|
+
|
113
|
+
@param ec Set to the error, if any occurred.
|
114
|
+
*/
|
115
|
+
void
|
116
|
+
create(file_mode mode, path_type const& path, error_code& ec);
|
117
|
+
|
118
|
+
/** Open a file.
|
119
|
+
|
120
|
+
@par Requirements
|
121
|
+
|
122
|
+
The file must not already be open.
|
123
|
+
|
124
|
+
@param mode The open mode, which must be a valid @ref file_mode.
|
125
|
+
|
126
|
+
@param path The path of the file to open.
|
127
|
+
|
128
|
+
@param ec Set to the error, if any occurred.
|
129
|
+
*/
|
130
|
+
void
|
131
|
+
open(file_mode mode, path_type const& path, error_code& ec);
|
132
|
+
|
133
|
+
/** Remove a file from the file system.
|
134
|
+
|
135
|
+
It is not an error to attempt to erase a file that does not exist.
|
136
|
+
|
137
|
+
@param path The path of the file to remove.
|
138
|
+
|
139
|
+
@param ec Set to the error, if any occurred.
|
140
|
+
*/
|
141
|
+
static
|
142
|
+
void
|
143
|
+
erase(path_type const& path, error_code& ec);
|
144
|
+
|
145
|
+
/** Return the size of the file.
|
146
|
+
|
147
|
+
@par Requirements
|
148
|
+
|
149
|
+
The file must be open.
|
150
|
+
|
151
|
+
@param ec Set to the error, if any occurred.
|
152
|
+
|
153
|
+
@return The size of the file, in bytes.
|
154
|
+
*/
|
155
|
+
std::uint64_t
|
156
|
+
size(error_code& ec) const;
|
157
|
+
|
158
|
+
/** Read data from a location in the file.
|
159
|
+
|
160
|
+
@par Requirements
|
161
|
+
|
162
|
+
The file must be open.
|
163
|
+
|
164
|
+
@param offset The position in the file to read from,
|
165
|
+
expressed as a byte offset from the beginning.
|
166
|
+
|
167
|
+
@param buffer The location to store the data.
|
168
|
+
|
169
|
+
@param bytes The number of bytes to read.
|
170
|
+
|
171
|
+
@param ec Set to the error, if any occurred.
|
172
|
+
*/
|
173
|
+
void
|
174
|
+
read(std::uint64_t offset,
|
175
|
+
void* buffer, std::size_t bytes, error_code& ec);
|
176
|
+
|
177
|
+
/** Write data to a location in the file.
|
178
|
+
|
179
|
+
@par Requirements
|
180
|
+
|
181
|
+
The file must be open with a mode allowing writes.
|
182
|
+
|
183
|
+
@param offset The position in the file to write from,
|
184
|
+
expressed as a byte offset from the beginning.
|
185
|
+
|
186
|
+
@param buffer The data the write.
|
187
|
+
|
188
|
+
@param bytes The number of bytes to write.
|
189
|
+
|
190
|
+
@param ec Set to the error, if any occurred.
|
191
|
+
*/
|
192
|
+
void
|
193
|
+
write(std::uint64_t offset,
|
194
|
+
void const* buffer, std::size_t bytes, error_code& ec);
|
195
|
+
|
196
|
+
/** Perform a low level file synchronization.
|
197
|
+
|
198
|
+
@par Requirements
|
199
|
+
|
200
|
+
The file must be open with a mode allowing writes.
|
201
|
+
|
202
|
+
@param ec Set to the error, if any occurred.
|
203
|
+
*/
|
204
|
+
void
|
205
|
+
sync(error_code& ec);
|
206
|
+
|
207
|
+
/** Truncate the file at a specific size.
|
208
|
+
|
209
|
+
@par Requirements
|
210
|
+
|
211
|
+
The file must be open with a mode allowing writes.
|
212
|
+
|
213
|
+
@param length The new file size.
|
214
|
+
|
215
|
+
@param ec Set to the error, if any occurred.
|
216
|
+
*/
|
217
|
+
void
|
218
|
+
trunc(std::uint64_t length, error_code& ec);
|
219
|
+
|
220
|
+
private:
|
221
|
+
static
|
222
|
+
void
|
223
|
+
err(DWORD dwError, error_code& ec)
|
224
|
+
{
|
225
|
+
ec = error_code{static_cast<int>(dwError), system_category()};
|
226
|
+
}
|
227
|
+
|
228
|
+
static
|
229
|
+
void
|
230
|
+
last_err(error_code& ec)
|
231
|
+
{
|
232
|
+
err(::GetLastError(), ec);
|
233
|
+
}
|
234
|
+
|
235
|
+
static
|
236
|
+
std::pair<DWORD, DWORD>
|
237
|
+
flags(file_mode mode);
|
238
|
+
};
|
239
|
+
|
240
|
+
} // nudb
|
241
|
+
|
242
|
+
#include <nudb/impl/win32_file.ipp>
|
243
|
+
|
244
|
+
#endif
|
245
|
+
|
246
|
+
#endif
|
@@ -0,0 +1,45 @@
|
|
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_XXHASHER_HPP
|
9
|
+
#define NUDB_XXHASHER_HPP
|
10
|
+
|
11
|
+
#include <nudb/detail/xxhash.hpp>
|
12
|
+
#include <cstddef>
|
13
|
+
#include <cstdint>
|
14
|
+
#include <type_traits>
|
15
|
+
|
16
|
+
namespace nudb {
|
17
|
+
|
18
|
+
/** A Hasher that uses xxHash.
|
19
|
+
|
20
|
+
This object meets the requirements of @b Hasher. It is
|
21
|
+
the default hash function unless otherwise specified.
|
22
|
+
*/
|
23
|
+
class xxhasher
|
24
|
+
{
|
25
|
+
std::uint64_t seed_;
|
26
|
+
|
27
|
+
public:
|
28
|
+
using result_type = std::uint64_t;
|
29
|
+
|
30
|
+
explicit
|
31
|
+
xxhasher(std::uint64_t seed)
|
32
|
+
: seed_(seed)
|
33
|
+
{
|
34
|
+
}
|
35
|
+
|
36
|
+
result_type
|
37
|
+
operator()(void const* data, std::size_t bytes) const noexcept
|
38
|
+
{
|
39
|
+
return detail::XXH64(data, bytes, seed_);
|
40
|
+
}
|
41
|
+
};
|
42
|
+
|
43
|
+
} // nudb
|
44
|
+
|
45
|
+
#endif
|
data/ext/rudb/extconf.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
require "mkmf"
|
2
|
+
|
3
|
+
RbConfig::CONFIG["CPP"] = "g++ -E -std=gnu++11"
|
4
|
+
$INCFLAGS << " -I./NuDB/include"
|
5
|
+
|
6
|
+
have_library("boost_thread")
|
7
|
+
have_library("boost_system")
|
8
|
+
|
9
|
+
abort "Can't find header or library of NuDB" unless have_header('nudb/nudb.hpp')
|
10
|
+
|
11
|
+
create_header
|
12
|
+
create_makefile("rudb")
|
data/ext/rudb/rudb.cpp
ADDED
@@ -0,0 +1,234 @@
|
|
1
|
+
#include RUBY_EXTCONF_H
|
2
|
+
|
3
|
+
#include <ruby.h>
|
4
|
+
#include <nudb/nudb.hpp>
|
5
|
+
|
6
|
+
static VALUE mRuDB;
|
7
|
+
static VALUE cRuDB_store;
|
8
|
+
static VALUE cRuDB_ec;
|
9
|
+
|
10
|
+
struct nudb_store_pointer {
|
11
|
+
nudb::store* store;
|
12
|
+
};
|
13
|
+
|
14
|
+
///
|
15
|
+
|
16
|
+
// TODO pull in error_category (requires ref mark?)
|
17
|
+
|
18
|
+
void ec_free(nudb::error_code* ec_pointer){
|
19
|
+
delete ec_pointer;
|
20
|
+
}
|
21
|
+
|
22
|
+
VALUE ec2obj(nudb::error_code* ec){
|
23
|
+
return Data_Wrap_Struct(cRuDB_ec, 0, ec_free, ec);
|
24
|
+
}
|
25
|
+
|
26
|
+
VALUE rudb_ec_value(VALUE _self){
|
27
|
+
nudb::error_code* ec_pointer;
|
28
|
+
Data_Get_Struct(_self, nudb::error_code , ec_pointer);
|
29
|
+
return INT2NUM(ec_pointer->value());
|
30
|
+
}
|
31
|
+
|
32
|
+
VALUE rudb_ec_message(VALUE _self){
|
33
|
+
nudb::error_code* ec_pointer;
|
34
|
+
Data_Get_Struct(_self, nudb::error_code , ec_pointer);
|
35
|
+
return rb_str_new_cstr(ec_pointer->message().c_str());
|
36
|
+
}
|
37
|
+
|
38
|
+
///
|
39
|
+
|
40
|
+
VALUE rudb_create(VALUE _self, VALUE opts) {
|
41
|
+
VALUE dat = rb_hash_aref(opts, ID2SYM(rb_intern("dat_path")));
|
42
|
+
VALUE key = rb_hash_aref(opts, ID2SYM(rb_intern("key_path")));
|
43
|
+
VALUE log = rb_hash_aref(opts, ID2SYM(rb_intern("log_path")));
|
44
|
+
VALUE app_num = rb_hash_aref(opts, ID2SYM(rb_intern("app_num")));
|
45
|
+
VALUE salt = rb_hash_aref(opts, ID2SYM(rb_intern("salt")));
|
46
|
+
VALUE key_size = rb_hash_aref(opts, ID2SYM(rb_intern("key_size")));
|
47
|
+
VALUE block_size = rb_hash_aref(opts, ID2SYM(rb_intern("block_size")));
|
48
|
+
VALUE load_factor = rb_hash_aref(opts, ID2SYM(rb_intern("load_factor")));
|
49
|
+
|
50
|
+
Check_Type(dat, T_STRING);
|
51
|
+
Check_Type(key, T_STRING);
|
52
|
+
Check_Type(log, T_STRING);
|
53
|
+
Check_Type(app_num, T_FIXNUM);
|
54
|
+
Check_Type(salt, T_FIXNUM);
|
55
|
+
Check_Type(key_size, T_FIXNUM);
|
56
|
+
Check_Type(block_size, T_FIXNUM);
|
57
|
+
Check_Type(load_factor, T_FLOAT);
|
58
|
+
|
59
|
+
std::string _dat = std::string((char*)RSTRING_PTR(dat), RSTRING_LEN(dat));
|
60
|
+
std::string _key = std::string((char*)RSTRING_PTR(key), RSTRING_LEN(key));
|
61
|
+
std::string _log = std::string((char*)RSTRING_PTR(log), RSTRING_LEN(log));
|
62
|
+
|
63
|
+
std::uint64_t _app_num = NUM2ULL(app_num);
|
64
|
+
std::uint64_t _salt = NUM2ULL(salt);
|
65
|
+
nudb::nsize_t _key_size = NUM2UINT(key_size);
|
66
|
+
nudb::nsize_t _block_size = NUM2UINT(block_size);
|
67
|
+
float _load_factor = NUM2DBL(load_factor);
|
68
|
+
|
69
|
+
// TODO parameterize hasher typer
|
70
|
+
nudb::error_code ec;
|
71
|
+
nudb::create<nudb::xxhasher>(_dat, _key, _log,
|
72
|
+
_app_num,
|
73
|
+
_salt,
|
74
|
+
_key_size,
|
75
|
+
_block_size,
|
76
|
+
_load_factor,
|
77
|
+
ec);
|
78
|
+
|
79
|
+
return ec2obj(new nudb::error_code(ec));
|
80
|
+
}
|
81
|
+
|
82
|
+
VALUE rudb_erase_file(VALUE _self, VALUE file) {
|
83
|
+
Check_Type(file, T_STRING);
|
84
|
+
std::string fil = std::string((char*)RSTRING_PTR(file), RSTRING_LEN(file));
|
85
|
+
|
86
|
+
nudb::error_code ec;
|
87
|
+
nudb::erase_file(fil, ec);
|
88
|
+
|
89
|
+
return ec2obj(new nudb::error_code(ec));
|
90
|
+
}
|
91
|
+
|
92
|
+
VALUE rudb_make_salt(VALUE _self) {
|
93
|
+
return INT2NUM(nudb::make_salt());
|
94
|
+
}
|
95
|
+
|
96
|
+
VALUE rudb_block_size(VALUE _self, VALUE _path) {
|
97
|
+
Check_Type(_path, T_STRING);
|
98
|
+
std::string path = std::string((char*)RSTRING_PTR(_path), RSTRING_LEN(_path));
|
99
|
+
return INT2NUM(nudb::block_size(path));
|
100
|
+
}
|
101
|
+
|
102
|
+
///
|
103
|
+
|
104
|
+
void db_free(nudb_store_pointer* store_pointer){
|
105
|
+
if(store_pointer->store != NULL){
|
106
|
+
// FIXME nudb::store is polymorphic w/out virtual destructor
|
107
|
+
delete store_pointer->store;
|
108
|
+
store_pointer->store = NULL;
|
109
|
+
}
|
110
|
+
delete store_pointer;
|
111
|
+
}
|
112
|
+
|
113
|
+
static VALUE store_alloc(VALUE klass){
|
114
|
+
nudb_store_pointer* store_pointer = ALLOC(nudb_store_pointer);
|
115
|
+
return Data_Wrap_Struct(klass, 0, db_free, store_pointer);
|
116
|
+
}
|
117
|
+
|
118
|
+
VALUE rudb_store_init(VALUE _self){
|
119
|
+
nudb_store_pointer* store_pointer;
|
120
|
+
Data_Get_Struct(_self, nudb_store_pointer, store_pointer);
|
121
|
+
store_pointer->store = new nudb::store();
|
122
|
+
return _self;
|
123
|
+
}
|
124
|
+
|
125
|
+
VALUE rudb_store_open(VALUE _self, VALUE dat_path, VALUE key_path, VALUE log_path) {
|
126
|
+
Check_Type(dat_path, T_STRING);
|
127
|
+
Check_Type(key_path, T_STRING);
|
128
|
+
Check_Type(log_path, T_STRING);
|
129
|
+
|
130
|
+
nudb_store_pointer* store_pointer;
|
131
|
+
Data_Get_Struct(_self, nudb_store_pointer, store_pointer);
|
132
|
+
|
133
|
+
std::string dat = std::string((char*)RSTRING_PTR(dat_path),
|
134
|
+
RSTRING_LEN(dat_path));
|
135
|
+
std::string key = std::string((char*)RSTRING_PTR(key_path),
|
136
|
+
RSTRING_LEN(key_path));
|
137
|
+
std::string log = std::string((char*)RSTRING_PTR(log_path),
|
138
|
+
RSTRING_LEN(log_path));
|
139
|
+
|
140
|
+
nudb::error_code ec;
|
141
|
+
store_pointer->store->open(dat, key, log, ec);
|
142
|
+
|
143
|
+
return ec2obj(new nudb::error_code(ec));
|
144
|
+
}
|
145
|
+
|
146
|
+
VALUE rudb_store_insert(VALUE _self, VALUE key, VALUE value){
|
147
|
+
Check_Type(key, T_STRING);
|
148
|
+
Check_Type(value, T_STRING);
|
149
|
+
|
150
|
+
std::string key_str = std::string((char*)RSTRING_PTR(key), RSTRING_LEN(key));
|
151
|
+
std::string value_str = std::string((char*)RSTRING_PTR(value), RSTRING_LEN(value));
|
152
|
+
|
153
|
+
nudb_store_pointer* store_pointer;
|
154
|
+
Data_Get_Struct(_self, nudb_store_pointer, store_pointer);
|
155
|
+
|
156
|
+
if (store_pointer->store == NULL) {
|
157
|
+
rb_raise(rb_eRuntimeError, "db not open");
|
158
|
+
}
|
159
|
+
|
160
|
+
nudb::error_code ec;
|
161
|
+
store_pointer->store->insert(key_str.c_str(),
|
162
|
+
value_str.c_str(),
|
163
|
+
value_str.size(), ec);
|
164
|
+
|
165
|
+
return ec2obj(new nudb::error_code(ec));
|
166
|
+
}
|
167
|
+
|
168
|
+
VALUE rudb_store_fetch(VALUE _self, VALUE key){
|
169
|
+
Check_Type(key, T_STRING);
|
170
|
+
std::string key_str = std::string((char*)RSTRING_PTR(key), RSTRING_LEN(key));
|
171
|
+
|
172
|
+
nudb_store_pointer* store_pointer;
|
173
|
+
Data_Get_Struct(_self, nudb_store_pointer, store_pointer);
|
174
|
+
|
175
|
+
if (store_pointer->store == NULL) {
|
176
|
+
rb_raise(rb_eRuntimeError, "db not open");
|
177
|
+
}
|
178
|
+
|
179
|
+
std::string result;
|
180
|
+
nudb::error_code ec;
|
181
|
+
store_pointer->store->fetch(key_str.c_str(),
|
182
|
+
[&](void const* buffer, std::size_t size){
|
183
|
+
result = std::string((char*) buffer, size);
|
184
|
+
}, ec);
|
185
|
+
|
186
|
+
VALUE result_obj = rb_str_new(result.c_str(),
|
187
|
+
result.size());
|
188
|
+
|
189
|
+
// TODO if block given invoke w/ result_obj (only if succeeded)
|
190
|
+
|
191
|
+
VALUE ec_obj = ec2obj(new nudb::error_code(ec));
|
192
|
+
|
193
|
+
VALUE ret = rb_ary_new();
|
194
|
+
rb_ary_push(ret, result_obj); // TODO Qnil if not success
|
195
|
+
rb_ary_push(ret, ec_obj);
|
196
|
+
|
197
|
+
return ret;
|
198
|
+
}
|
199
|
+
|
200
|
+
VALUE rudb_store_close(VALUE _self){
|
201
|
+
nudb_store_pointer* store_pointer;
|
202
|
+
Data_Get_Struct(_self, nudb_store_pointer, store_pointer);
|
203
|
+
|
204
|
+
nudb::error_code ec;
|
205
|
+
store_pointer->store->close(ec);
|
206
|
+
|
207
|
+
return ec2obj(new nudb::error_code(ec));
|
208
|
+
}
|
209
|
+
|
210
|
+
///
|
211
|
+
|
212
|
+
typedef VALUE (*METHOD)(...);
|
213
|
+
|
214
|
+
extern "C"{
|
215
|
+
void Init_rudb(){
|
216
|
+
mRuDB = rb_define_module("RuDB");
|
217
|
+
rb_define_singleton_method(mRuDB, "create", (METHOD)rudb_create, 1);
|
218
|
+
rb_define_singleton_method(mRuDB, "erase_file", (METHOD)rudb_erase_file, 1);
|
219
|
+
rb_define_singleton_method(mRuDB, "make_salt", (METHOD)rudb_make_salt, 0);
|
220
|
+
rb_define_singleton_method(mRuDB, "block_size", (METHOD)rudb_block_size, 1);
|
221
|
+
|
222
|
+
cRuDB_store = rb_define_class_under(mRuDB, "Store", rb_cObject);
|
223
|
+
rb_define_alloc_func(cRuDB_store, store_alloc);
|
224
|
+
rb_define_method(cRuDB_store, "initialize", (METHOD)rudb_store_init, 0);
|
225
|
+
rb_define_method(cRuDB_store, "open", (METHOD)rudb_store_open, 3);
|
226
|
+
rb_define_method(cRuDB_store, "insert", (METHOD)rudb_store_insert, 2);
|
227
|
+
rb_define_method(cRuDB_store, "fetch", (METHOD)rudb_store_fetch, 1);
|
228
|
+
rb_define_method(cRuDB_store, "close", (METHOD)rudb_store_close, 0);
|
229
|
+
|
230
|
+
cRuDB_ec = rb_define_class_under(mRuDB, "ErrorCode", rb_cObject);
|
231
|
+
rb_define_method(cRuDB_ec, "value", (METHOD)rudb_ec_value, 0);
|
232
|
+
rb_define_method(cRuDB_ec, "message", (METHOD)rudb_ec_message, 0);
|
233
|
+
}
|
234
|
+
}
|
data/lib/rudb/version.rb
ADDED
data/lib/rudb.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'rudb.so'
|
metadata
ADDED
@@ -0,0 +1,104 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rrudb
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Dev Null Productions
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-05-14 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: Ruby NuDB Wrapper
|
14
|
+
email:
|
15
|
+
- devnullproductions@gmail.com
|
16
|
+
executables: []
|
17
|
+
extensions:
|
18
|
+
- ext/rudb/extconf.rb
|
19
|
+
extra_rdoc_files: []
|
20
|
+
files:
|
21
|
+
- ".yardopts"
|
22
|
+
- LICENSE.txt
|
23
|
+
- README.md
|
24
|
+
- examples/example.rb
|
25
|
+
- ext/rudb/NuDB/include/nudb/CMakeLists.txt
|
26
|
+
- ext/rudb/NuDB/include/nudb/_experimental/basic_seconds_clock.hpp
|
27
|
+
- ext/rudb/NuDB/include/nudb/_experimental/chrono_util.hpp
|
28
|
+
- ext/rudb/NuDB/include/nudb/_experimental/test/fail_file.hpp
|
29
|
+
- ext/rudb/NuDB/include/nudb/_experimental/test/temp_dir.hpp
|
30
|
+
- ext/rudb/NuDB/include/nudb/_experimental/test/test_store.hpp
|
31
|
+
- ext/rudb/NuDB/include/nudb/_experimental/test/xor_shift_engine.hpp
|
32
|
+
- ext/rudb/NuDB/include/nudb/_experimental/util.hpp
|
33
|
+
- ext/rudb/NuDB/include/nudb/basic_store.hpp
|
34
|
+
- ext/rudb/NuDB/include/nudb/concepts.hpp
|
35
|
+
- ext/rudb/NuDB/include/nudb/context.hpp
|
36
|
+
- ext/rudb/NuDB/include/nudb/create.hpp
|
37
|
+
- ext/rudb/NuDB/include/nudb/detail/arena.hpp
|
38
|
+
- ext/rudb/NuDB/include/nudb/detail/bucket.hpp
|
39
|
+
- ext/rudb/NuDB/include/nudb/detail/buffer.hpp
|
40
|
+
- ext/rudb/NuDB/include/nudb/detail/bulkio.hpp
|
41
|
+
- ext/rudb/NuDB/include/nudb/detail/cache.hpp
|
42
|
+
- ext/rudb/NuDB/include/nudb/detail/endian.hpp
|
43
|
+
- ext/rudb/NuDB/include/nudb/detail/field.hpp
|
44
|
+
- ext/rudb/NuDB/include/nudb/detail/format.hpp
|
45
|
+
- ext/rudb/NuDB/include/nudb/detail/gentex.hpp
|
46
|
+
- ext/rudb/NuDB/include/nudb/detail/mutex.hpp
|
47
|
+
- ext/rudb/NuDB/include/nudb/detail/pool.hpp
|
48
|
+
- ext/rudb/NuDB/include/nudb/detail/store_base.hpp
|
49
|
+
- ext/rudb/NuDB/include/nudb/detail/stream.hpp
|
50
|
+
- ext/rudb/NuDB/include/nudb/detail/xxhash.hpp
|
51
|
+
- ext/rudb/NuDB/include/nudb/error.hpp
|
52
|
+
- ext/rudb/NuDB/include/nudb/file.hpp
|
53
|
+
- ext/rudb/NuDB/include/nudb/impl/basic_store.ipp
|
54
|
+
- ext/rudb/NuDB/include/nudb/impl/context.ipp
|
55
|
+
- ext/rudb/NuDB/include/nudb/impl/create.ipp
|
56
|
+
- ext/rudb/NuDB/include/nudb/impl/error.ipp
|
57
|
+
- ext/rudb/NuDB/include/nudb/impl/posix_file.ipp
|
58
|
+
- ext/rudb/NuDB/include/nudb/impl/recover.ipp
|
59
|
+
- ext/rudb/NuDB/include/nudb/impl/rekey.ipp
|
60
|
+
- ext/rudb/NuDB/include/nudb/impl/verify.ipp
|
61
|
+
- ext/rudb/NuDB/include/nudb/impl/visit.ipp
|
62
|
+
- ext/rudb/NuDB/include/nudb/impl/win32_file.ipp
|
63
|
+
- ext/rudb/NuDB/include/nudb/native_file.hpp
|
64
|
+
- ext/rudb/NuDB/include/nudb/nudb.hpp
|
65
|
+
- ext/rudb/NuDB/include/nudb/posix_file.hpp
|
66
|
+
- ext/rudb/NuDB/include/nudb/progress.hpp
|
67
|
+
- ext/rudb/NuDB/include/nudb/recover.hpp
|
68
|
+
- ext/rudb/NuDB/include/nudb/rekey.hpp
|
69
|
+
- ext/rudb/NuDB/include/nudb/store.hpp
|
70
|
+
- ext/rudb/NuDB/include/nudb/type_traits.hpp
|
71
|
+
- ext/rudb/NuDB/include/nudb/verify.hpp
|
72
|
+
- ext/rudb/NuDB/include/nudb/version.hpp
|
73
|
+
- ext/rudb/NuDB/include/nudb/visit.hpp
|
74
|
+
- ext/rudb/NuDB/include/nudb/win32_file.hpp
|
75
|
+
- ext/rudb/NuDB/include/nudb/xxhasher.hpp
|
76
|
+
- ext/rudb/extconf.rb
|
77
|
+
- ext/rudb/rudb.cpp
|
78
|
+
- lib/rudb.rb
|
79
|
+
- lib/rudb/version.rb
|
80
|
+
homepage: https://github.com/DevNullProd/RuDB
|
81
|
+
licenses:
|
82
|
+
- MIT
|
83
|
+
metadata: {}
|
84
|
+
post_install_message:
|
85
|
+
rdoc_options: []
|
86
|
+
require_paths:
|
87
|
+
- lib
|
88
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
89
|
+
requirements:
|
90
|
+
- - ">="
|
91
|
+
- !ruby/object:Gem::Version
|
92
|
+
version: '0'
|
93
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
94
|
+
requirements:
|
95
|
+
- - ">="
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
version: '0'
|
98
|
+
requirements: []
|
99
|
+
rubyforge_project:
|
100
|
+
rubygems_version: 2.7.6
|
101
|
+
signing_key:
|
102
|
+
specification_version: 4
|
103
|
+
summary: Wrapper around the NuDB fast key/value insert-only database.
|
104
|
+
test_files: []
|