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
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 97365f391776500be966ed6f9549b86e56121cb688ea6875bd6cba2e7d39dbcb
4
+ data.tar.gz: 364d820a47146a01a2d969111b1e044ec80bc8e02f2887b5c1c49678b4a60551
5
+ SHA512:
6
+ metadata.gz: 6fcef1c9c4e036e881ba4805ede5579e6eed788f7ed6d5fa3af93888ce55d284751f8ed555809e6ecedcf2f0e478e76d252bcefd4047014c12d7feaa19067327
7
+ data.tar.gz: 880d565f2aac8e0ac3821c495a9c52eb82baae3acf10fdf7601c578ed3f4d4ad1b12dd269ff490c47cfc8222d4395d507d7b78e5b288aead70373fa7b8bffc58
data/.yardopts ADDED
@@ -0,0 +1 @@
1
+ --no-private
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2019 Dev Null Productions <devnullproductions@gmail.com>
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,26 @@
1
+ ### RuDB - Ruby NuDB wrapper
2
+
3
+ RuDB provides a native wrapper around the [NuDB](https://github.com/CPPAlliance/NuDB) database. As NuDB is a *header only* library, this gem includes all the necessary logic builtin to manage a NuDB instance. As per the NuDB requirements, the following are necessary to install this gem:
4
+
5
+ * Boost 1.61 or higher (development headers)
6
+ * C++11 or greater
7
+
8
+ #### Installation / Documentation
9
+
10
+ rudb may be installed with the following command:
11
+
12
+ ```ruby
13
+ $ gem install rrudb
14
+ ```
15
+
16
+ (Yes, there are two '**r**'s in there!)
17
+
18
+ #### Usage
19
+
20
+ See **examples/example.rb** for a Ruby port of **NuDB/examples/example.cpp**
21
+
22
+ #### License
23
+
24
+ Copyright (C) 2019 Dev Null Productions
25
+
26
+ Made available under the MIT License
@@ -0,0 +1,39 @@
1
+ # Port of NuDB/examples/example.cpp to ruby
2
+
3
+ require 'rudb'
4
+
5
+ N = 1000
6
+ KEY_SIZE = 32/8 # => sizeof(uint32_t) = 4 bytes
7
+
8
+ dat_path = 'db.dat'
9
+ key_path = 'db.key'
10
+ log_path = 'db.log'
11
+
12
+ ec = RuDB::create :dat_path => dat_path,
13
+ :key_path => key_path,
14
+ :log_path => log_path,
15
+ :app_num => 1,
16
+ :salt => RuDB::make_salt,
17
+ :key_size => KEY_SIZE,
18
+ :block_size => RuDB::block_size('.'),
19
+ :load_factor => 0.5
20
+
21
+ db = RuDB::Store.new
22
+ ec = db.open(dat_path, key_path, log_path)
23
+
24
+ data = 0
25
+ 0.upto(N) { |i|
26
+ ec = db.insert([i].pack("L"),
27
+ [data].pack("L"))
28
+ }
29
+
30
+ 0.upto(N) { |i|
31
+ dat, ec = db.fetch([i].pack("L"))
32
+ # do something with dat
33
+ }
34
+
35
+ ec = db.close
36
+
37
+ RuDB::erase_file dat_path
38
+ RuDB::erase_file key_path
39
+ RuDB::erase_file log_path
@@ -0,0 +1,104 @@
1
+
2
+ #[===================================================================[
3
+ define the primary target: nudb (header only lib)
4
+ #]===================================================================]
5
+
6
+ add_library (nudb_core INTERFACE)
7
+ target_include_directories (nudb_core
8
+ INTERFACE
9
+ $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/..>
10
+ $<INSTALL_INTERFACE:include>)
11
+ target_link_libraries (nudb_core
12
+ INTERFACE
13
+ Boost::thread
14
+ Boost::system)
15
+ # this is the min std required to use NuDB - should
16
+ # it be 11 or 14?
17
+ target_compile_features (nudb_core INTERFACE cxx_std_11)
18
+ add_library (NuDB::nudb ALIAS nudb_core)
19
+ install (
20
+ FILES
21
+ basic_store.hpp
22
+ concepts.hpp
23
+ create.hpp
24
+ error.hpp
25
+ file.hpp
26
+ native_file.hpp
27
+ nudb.hpp
28
+ posix_file.hpp
29
+ progress.hpp
30
+ recover.hpp
31
+ rekey.hpp
32
+ store.hpp
33
+ type_traits.hpp
34
+ verify.hpp
35
+ version.hpp
36
+ visit.hpp
37
+ win32_file.hpp
38
+ xxhasher.hpp
39
+ DESTINATION include/nudb)
40
+ install (
41
+ FILES
42
+ _experimental/basic_seconds_clock.hpp
43
+ _experimental/chrono_util.hpp
44
+ _experimental/util.hpp
45
+ DESTINATION include/nudb/_experimental)
46
+ # not sure if these should be part of the install set
47
+ # are they needed by any public headers ?
48
+ install (
49
+ FILES
50
+ _experimental/test/fail_file.hpp
51
+ _experimental/test/temp_dir.hpp
52
+ _experimental/test/test_store.hpp
53
+ _experimental/test/xor_shift_engine.hpp
54
+ DESTINATION include/nudb/_experimental/test)
55
+ install (
56
+ FILES
57
+ impl/basic_store.ipp
58
+ impl/create.ipp
59
+ impl/error.ipp
60
+ impl/posix_file.ipp
61
+ impl/recover.ipp
62
+ impl/rekey.ipp
63
+ impl/verify.ipp
64
+ impl/visit.ipp
65
+ impl/win32_file.ipp
66
+ DESTINATION include/nudb/impl)
67
+ install (
68
+ FILES
69
+ detail/arena.hpp
70
+ detail/bucket.hpp
71
+ detail/buffer.hpp
72
+ detail/bulkio.hpp
73
+ detail/cache.hpp
74
+ detail/endian.hpp
75
+ detail/field.hpp
76
+ detail/format.hpp
77
+ detail/gentex.hpp
78
+ detail/mutex.hpp
79
+ detail/pool.hpp
80
+ detail/stream.hpp
81
+ detail/xxhash.hpp
82
+ DESTINATION include/nudb/impl)
83
+ install (
84
+ TARGETS nudb_core
85
+ EXPORT NuDBExports
86
+ INCLUDES DESTINATION include)
87
+ install (EXPORT NuDBExports
88
+ FILE NuDBTargets.cmake
89
+ NAMESPACE NuDB::
90
+ DESTINATION lib/cmake/nudb)
91
+ include (CMakePackageConfigHelpers)
92
+ write_basic_package_version_file (
93
+ NuDBConfigVersion.cmake
94
+ VERSION ${CMAKE_PROJECT_VERSION}
95
+ COMPATIBILITY SameMajorVersion)
96
+
97
+ if (is_root_project)
98
+ install (
99
+ FILES
100
+ ${CMAKE_SOURCE_DIR}/scripts/NuDBConfig.cmake
101
+ ${CMAKE_CURRENT_BINARY_DIR}/NuDBConfigVersion.cmake
102
+ DESTINATION lib/cmake/nudb)
103
+ endif ()
104
+
@@ -0,0 +1,200 @@
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_EXPERIMENTAL_BASIC_SECONDS_CLOCK_HPP
9
+ #define NUDB_EXPERIMENTAL_BASIC_SECONDS_CLOCK_HPP
10
+
11
+ #include "chrono_util.hpp"
12
+
13
+ #include <algorithm>
14
+ #include <chrono>
15
+ #include <condition_variable>
16
+ #include <mutex>
17
+ #include <thread>
18
+ #include <vector>
19
+
20
+ namespace detail {
21
+
22
+ class seconds_clock_worker
23
+ {
24
+ public:
25
+ virtual void sample() = 0;
26
+ };
27
+
28
+ //------------------------------------------------------------------------------
29
+
30
+ // Updates the clocks
31
+ class seconds_clock_thread
32
+ {
33
+ public:
34
+ using mutex = std::mutex;
35
+ using cond_var = std::condition_variable;
36
+ using lock_guard = std::lock_guard <mutex>;
37
+ using unique_lock = std::unique_lock <mutex>;
38
+ using clock_type = std::chrono::steady_clock;
39
+ using seconds = std::chrono::seconds;
40
+ using thread = std::thread;
41
+ using workers = std::vector <seconds_clock_worker*>;
42
+
43
+ bool stop_;
44
+ mutex m_;
45
+ cond_var cond_;
46
+ workers workers_;
47
+ thread thread_;
48
+
49
+ seconds_clock_thread()
50
+ : stop_(false)
51
+ {
52
+ thread_ = thread{
53
+ &seconds_clock_thread::run, this};
54
+ }
55
+
56
+ ~seconds_clock_thread()
57
+ {
58
+ stop();
59
+ }
60
+
61
+ void add(seconds_clock_worker& w)
62
+ {
63
+ lock_guard lock{m_};
64
+ workers_.push_back(&w);
65
+ }
66
+
67
+ void remove(seconds_clock_worker& w)
68
+ {
69
+ lock_guard lock{m_};
70
+ workers_.erase(std::find(
71
+ workers_.begin(), workers_.end(), &w));
72
+ }
73
+
74
+ void stop()
75
+ {
76
+ if(thread_.joinable())
77
+ {
78
+ {
79
+ lock_guard lock{m_};
80
+ stop_ = true;
81
+ }
82
+ cond_.notify_all();
83
+ thread_.join();
84
+ }
85
+ }
86
+
87
+ void run()
88
+ {
89
+ unique_lock lock{m_};
90
+ for(;;)
91
+ {
92
+ for(auto iter : workers_)
93
+ iter->sample();
94
+
95
+ using namespace std::chrono;
96
+ clock_type::time_point const when(
97
+ floor <seconds>(
98
+ clock_type::now().time_since_epoch()) +
99
+ milliseconds(900));
100
+
101
+ if(cond_.wait_until(lock, when, [this]{ return stop_; }))
102
+ return;
103
+ }
104
+ }
105
+
106
+ static seconds_clock_thread& instance()
107
+ {
108
+ static seconds_clock_thread singleton;
109
+ return singleton;
110
+ }
111
+ };
112
+
113
+ } // detail
114
+
115
+ //------------------------------------------------------------------------------
116
+
117
+ /** Called before main exits to terminate the utility thread.
118
+ This is a workaround for Visual Studio 2013:
119
+ http://connect.microsoft.com/VisualStudio/feedback/details/786016/creating-a-global-c-object-that-used-thread-join-in-its-destructor-causes-a-lockup
120
+ http://stackoverflow.com/questions/10915233/stdthreadjoin-hangs-if-called-after-main-exits-when-using-vs2012-rc
121
+ */
122
+ inline
123
+ void
124
+ basic_seconds_clock_main_hook()
125
+ {
126
+ #ifdef _MSC_VER
127
+ detail::seconds_clock_thread::instance().stop();
128
+ #endif
129
+ }
130
+
131
+ /** A clock whose minimum resolution is one second.
132
+
133
+ The purpose of this class is to optimize the performance of the now()
134
+ member function call. It uses a dedicated thread that wakes up at least
135
+ once per second to sample the requested trivial clock.
136
+
137
+ @tparam Clock A type meeting these requirements:
138
+ http://en.cppreference.com/w/cpp/concept/Clock
139
+ */
140
+ template<class Clock>
141
+ class basic_seconds_clock
142
+ {
143
+ public:
144
+ using rep = typename Clock::rep;
145
+ using period = typename Clock::period;
146
+ using duration = typename Clock::duration;
147
+ using time_point = typename Clock::time_point;
148
+
149
+ static bool const is_steady = Clock::is_steady;
150
+
151
+ static time_point now()
152
+ {
153
+ // Make sure the thread is constructed before the
154
+ // worker otherwise we will crash during destruction
155
+ // of objects with static storage duration.
156
+ struct initializer
157
+ {
158
+ initializer()
159
+ {
160
+ detail::seconds_clock_thread::instance();
161
+ }
162
+ };
163
+ static initializer init;
164
+
165
+ struct worker : detail::seconds_clock_worker
166
+ {
167
+ time_point m_now;
168
+ std::mutex m_;
169
+
170
+ worker()
171
+ : m_now(Clock::now())
172
+ {
173
+ detail::seconds_clock_thread::instance().add(*this);
174
+ }
175
+
176
+ ~worker()
177
+ {
178
+ detail::seconds_clock_thread::instance().remove(*this);
179
+ }
180
+
181
+ time_point now()
182
+ {
183
+ std::lock_guard<std::mutex> lock{m_};
184
+ return m_now;
185
+ }
186
+
187
+ void sample()
188
+ {
189
+ std::lock_guard<std::mutex> lock{m_};
190
+ m_now = Clock::now();
191
+ }
192
+ };
193
+
194
+ static worker w;
195
+
196
+ return w.now();
197
+ }
198
+ };
199
+
200
+ #endif
@@ -0,0 +1,58 @@
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_EXPERIMENTAL_CHRONO_UTIL_HPP
9
+ #define NUDB_EXPERIMENTAL_CHRONO_UTIL_HPP
10
+
11
+ #include <chrono>
12
+
13
+ // From Howard Hinnant
14
+ // http://home.roadrunner.com/~hinnant/duration_io/chrono_util.html
15
+
16
+ #if !defined(_MSC_FULL_VER) || (_MSC_FULL_VER <= 190023506)
17
+ // round down
18
+ template <class To, class Rep, class Period>
19
+ To floor(std::chrono::duration <Rep, Period> const& d)
20
+ {
21
+ To t = std::chrono::duration_cast<To>(d);
22
+ if (t > d)
23
+ --t;
24
+ return t;
25
+ }
26
+
27
+ // round to nearest, to even on tie
28
+ template <class To, class Rep, class Period>
29
+ To round (std::chrono::duration <Rep, Period> const& d)
30
+ {
31
+ To t0 = std::chrono::duration_cast<To>(d);
32
+ To t1 = t0;
33
+ ++t1;
34
+ auto diff0 = d - t0;
35
+ auto diff1 = t1 - d;
36
+ if (diff0 == diff1)
37
+ {
38
+ if (t0.count() & 1)
39
+ return t1;
40
+ return t0;
41
+ }
42
+ else if (diff0 < diff1)
43
+ return t0;
44
+ return t1;
45
+ }
46
+
47
+ // round up
48
+ template <class To, class Rep, class Period>
49
+ To ceil (std::chrono::duration <Rep, Period> const& d)
50
+ {
51
+ To t = std::chrono::duration_cast<To>(d);
52
+ if (t < d)
53
+ ++t;
54
+ return t;
55
+ }
56
+ #endif
57
+
58
+ #endif