filiptepper-leveldb-ruby 0.14

Sign up to get free protection for your applications and to get access to all the features.
Files changed (123) hide show
  1. data/LICENSE +24 -0
  2. data/README +72 -0
  3. data/ext/leveldb/extconf.rb +14 -0
  4. data/ext/leveldb/leveldb.cc +530 -0
  5. data/ext/leveldb/platform.rb +83 -0
  6. data/leveldb/Makefile +191 -0
  7. data/leveldb/build_detect_platform +160 -0
  8. data/leveldb/db/builder.cc +88 -0
  9. data/leveldb/db/builder.h +34 -0
  10. data/leveldb/db/c.cc +581 -0
  11. data/leveldb/db/corruption_test.cc +359 -0
  12. data/leveldb/db/db_bench.cc +970 -0
  13. data/leveldb/db/db_impl.cc +1448 -0
  14. data/leveldb/db/db_impl.h +194 -0
  15. data/leveldb/db/db_iter.cc +299 -0
  16. data/leveldb/db/db_iter.h +26 -0
  17. data/leveldb/db/db_test.cc +1901 -0
  18. data/leveldb/db/dbformat.cc +140 -0
  19. data/leveldb/db/dbformat.h +227 -0
  20. data/leveldb/db/dbformat_test.cc +112 -0
  21. data/leveldb/db/filename.cc +139 -0
  22. data/leveldb/db/filename.h +80 -0
  23. data/leveldb/db/filename_test.cc +122 -0
  24. data/leveldb/db/log_format.h +35 -0
  25. data/leveldb/db/log_reader.cc +259 -0
  26. data/leveldb/db/log_reader.h +108 -0
  27. data/leveldb/db/log_test.cc +500 -0
  28. data/leveldb/db/log_writer.cc +103 -0
  29. data/leveldb/db/log_writer.h +48 -0
  30. data/leveldb/db/memtable.cc +145 -0
  31. data/leveldb/db/memtable.h +91 -0
  32. data/leveldb/db/repair.cc +389 -0
  33. data/leveldb/db/skiplist.h +379 -0
  34. data/leveldb/db/skiplist_test.cc +378 -0
  35. data/leveldb/db/snapshot.h +66 -0
  36. data/leveldb/db/table_cache.cc +121 -0
  37. data/leveldb/db/table_cache.h +61 -0
  38. data/leveldb/db/version_edit.cc +266 -0
  39. data/leveldb/db/version_edit.h +107 -0
  40. data/leveldb/db/version_edit_test.cc +46 -0
  41. data/leveldb/db/version_set.cc +1402 -0
  42. data/leveldb/db/version_set.h +370 -0
  43. data/leveldb/db/version_set_test.cc +179 -0
  44. data/leveldb/db/write_batch.cc +147 -0
  45. data/leveldb/db/write_batch_internal.h +49 -0
  46. data/leveldb/db/write_batch_test.cc +120 -0
  47. data/leveldb/helpers/memenv/memenv.cc +374 -0
  48. data/leveldb/helpers/memenv/memenv.h +20 -0
  49. data/leveldb/helpers/memenv/memenv_test.cc +232 -0
  50. data/leveldb/include/leveldb/c.h +275 -0
  51. data/leveldb/include/leveldb/cache.h +99 -0
  52. data/leveldb/include/leveldb/comparator.h +63 -0
  53. data/leveldb/include/leveldb/db.h +161 -0
  54. data/leveldb/include/leveldb/env.h +323 -0
  55. data/leveldb/include/leveldb/filter_policy.h +70 -0
  56. data/leveldb/include/leveldb/iterator.h +100 -0
  57. data/leveldb/include/leveldb/options.h +195 -0
  58. data/leveldb/include/leveldb/slice.h +109 -0
  59. data/leveldb/include/leveldb/status.h +106 -0
  60. data/leveldb/include/leveldb/table.h +85 -0
  61. data/leveldb/include/leveldb/table_builder.h +92 -0
  62. data/leveldb/include/leveldb/write_batch.h +64 -0
  63. data/leveldb/port/atomic_pointer.h +144 -0
  64. data/leveldb/port/port.h +21 -0
  65. data/leveldb/port/port_android.cc +64 -0
  66. data/leveldb/port/port_android.h +159 -0
  67. data/leveldb/port/port_example.h +125 -0
  68. data/leveldb/port/port_posix.cc +50 -0
  69. data/leveldb/port/port_posix.h +129 -0
  70. data/leveldb/port/win/stdint.h +24 -0
  71. data/leveldb/table/block.cc +267 -0
  72. data/leveldb/table/block.h +44 -0
  73. data/leveldb/table/block_builder.cc +109 -0
  74. data/leveldb/table/block_builder.h +57 -0
  75. data/leveldb/table/filter_block.cc +111 -0
  76. data/leveldb/table/filter_block.h +68 -0
  77. data/leveldb/table/filter_block_test.cc +128 -0
  78. data/leveldb/table/format.cc +145 -0
  79. data/leveldb/table/format.h +108 -0
  80. data/leveldb/table/iterator.cc +67 -0
  81. data/leveldb/table/iterator_wrapper.h +63 -0
  82. data/leveldb/table/merger.cc +197 -0
  83. data/leveldb/table/merger.h +26 -0
  84. data/leveldb/table/table.cc +276 -0
  85. data/leveldb/table/table_builder.cc +270 -0
  86. data/leveldb/table/table_test.cc +838 -0
  87. data/leveldb/table/two_level_iterator.cc +182 -0
  88. data/leveldb/table/two_level_iterator.h +34 -0
  89. data/leveldb/util/arena.cc +68 -0
  90. data/leveldb/util/arena.h +68 -0
  91. data/leveldb/util/arena_test.cc +68 -0
  92. data/leveldb/util/bloom.cc +95 -0
  93. data/leveldb/util/bloom_test.cc +159 -0
  94. data/leveldb/util/cache.cc +328 -0
  95. data/leveldb/util/cache_test.cc +186 -0
  96. data/leveldb/util/coding.cc +194 -0
  97. data/leveldb/util/coding.h +104 -0
  98. data/leveldb/util/coding_test.cc +173 -0
  99. data/leveldb/util/comparator.cc +76 -0
  100. data/leveldb/util/crc32c.cc +332 -0
  101. data/leveldb/util/crc32c.h +45 -0
  102. data/leveldb/util/crc32c_test.cc +72 -0
  103. data/leveldb/util/env.cc +96 -0
  104. data/leveldb/util/env_posix.cc +609 -0
  105. data/leveldb/util/env_test.cc +104 -0
  106. data/leveldb/util/filter_policy.cc +11 -0
  107. data/leveldb/util/hash.cc +45 -0
  108. data/leveldb/util/hash.h +19 -0
  109. data/leveldb/util/histogram.cc +139 -0
  110. data/leveldb/util/histogram.h +42 -0
  111. data/leveldb/util/logging.cc +81 -0
  112. data/leveldb/util/logging.h +47 -0
  113. data/leveldb/util/mutexlock.h +39 -0
  114. data/leveldb/util/options.cc +29 -0
  115. data/leveldb/util/posix_logger.h +98 -0
  116. data/leveldb/util/random.h +59 -0
  117. data/leveldb/util/status.cc +75 -0
  118. data/leveldb/util/testharness.cc +77 -0
  119. data/leveldb/util/testharness.h +138 -0
  120. data/leveldb/util/testutil.cc +51 -0
  121. data/leveldb/util/testutil.h +53 -0
  122. data/lib/leveldb.rb +76 -0
  123. metadata +175 -0
@@ -0,0 +1,20 @@
1
+ // Copyright (c) 2011 The LevelDB Authors. All rights reserved.
2
+ // Use of this source code is governed by a BSD-style license that can be
3
+ // found in the LICENSE file. See the AUTHORS file for names of contributors.
4
+
5
+ #ifndef STORAGE_LEVELDB_HELPERS_MEMENV_MEMENV_H_
6
+ #define STORAGE_LEVELDB_HELPERS_MEMENV_MEMENV_H_
7
+
8
+ namespace leveldb {
9
+
10
+ class Env;
11
+
12
+ // Returns a new environment that stores its data in memory and delegates
13
+ // all non-file-storage tasks to base_env. The caller must delete the result
14
+ // when it is no longer needed.
15
+ // *base_env must remain live while the result is in use.
16
+ Env* NewMemEnv(Env* base_env);
17
+
18
+ } // namespace leveldb
19
+
20
+ #endif // STORAGE_LEVELDB_HELPERS_MEMENV_MEMENV_H_
@@ -0,0 +1,232 @@
1
+ // Copyright (c) 2011 The LevelDB Authors. All rights reserved.
2
+ // Use of this source code is governed by a BSD-style license that can be
3
+ // found in the LICENSE file. See the AUTHORS file for names of contributors.
4
+
5
+ #include "helpers/memenv/memenv.h"
6
+
7
+ #include "db/db_impl.h"
8
+ #include "leveldb/db.h"
9
+ #include "leveldb/env.h"
10
+ #include "util/testharness.h"
11
+ #include <string>
12
+ #include <vector>
13
+
14
+ namespace leveldb {
15
+
16
+ class MemEnvTest {
17
+ public:
18
+ Env* env_;
19
+
20
+ MemEnvTest()
21
+ : env_(NewMemEnv(Env::Default())) {
22
+ }
23
+ ~MemEnvTest() {
24
+ delete env_;
25
+ }
26
+ };
27
+
28
+ TEST(MemEnvTest, Basics) {
29
+ uint64_t file_size;
30
+ WritableFile* writable_file;
31
+ std::vector<std::string> children;
32
+
33
+ ASSERT_OK(env_->CreateDir("/dir"));
34
+
35
+ // Check that the directory is empty.
36
+ ASSERT_TRUE(!env_->FileExists("/dir/non_existent"));
37
+ ASSERT_TRUE(!env_->GetFileSize("/dir/non_existent", &file_size).ok());
38
+ ASSERT_OK(env_->GetChildren("/dir", &children));
39
+ ASSERT_EQ(0, children.size());
40
+
41
+ // Create a file.
42
+ ASSERT_OK(env_->NewWritableFile("/dir/f", &writable_file));
43
+ delete writable_file;
44
+
45
+ // Check that the file exists.
46
+ ASSERT_TRUE(env_->FileExists("/dir/f"));
47
+ ASSERT_OK(env_->GetFileSize("/dir/f", &file_size));
48
+ ASSERT_EQ(0, file_size);
49
+ ASSERT_OK(env_->GetChildren("/dir", &children));
50
+ ASSERT_EQ(1, children.size());
51
+ ASSERT_EQ("f", children[0]);
52
+
53
+ // Write to the file.
54
+ ASSERT_OK(env_->NewWritableFile("/dir/f", &writable_file));
55
+ ASSERT_OK(writable_file->Append("abc"));
56
+ delete writable_file;
57
+
58
+ // Check for expected size.
59
+ ASSERT_OK(env_->GetFileSize("/dir/f", &file_size));
60
+ ASSERT_EQ(3, file_size);
61
+
62
+ // Check that renaming works.
63
+ ASSERT_TRUE(!env_->RenameFile("/dir/non_existent", "/dir/g").ok());
64
+ ASSERT_OK(env_->RenameFile("/dir/f", "/dir/g"));
65
+ ASSERT_TRUE(!env_->FileExists("/dir/f"));
66
+ ASSERT_TRUE(env_->FileExists("/dir/g"));
67
+ ASSERT_OK(env_->GetFileSize("/dir/g", &file_size));
68
+ ASSERT_EQ(3, file_size);
69
+
70
+ // Check that opening non-existent file fails.
71
+ SequentialFile* seq_file;
72
+ RandomAccessFile* rand_file;
73
+ ASSERT_TRUE(!env_->NewSequentialFile("/dir/non_existent", &seq_file).ok());
74
+ ASSERT_TRUE(!seq_file);
75
+ ASSERT_TRUE(!env_->NewRandomAccessFile("/dir/non_existent", &rand_file).ok());
76
+ ASSERT_TRUE(!rand_file);
77
+
78
+ // Check that deleting works.
79
+ ASSERT_TRUE(!env_->DeleteFile("/dir/non_existent").ok());
80
+ ASSERT_OK(env_->DeleteFile("/dir/g"));
81
+ ASSERT_TRUE(!env_->FileExists("/dir/g"));
82
+ ASSERT_OK(env_->GetChildren("/dir", &children));
83
+ ASSERT_EQ(0, children.size());
84
+ ASSERT_OK(env_->DeleteDir("/dir"));
85
+ }
86
+
87
+ TEST(MemEnvTest, ReadWrite) {
88
+ WritableFile* writable_file;
89
+ SequentialFile* seq_file;
90
+ RandomAccessFile* rand_file;
91
+ Slice result;
92
+ char scratch[100];
93
+
94
+ ASSERT_OK(env_->CreateDir("/dir"));
95
+
96
+ ASSERT_OK(env_->NewWritableFile("/dir/f", &writable_file));
97
+ ASSERT_OK(writable_file->Append("hello "));
98
+ ASSERT_OK(writable_file->Append("world"));
99
+ delete writable_file;
100
+
101
+ // Read sequentially.
102
+ ASSERT_OK(env_->NewSequentialFile("/dir/f", &seq_file));
103
+ ASSERT_OK(seq_file->Read(5, &result, scratch)); // Read "hello".
104
+ ASSERT_EQ(0, result.compare("hello"));
105
+ ASSERT_OK(seq_file->Skip(1));
106
+ ASSERT_OK(seq_file->Read(1000, &result, scratch)); // Read "world".
107
+ ASSERT_EQ(0, result.compare("world"));
108
+ ASSERT_OK(seq_file->Read(1000, &result, scratch)); // Try reading past EOF.
109
+ ASSERT_EQ(0, result.size());
110
+ ASSERT_OK(seq_file->Skip(100)); // Try to skip past end of file.
111
+ ASSERT_OK(seq_file->Read(1000, &result, scratch));
112
+ ASSERT_EQ(0, result.size());
113
+ delete seq_file;
114
+
115
+ // Random reads.
116
+ ASSERT_OK(env_->NewRandomAccessFile("/dir/f", &rand_file));
117
+ ASSERT_OK(rand_file->Read(6, 5, &result, scratch)); // Read "world".
118
+ ASSERT_EQ(0, result.compare("world"));
119
+ ASSERT_OK(rand_file->Read(0, 5, &result, scratch)); // Read "hello".
120
+ ASSERT_EQ(0, result.compare("hello"));
121
+ ASSERT_OK(rand_file->Read(10, 100, &result, scratch)); // Read "d".
122
+ ASSERT_EQ(0, result.compare("d"));
123
+
124
+ // Too high offset.
125
+ ASSERT_TRUE(!rand_file->Read(1000, 5, &result, scratch).ok());
126
+ delete rand_file;
127
+ }
128
+
129
+ TEST(MemEnvTest, Locks) {
130
+ FileLock* lock;
131
+
132
+ // These are no-ops, but we test they return success.
133
+ ASSERT_OK(env_->LockFile("some file", &lock));
134
+ ASSERT_OK(env_->UnlockFile(lock));
135
+ }
136
+
137
+ TEST(MemEnvTest, Misc) {
138
+ std::string test_dir;
139
+ ASSERT_OK(env_->GetTestDirectory(&test_dir));
140
+ ASSERT_TRUE(!test_dir.empty());
141
+
142
+ WritableFile* writable_file;
143
+ ASSERT_OK(env_->NewWritableFile("/a/b", &writable_file));
144
+
145
+ // These are no-ops, but we test they return success.
146
+ ASSERT_OK(writable_file->Sync());
147
+ ASSERT_OK(writable_file->Flush());
148
+ ASSERT_OK(writable_file->Close());
149
+ delete writable_file;
150
+ }
151
+
152
+ TEST(MemEnvTest, LargeWrite) {
153
+ const size_t kWriteSize = 300 * 1024;
154
+ char* scratch = new char[kWriteSize * 2];
155
+
156
+ std::string write_data;
157
+ for (size_t i = 0; i < kWriteSize; ++i) {
158
+ write_data.append(1, static_cast<char>(i));
159
+ }
160
+
161
+ WritableFile* writable_file;
162
+ ASSERT_OK(env_->NewWritableFile("/dir/f", &writable_file));
163
+ ASSERT_OK(writable_file->Append("foo"));
164
+ ASSERT_OK(writable_file->Append(write_data));
165
+ delete writable_file;
166
+
167
+ SequentialFile* seq_file;
168
+ Slice result;
169
+ ASSERT_OK(env_->NewSequentialFile("/dir/f", &seq_file));
170
+ ASSERT_OK(seq_file->Read(3, &result, scratch)); // Read "foo".
171
+ ASSERT_EQ(0, result.compare("foo"));
172
+
173
+ size_t read = 0;
174
+ std::string read_data;
175
+ while (read < kWriteSize) {
176
+ ASSERT_OK(seq_file->Read(kWriteSize - read, &result, scratch));
177
+ read_data.append(result.data(), result.size());
178
+ read += result.size();
179
+ }
180
+ ASSERT_TRUE(write_data == read_data);
181
+ delete seq_file;
182
+ delete [] scratch;
183
+ }
184
+
185
+ TEST(MemEnvTest, DBTest) {
186
+ Options options;
187
+ options.create_if_missing = true;
188
+ options.env = env_;
189
+ DB* db;
190
+
191
+ const Slice keys[] = {Slice("aaa"), Slice("bbb"), Slice("ccc")};
192
+ const Slice vals[] = {Slice("foo"), Slice("bar"), Slice("baz")};
193
+
194
+ ASSERT_OK(DB::Open(options, "/dir/db", &db));
195
+ for (size_t i = 0; i < 3; ++i) {
196
+ ASSERT_OK(db->Put(WriteOptions(), keys[i], vals[i]));
197
+ }
198
+
199
+ for (size_t i = 0; i < 3; ++i) {
200
+ std::string res;
201
+ ASSERT_OK(db->Get(ReadOptions(), keys[i], &res));
202
+ ASSERT_TRUE(res == vals[i]);
203
+ }
204
+
205
+ Iterator* iterator = db->NewIterator(ReadOptions());
206
+ iterator->SeekToFirst();
207
+ for (size_t i = 0; i < 3; ++i) {
208
+ ASSERT_TRUE(iterator->Valid());
209
+ ASSERT_TRUE(keys[i] == iterator->key());
210
+ ASSERT_TRUE(vals[i] == iterator->value());
211
+ iterator->Next();
212
+ }
213
+ ASSERT_TRUE(!iterator->Valid());
214
+ delete iterator;
215
+
216
+ DBImpl* dbi = reinterpret_cast<DBImpl*>(db);
217
+ ASSERT_OK(dbi->TEST_CompactMemTable());
218
+
219
+ for (size_t i = 0; i < 3; ++i) {
220
+ std::string res;
221
+ ASSERT_OK(db->Get(ReadOptions(), keys[i], &res));
222
+ ASSERT_TRUE(res == vals[i]);
223
+ }
224
+
225
+ delete db;
226
+ }
227
+
228
+ } // namespace leveldb
229
+
230
+ int main(int argc, char** argv) {
231
+ return leveldb::test::RunAllTests();
232
+ }
@@ -0,0 +1,275 @@
1
+ /* Copyright (c) 2011 The LevelDB Authors. All rights reserved.
2
+ Use of this source code is governed by a BSD-style license that can be
3
+ found in the LICENSE file. See the AUTHORS file for names of contributors.
4
+
5
+ C bindings for leveldb. May be useful as a stable ABI that can be
6
+ used by programs that keep leveldb in a shared library, or for
7
+ a JNI api.
8
+
9
+ Does not support:
10
+ . getters for the option types
11
+ . custom comparators that implement key shortening
12
+ . capturing post-write-snapshot
13
+ . custom iter, db, env, cache implementations using just the C bindings
14
+
15
+ Some conventions:
16
+
17
+ (1) We expose just opaque struct pointers and functions to clients.
18
+ This allows us to change internal representations without having to
19
+ recompile clients.
20
+
21
+ (2) For simplicity, there is no equivalent to the Slice type. Instead,
22
+ the caller has to pass the pointer and length as separate
23
+ arguments.
24
+
25
+ (3) Errors are represented by a null-terminated c string. NULL
26
+ means no error. All operations that can raise an error are passed
27
+ a "char** errptr" as the last argument. One of the following must
28
+ be true on entry:
29
+ *errptr == NULL
30
+ *errptr points to a malloc()ed null-terminated error message
31
+ On success, a leveldb routine leaves *errptr unchanged.
32
+ On failure, leveldb frees the old value of *errptr and
33
+ set *errptr to a malloc()ed error message.
34
+
35
+ (4) Bools have the type unsigned char (0 == false; rest == true)
36
+
37
+ (5) All of the pointer arguments must be non-NULL.
38
+ */
39
+
40
+ #ifndef STORAGE_LEVELDB_INCLUDE_C_H_
41
+ #define STORAGE_LEVELDB_INCLUDE_C_H_
42
+
43
+ #ifdef __cplusplus
44
+ extern "C" {
45
+ #endif
46
+
47
+ #include <stdarg.h>
48
+ #include <stddef.h>
49
+ #include <stdint.h>
50
+
51
+ /* Exported types */
52
+
53
+ typedef struct leveldb_t leveldb_t;
54
+ typedef struct leveldb_cache_t leveldb_cache_t;
55
+ typedef struct leveldb_comparator_t leveldb_comparator_t;
56
+ typedef struct leveldb_env_t leveldb_env_t;
57
+ typedef struct leveldb_filelock_t leveldb_filelock_t;
58
+ typedef struct leveldb_filterpolicy_t leveldb_filterpolicy_t;
59
+ typedef struct leveldb_iterator_t leveldb_iterator_t;
60
+ typedef struct leveldb_logger_t leveldb_logger_t;
61
+ typedef struct leveldb_options_t leveldb_options_t;
62
+ typedef struct leveldb_randomfile_t leveldb_randomfile_t;
63
+ typedef struct leveldb_readoptions_t leveldb_readoptions_t;
64
+ typedef struct leveldb_seqfile_t leveldb_seqfile_t;
65
+ typedef struct leveldb_snapshot_t leveldb_snapshot_t;
66
+ typedef struct leveldb_writablefile_t leveldb_writablefile_t;
67
+ typedef struct leveldb_writebatch_t leveldb_writebatch_t;
68
+ typedef struct leveldb_writeoptions_t leveldb_writeoptions_t;
69
+
70
+ /* DB operations */
71
+
72
+ extern leveldb_t* leveldb_open(
73
+ const leveldb_options_t* options,
74
+ const char* name,
75
+ char** errptr);
76
+
77
+ extern void leveldb_close(leveldb_t* db);
78
+
79
+ extern void leveldb_put(
80
+ leveldb_t* db,
81
+ const leveldb_writeoptions_t* options,
82
+ const char* key, size_t keylen,
83
+ const char* val, size_t vallen,
84
+ char** errptr);
85
+
86
+ extern void leveldb_delete(
87
+ leveldb_t* db,
88
+ const leveldb_writeoptions_t* options,
89
+ const char* key, size_t keylen,
90
+ char** errptr);
91
+
92
+ extern void leveldb_write(
93
+ leveldb_t* db,
94
+ const leveldb_writeoptions_t* options,
95
+ leveldb_writebatch_t* batch,
96
+ char** errptr);
97
+
98
+ /* Returns NULL if not found. A malloc()ed array otherwise.
99
+ Stores the length of the array in *vallen. */
100
+ extern char* leveldb_get(
101
+ leveldb_t* db,
102
+ const leveldb_readoptions_t* options,
103
+ const char* key, size_t keylen,
104
+ size_t* vallen,
105
+ char** errptr);
106
+
107
+ extern leveldb_iterator_t* leveldb_create_iterator(
108
+ leveldb_t* db,
109
+ const leveldb_readoptions_t* options);
110
+
111
+ extern const leveldb_snapshot_t* leveldb_create_snapshot(
112
+ leveldb_t* db);
113
+
114
+ extern void leveldb_release_snapshot(
115
+ leveldb_t* db,
116
+ const leveldb_snapshot_t* snapshot);
117
+
118
+ /* Returns NULL if property name is unknown.
119
+ Else returns a pointer to a malloc()-ed null-terminated value. */
120
+ extern char* leveldb_property_value(
121
+ leveldb_t* db,
122
+ const char* propname);
123
+
124
+ extern void leveldb_approximate_sizes(
125
+ leveldb_t* db,
126
+ int num_ranges,
127
+ const char* const* range_start_key, const size_t* range_start_key_len,
128
+ const char* const* range_limit_key, const size_t* range_limit_key_len,
129
+ uint64_t* sizes);
130
+
131
+ extern void leveldb_compact_range(
132
+ leveldb_t* db,
133
+ const char* start_key, size_t start_key_len,
134
+ const char* limit_key, size_t limit_key_len);
135
+
136
+ /* Management operations */
137
+
138
+ extern void leveldb_destroy_db(
139
+ const leveldb_options_t* options,
140
+ const char* name,
141
+ char** errptr);
142
+
143
+ extern void leveldb_repair_db(
144
+ const leveldb_options_t* options,
145
+ const char* name,
146
+ char** errptr);
147
+
148
+ /* Iterator */
149
+
150
+ extern void leveldb_iter_destroy(leveldb_iterator_t*);
151
+ extern unsigned char leveldb_iter_valid(const leveldb_iterator_t*);
152
+ extern void leveldb_iter_seek_to_first(leveldb_iterator_t*);
153
+ extern void leveldb_iter_seek_to_last(leveldb_iterator_t*);
154
+ extern void leveldb_iter_seek(leveldb_iterator_t*, const char* k, size_t klen);
155
+ extern void leveldb_iter_next(leveldb_iterator_t*);
156
+ extern void leveldb_iter_prev(leveldb_iterator_t*);
157
+ extern const char* leveldb_iter_key(const leveldb_iterator_t*, size_t* klen);
158
+ extern const char* leveldb_iter_value(const leveldb_iterator_t*, size_t* vlen);
159
+ extern void leveldb_iter_get_error(const leveldb_iterator_t*, char** errptr);
160
+
161
+ /* Write batch */
162
+
163
+ extern leveldb_writebatch_t* leveldb_writebatch_create();
164
+ extern void leveldb_writebatch_destroy(leveldb_writebatch_t*);
165
+ extern void leveldb_writebatch_clear(leveldb_writebatch_t*);
166
+ extern void leveldb_writebatch_put(
167
+ leveldb_writebatch_t*,
168
+ const char* key, size_t klen,
169
+ const char* val, size_t vlen);
170
+ extern void leveldb_writebatch_delete(
171
+ leveldb_writebatch_t*,
172
+ const char* key, size_t klen);
173
+ extern void leveldb_writebatch_iterate(
174
+ leveldb_writebatch_t*,
175
+ void* state,
176
+ void (*put)(void*, const char* k, size_t klen, const char* v, size_t vlen),
177
+ void (*deleted)(void*, const char* k, size_t klen));
178
+
179
+ /* Options */
180
+
181
+ extern leveldb_options_t* leveldb_options_create();
182
+ extern void leveldb_options_destroy(leveldb_options_t*);
183
+ extern void leveldb_options_set_comparator(
184
+ leveldb_options_t*,
185
+ leveldb_comparator_t*);
186
+ extern void leveldb_options_set_filter_policy(
187
+ leveldb_options_t*,
188
+ leveldb_filterpolicy_t*);
189
+ extern void leveldb_options_set_create_if_missing(
190
+ leveldb_options_t*, unsigned char);
191
+ extern void leveldb_options_set_error_if_exists(
192
+ leveldb_options_t*, unsigned char);
193
+ extern void leveldb_options_set_paranoid_checks(
194
+ leveldb_options_t*, unsigned char);
195
+ extern void leveldb_options_set_env(leveldb_options_t*, leveldb_env_t*);
196
+ extern void leveldb_options_set_info_log(leveldb_options_t*, leveldb_logger_t*);
197
+ extern void leveldb_options_set_write_buffer_size(leveldb_options_t*, size_t);
198
+ extern void leveldb_options_set_max_open_files(leveldb_options_t*, int);
199
+ extern void leveldb_options_set_cache(leveldb_options_t*, leveldb_cache_t*);
200
+ extern void leveldb_options_set_block_size(leveldb_options_t*, size_t);
201
+ extern void leveldb_options_set_block_restart_interval(leveldb_options_t*, int);
202
+
203
+ enum {
204
+ leveldb_no_compression = 0,
205
+ leveldb_snappy_compression = 1
206
+ };
207
+ extern void leveldb_options_set_compression(leveldb_options_t*, int);
208
+
209
+ /* Comparator */
210
+
211
+ extern leveldb_comparator_t* leveldb_comparator_create(
212
+ void* state,
213
+ void (*destructor)(void*),
214
+ int (*compare)(
215
+ void*,
216
+ const char* a, size_t alen,
217
+ const char* b, size_t blen),
218
+ const char* (*name)(void*));
219
+ extern void leveldb_comparator_destroy(leveldb_comparator_t*);
220
+
221
+ /* Filter policy */
222
+
223
+ extern leveldb_filterpolicy_t* leveldb_filterpolicy_create(
224
+ void* state,
225
+ void (*destructor)(void*),
226
+ char* (*create_filter)(
227
+ void*,
228
+ const char* const* key_array, const size_t* key_length_array,
229
+ int num_keys,
230
+ size_t* filter_length),
231
+ unsigned char (*key_may_match)(
232
+ void*,
233
+ const char* key, size_t length,
234
+ const char* filter, size_t filter_length),
235
+ const char* (*name)(void*));
236
+ extern void leveldb_filterpolicy_destroy(leveldb_filterpolicy_t*);
237
+
238
+ extern leveldb_filterpolicy_t* leveldb_filterpolicy_create_bloom(
239
+ int bits_per_key);
240
+
241
+ /* Read options */
242
+
243
+ extern leveldb_readoptions_t* leveldb_readoptions_create();
244
+ extern void leveldb_readoptions_destroy(leveldb_readoptions_t*);
245
+ extern void leveldb_readoptions_set_verify_checksums(
246
+ leveldb_readoptions_t*,
247
+ unsigned char);
248
+ extern void leveldb_readoptions_set_fill_cache(
249
+ leveldb_readoptions_t*, unsigned char);
250
+ extern void leveldb_readoptions_set_snapshot(
251
+ leveldb_readoptions_t*,
252
+ const leveldb_snapshot_t*);
253
+
254
+ /* Write options */
255
+
256
+ extern leveldb_writeoptions_t* leveldb_writeoptions_create();
257
+ extern void leveldb_writeoptions_destroy(leveldb_writeoptions_t*);
258
+ extern void leveldb_writeoptions_set_sync(
259
+ leveldb_writeoptions_t*, unsigned char);
260
+
261
+ /* Cache */
262
+
263
+ extern leveldb_cache_t* leveldb_cache_create_lru(size_t capacity);
264
+ extern void leveldb_cache_destroy(leveldb_cache_t* cache);
265
+
266
+ /* Env */
267
+
268
+ extern leveldb_env_t* leveldb_create_default_env();
269
+ extern void leveldb_env_destroy(leveldb_env_t*);
270
+
271
+ #ifdef __cplusplus
272
+ } /* end extern "C" */
273
+ #endif
274
+
275
+ #endif /* STORAGE_LEVELDB_INCLUDE_C_H_ */