bitcoinleveldb_db/db.rs
1crate::ix!();
2
3//-------------------------------------------[.cpp/bitcoin/src/leveldb/include/leveldb/db.h]
4
5// Update CMakeLists.txt if you change these
6pub const MAJOR_VERSION: i32 = 1;
7pub const MINOR_VERSION: i32 = 22;
8
9
10/**
11 A range of keys
12 */
13#[derive(Default)]
14pub struct Range {
15
16 /**
17 Included in the range
18 */
19 start: Slice,
20
21 /**
22 Not included in the range
23 */
24 limit: Slice,
25}
26
27impl Range {
28
29 pub fn new(
30 s: &Slice,
31 l: &Slice) -> Self {
32
33 todo!();
34 /*
35 : start(s),
36 : limit(l),
37
38
39 */
40 }
41}
42
43/**
44 | A DB is a persistent ordered map from keys to
45 | values.
46 |
47 | A DB is safe for concurrent access from
48 | multiple threads without any external
49 | synchronization.
50 */
51pub trait DB:
52 Put
53 + Delete
54 + Write
55 + Get
56 + NewIterator
57 + GetSnapshot
58 + ReleaseSnapshot
59 + GetProperty
60 + GetApproximateSizes
61 + CompactRange {
62
63 /**
64 | Open the database with the specified "name".
65 |
66 | Stores a pointer to a heap-allocated database
67 | in *dbptr and returns OK on success.
68 |
69 | Stores nullptr in *dbptr and returns a non-OK
70 | status on error.
71 |
72 | Caller should delete *dbptr when it is no
73 | longer needed.
74 */
75 fn open(&mut self,
76 options: &Options,
77 dbname: &String,
78 dbptr: *mut *mut dyn DB) -> crate::Status {
79
80 todo!();
81 /*
82 *dbptr = nullptr;
83
84 DBImpl* impl = new DBImpl(options, dbname);
85 impl->mutex_.Lock();
86 VersionEdit edit;
87 // Recover handles create_if_missing, error_if_exists
88 bool save_manifest = false;
89 Status s = impl->Recover(&edit, &save_manifest);
90 if (s.ok() && impl->mem_ == nullptr) {
91 // Create new log and a corresponding memtable.
92 uint64_t new_log_number = impl->versions_->NewFileNumber();
93 WritableFile* lfile;
94 s = options.env->NewWritableFile(LogFileName(dbname, new_log_number),
95 &lfile);
96 if (s.ok()) {
97 edit.SetLogNumber(new_log_number);
98 impl->logfile_ = lfile;
99 impl->logfile_number_ = new_log_number;
100 impl->log_ = new LogWriter(lfile);
101 impl->mem_ = new MemTable(impl->internal_comparator_);
102 impl->mem_->Ref();
103 }
104 }
105 if (s.ok() && save_manifest) {
106 edit.SetPrevLogNumber(0); // No older logs needed after recovery.
107 edit.SetLogNumber(impl->logfile_number_);
108 s = impl->versions_->LogAndApply(&edit, &impl->mutex_);
109 }
110 if (s.ok()) {
111 impl->DeleteObsoleteFiles();
112 impl->MaybeScheduleCompaction();
113 }
114 impl->mutex_.Unlock();
115 if (s.ok()) {
116 assert(impl->mem_ != nullptr);
117 *dbptr = impl;
118 } else {
119 delete impl;
120 }
121 return s;
122 */
123 }
124}
125
126pub trait Put {
127
128 /**
129 | Set the database entry for "key" to "value".
130 | Returns OK on success, and a non-OK status on
131 | error.
132 |
133 | Note: consider setting options.sync = true.
134 |
135 | Default implementations of convenience
136 | methods that subclasses of DB can call
137 | if they wish
138 |
139 */
140 fn put(&mut self,
141 opt: &WriteOptions,
142 key_: &Slice,
143 value: &Slice) -> crate::Status {
144
145 todo!();
146 /*
147 WriteBatch batch;
148 batch.Put(key, value);
149 return Write(opt, &batch);
150 */
151 }
152}
153
154pub trait Delete {
155
156 /**
157 | Remove the database entry (if any) for "key".
158 | Returns OK on success, and a non-OK status on
159 | error. It is not an error if "key" did not
160 | exist in the database.
161 |
162 | Note: consider setting options.sync = true.
163 */
164 fn delete(&mut self,
165 opt: &WriteOptions,
166 key_: &Slice) -> crate::Status {
167
168 todo!();
169 /*
170 WriteBatch batch;
171 batch.Delete(key);
172 return Write(opt, &batch);
173 */
174 }
175}
176
177pub trait Write {
178
179 /**
180 | Apply the specified updates to the database.
181 |
182 | Returns OK on success, non-OK on failure.
183 |
184 | Note: consider setting options.sync = true.
185 */
186 fn write(&mut self,
187 options: &WriteOptions,
188 updates: *mut WriteBatch) -> crate::Status;
189}
190
191pub trait Get {
192
193 /**
194 | If the database contains an entry for "key"
195 | store the corresponding value in *value and
196 | return OK.
197 |
198 | If there is no entry for "key" leave *value
199 | unchanged and return a status for which
200 | Status::IsNotFound() returns true.
201 |
202 | May return some other Status on an error.
203 */
204 fn get(&mut self,
205 options: &ReadOptions,
206 key_: &Slice,
207 value: *mut String) -> crate::Status;
208}
209
210pub trait NewIterator {
211
212 /**
213 | Return a heap-allocated iterator over the
214 | contents of the database. The result of
215 | NewIterator() is initially invalid (caller
216 | must call one of the Seek methods on the
217 | iterator before using it).
218 |
219 | Caller should delete the iterator when it is
220 | no longer needed. The returned iterator
221 | should be deleted before this db is deleted.
222 */
223 fn new_iterator(&mut self, options: &ReadOptions) -> *mut LevelDBIterator;
224}
225
226pub trait GetSnapshot {
227
228 /**
229 | Return a handle to the current DB state.
230 | Iterators created with this handle will all
231 | observe a stable snapshot of the current DB
232 | state.
233 |
234 | The caller must call ReleaseSnapshot(result)
235 | when the snapshot is no longer needed.
236 */
237 fn get_snapshot(&mut self) -> Box<dyn Snapshot>;
238}
239
240pub trait ReleaseSnapshot {
241
242 /**
243 | Release a previously acquired snapshot.
244 | The caller must not use "snapshot" after
245 | this call.
246 |
247 */
248 fn release_snapshot(&mut self, snapshot: Box<dyn Snapshot>);
249}
250
251pub trait GetProperty {
252
253 /**
254 | DB implementations can export properties
255 | about their state via this method. If
256 | "property" is a valid property understood by
257 | this DB implementation, fills "*value" with
258 | its current value and returns true.
259 | Otherwise returns false.
260 |
261 |
262 | Valid property names include:
263 |
264 | "leveldb.num-files-at-level<N>" - return the
265 | number of files at level <N>, where <N>
266 | is an ASCII representation of a level
267 | number (e.g. "0").
268 |
269 | "leveldb.stats" - returns a multi-line
270 | string that describes statistics about
271 | the internal operation of the DB.
272 |
273 | "leveldb.sstables" - returns a multi-line
274 | string that describes all of the sstables
275 | that make up the db contents.
276 |
277 | "leveldb.approximate-memory-usage" - returns
278 | the approximate number of bytes of memory
279 | in use by the DB.
280 */
281 fn get_property(&mut self,
282 property: &str,
283 value: *mut String) -> bool;
284}
285
286pub trait GetApproximateSizes {
287
288 /**
289 | For each i in [0,n-1], store in "sizes[i]",
290 | the approximate file system space used by
291 | keys in "[range[i].start .. range[i].limit)".
292 |
293 | Note that the returned sizes measure file
294 | system space usage, so if the user data
295 | compresses by a factor of ten, the returned
296 | sizes will be one-tenth the size of the
297 | corresponding user data size.
298 |
299 | The results may not include the sizes of
300 | recently written data.
301 */
302 fn get_approximate_sizes(&mut self,
303 range: *const Range,
304 n: i32,
305 sizes: *mut u64);
306}
307
308pub trait CompactRange {
309
310 /**
311 | Compact the underlying storage for the key
312 | range [*begin,*end]. In particular, deleted
313 | and overwritten versions are discarded, and
314 | the data is rearranged to reduce the cost of
315 | operations needed to access the data. This
316 | operation should typically only be invoked by
317 | users who understand the underlying
318 | implementation.
319 |
320 | begin==nullptr is treated as a key before all
321 | keys in the database. end==nullptr is
322 | treated as a key after all keys in the
323 | database. Therefore the following call will
324 | compact the entire database:
325 | db->CompactRange(nullptr, nullptr);
326 */
327 fn compact_range(&mut self,
328 begin: *const Slice,
329 end: *const Slice);
330}
331
332/**
333 | Destroy the contents of the specified database.
334 | Be very careful using this method.
335 |
336 | Note: For backwards compatibility, if DestroyDB
337 | is unable to list the database files,
338 | Status::OK() will still be returned masking
339 | this failure.
340 */
341pub fn destroydb(
342 name: &String,
343 options: &Options) -> crate::Status {
344
345 todo!();
346 /*
347
348 */
349}
350
351/**
352 | If a DB cannot be opened, you may attempt to
353 | call this method to resurrect as much of the
354 | contents of the database as possible.
355 |
356 | Some data may be lost, so be careful when
357 | calling this function on a database that
358 | contains important information.
359 */
360pub fn repairdb(
361 dbname: &String,
362 options: &Options) -> crate::Status {
363
364 todo!();
365 /*
366
367 */
368}
369
370//-------------------------------------------[.cpp/bitcoin/src/leveldb/db/c.cc]
371
372pub struct LevelDB {
373 rep: Rc<RefCell<dyn DB>>,
374}
375
376pub struct LevelDBWriteBatch {
377 rep: WriteBatch,
378}
379
380pub struct LevelDBSnapshot {
381 rep: Rc<dyn Snapshot>,
382}
383
384pub struct LevelDBReadOptions {
385 rep: ReadOptions,
386}
387
388pub struct LevelDBWriteOptions {
389 rep: WriteOptions,
390}
391
392pub struct LevelDBOptions {
393 rep: Options,
394}
395
396pub struct LevelDBCache {
397 rep: Rc<RefCell<crate::Cache>>,
398}
399
400pub struct LevelDBSeqFile {
401 rep: Rc<RefCell<dyn SequentialFile>>,
402}
403
404pub struct LevelDBRandomFile {
405 rep: Rc<RefCell<dyn RandomAccessFile>>,
406}
407
408pub struct LevelDBWritableFile {
409 rep: Rc<RefCell<dyn WritableFile>>,
410}
411
412pub struct LevelDBLogger {
413 rep: Rc<RefCell<dyn Logger>>,
414}
415
416pub struct LevelDBFileLock {
417 rep: Rc<RefCell<Box<dyn FileLock>>>,
418}
419
420///-----------------
421pub struct LevelDBComparator {
422
423 state: *mut c_void,
424
425 destructor: fn(_0: *mut c_void) -> c_void,
426
427 compare: fn(
428 _0: *mut c_void,
429 a: *const u8,
430 alen: usize,
431 b: *const u8,
432 blen: usize
433 ) -> i32,
434
435 name: fn(_0: *mut c_void) -> *const u8,
436}
437
438impl Comparator<Slice> for LevelDBComparator {
439 fn compare(&self,
440 a: &Slice,
441 b: &Slice) -> Ordering {
442
443 todo!();
444 /*
445 return (*compare_)(state_, a.data(), a.size(), b.data(), b.size());
446 */
447 }
448}
449
450impl FindShortestSeparator for LevelDBComparator {
451
452 /**
453 | No-ops since the C binding does not support
454 | key shortening methods.
455 |
456 */
457 fn find_shortest_separator(&self,
458 _0: *mut String,
459 _1: &Slice) {
460
461 todo!();
462 /*
463
464 */
465 }
466}
467
468impl FindShortSuccessor for LevelDBComparator {
469 fn find_short_successor(&self, key_: *mut String) {
470
471 todo!();
472 /*
473
474 */
475 }
476}
477
478impl Drop for LevelDBComparator {
479 fn drop(&mut self) {
480 todo!();
481 /*
482 (*destructor_)(state_);
483 */
484 }
485}
486
487impl Name for LevelDBComparator {
488
489 fn name(&self) -> *const u8 {
490
491 todo!();
492 /*
493 return (*name_)(state_);
494 */
495 }
496}
497
498///-----------------
499pub struct LevelDBFilterPolicy {
500 state: *mut c_void,
501
502 destructor: fn(_0: *mut c_void) -> c_void,
503
504 name: fn(_0: *mut c_void) -> *const u8,
505
506 create: fn(
507 _0: *mut c_void,
508 key_array: *const *const u8,
509 key_length_array: *const usize,
510 num_keys: i32,
511 filter_length: *mut usize
512 ) -> *mut u8,
513
514 key_match: fn(
515 _0: *mut c_void,
516 key_: *const u8,
517 length: usize,
518 filter: *const u8,
519 filter_length: usize
520 ) -> u8,
521}
522
523impl FilterPolicy for LevelDBFilterPolicy {
524
525}
526
527impl Drop for LevelDBFilterPolicy {
528 fn drop(&mut self) {
529 todo!();
530 /*
531 (*destructor_)(state_);
532 */
533 }
534}
535
536impl Name for LevelDBFilterPolicy {
537 fn name(&self) -> *const u8 {
538
539 todo!();
540 /*
541 return (*name_)(state_);
542 */
543 }
544}
545
546impl CreateFilter for LevelDBFilterPolicy {
547 fn create_filter(&self,
548 keys: *const Slice,
549 n: i32,
550 dst: *mut String) {
551
552 todo!();
553 /*
554 std::vector<const char*> key_pointers(n);
555 std::vector<size_t> key_sizes(n);
556 for (int i = 0; i < n; i++) {
557 key_pointers[i] = keys[i].data();
558 key_sizes[i] = keys[i].size();
559 }
560 size_t len;
561 char* filter = (*create_)(state_, &key_pointers[0], &key_sizes[0], n, &len);
562 dst->append(filter, len);
563 free(filter);
564 */
565 }
566}
567
568impl KeyMayMatch for LevelDBFilterPolicy {
569 fn key_may_match(&self,
570 key_: &Slice,
571 filter: &Slice) -> bool {
572
573 todo!();
574 /*
575 return (*key_match_)(state_, key.data(), key.size(), filter.data(),
576 filter.size());
577 */
578 }
579}
580
581///-----------------
582pub struct LevelDBEnv {
583 rep: Rc<RefCell<dyn Env>>,
584 is_default: bool,
585}
586
587pub fn save_error(
588 errptr: *mut *mut u8,
589 s: &Status) -> bool {
590
591 todo!();
592 /*
593 assert(errptr != nullptr);
594 if (s.ok()) {
595 return false;
596 } else if (*errptr == nullptr) {
597 *errptr = strdup(s.ToString().c_str());
598 } else {
599 // TODO(sanjay): Merge with existing error?
600 free(*errptr);
601 *errptr = strdup(s.ToString().c_str());
602 }
603 return true;
604 */
605}
606
607pub fn copy_string(str_: &String) -> *mut u8 {
608
609 todo!();
610 /*
611 char* result = reinterpret_cast<char*>(malloc(sizeof(char) * str.size()));
612 memcpy(result, str.data(), sizeof(char) * str.size());
613 return result;
614 */
615}
616
617pub fn leveldb_open(
618 options: *const LevelDBOptions,
619 name: *const u8,
620 errptr: *mut *mut u8) -> *mut LevelDB {
621
622 todo!();
623 /*
624 DB* db;
625 if (SaveError(errptr, DB::Open(options->rep, std::string(name), &db))) {
626 return nullptr;
627 }
628 leveldb_t* result = new leveldb_t;
629 result->rep = db;
630 return result;
631 */
632}
633
634pub fn leveldb_close(db: *mut LevelDB) {
635
636 todo!();
637 /*
638 delete db->rep;
639 delete db;
640 */
641}
642
643pub fn leveldb_put(
644 db: *mut LevelDB,
645 options: *const LevelDBWriteOptions,
646 key_: *const u8,
647 keylen: usize,
648 val: *const u8,
649 vallen: usize,
650 errptr: *mut *mut u8) {
651
652 todo!();
653 /*
654 SaveError(errptr,
655 db->rep->Put(options->rep, Slice(key, keylen), Slice(val, vallen)));
656 */
657}
658
659pub fn leveldb_delete(
660 db: *mut LevelDB,
661 options: *const LevelDBWriteOptions,
662 key_: *const u8,
663 keylen: usize,
664 errptr: *mut *mut u8) {
665
666 todo!();
667 /*
668 SaveError(errptr, db->rep->Delete(options->rep, Slice(key, keylen)));
669 */
670}
671
672pub fn leveldb_write(
673 db: *mut LevelDB,
674 options: *const LevelDBWriteOptions,
675 batch: *mut LevelDBWriteBatch,
676 errptr: *mut *mut u8) {
677
678 todo!();
679 /*
680 SaveError(errptr, db->rep->Write(options->rep, &batch->rep));
681 */
682}
683
684pub fn leveldb_get(
685 db: *mut LevelDB,
686 options: *const LevelDBReadOptions,
687 key_: *const u8,
688 keylen: usize,
689 vallen: *mut usize,
690 errptr: *mut *mut u8) -> *mut u8 {
691
692 todo!();
693 /*
694 char* result = nullptr;
695 std::string tmp;
696 Status s = db->rep->Get(options->rep, Slice(key, keylen), &tmp);
697 if (s.ok()) {
698 *vallen = tmp.size();
699 result = CopyString(tmp);
700 } else {
701 *vallen = 0;
702 if (!s.IsNotFound()) {
703 SaveError(errptr, s);
704 }
705 }
706 return result;
707 */
708}
709
710pub fn leveldb_create_iterator(
711 db: *mut LevelDB,
712 options: *const LevelDBReadOptions) -> *mut LevelDBIterator {
713
714 todo!();
715 /*
716 leveldb_iterator_t* result = new leveldb_iterator_t;
717 result->rep = db->rep->NewIterator(options->rep);
718 return result;
719 */
720}
721
722pub fn leveldb_create_snapshot(db: *mut LevelDB) -> *const LevelDBSnapshot {
723
724 todo!();
725 /*
726 leveldb_snapshot_t* result = new leveldb_snapshot_t;
727 result->rep = db->rep->GetSnapshot();
728 return result;
729 */
730}
731
732pub fn leveldb_release_snapshot(
733 db: *mut LevelDB,
734 snapshot: *const LevelDBSnapshot) {
735
736 todo!();
737 /*
738 db->rep->ReleaseSnapshot(snapshot->rep);
739 delete snapshot;
740 */
741}
742
743pub fn leveldb_property_value(
744 db: *mut LevelDB,
745 propname: *const u8) -> *mut u8 {
746
747 todo!();
748 /*
749 std::string tmp;
750 if (db->rep->GetProperty(Slice(propname), &tmp)) {
751 // We use strdup() since we expect human readable output.
752 return strdup(tmp.c_str());
753 } else {
754 return nullptr;
755 }
756 */
757}
758
759pub fn leveldb_approximate_sizes(
760 db: *mut LevelDB,
761 num_ranges: i32,
762 range_start_key_: *const *const u8,
763 range_start_key_len: *const usize,
764 range_limit_key_: *const *const u8,
765 range_limit_key_len: *const usize,
766 sizes: *mut u64) {
767
768 todo!();
769 /*
770 Range* ranges = new Range[num_ranges];
771 for (int i = 0; i < num_ranges; i++) {
772 ranges[i].start = Slice(range_start_key[i], range_start_key_len[i]);
773 ranges[i].limit = Slice(range_limit_key[i], range_limit_key_len[i]);
774 }
775 db->rep->GetApproximateSizes(ranges, num_ranges, sizes);
776 delete[] ranges;
777 */
778}
779
780pub fn leveldb_compact_range(
781 db: *mut LevelDB,
782 start_key_: *const u8,
783 start_key_len: usize,
784 limit_key_: *const u8,
785 limit_key_len: usize) {
786
787 todo!();
788 /*
789 Slice a, b;
790 db->rep->CompactRange(
791 // Pass null Slice if corresponding "const char*" is null
792 (start_key ? (a = Slice(start_key, start_key_len), &a) : nullptr),
793 (limit_key ? (b = Slice(limit_key, limit_key_len), &b) : nullptr));
794 */
795}
796
797pub fn leveldb_destroy_db(
798 options: *const LevelDBOptions,
799 name: *const u8,
800 errptr: *mut *mut u8) {
801
802 todo!();
803 /*
804 SaveError(errptr, DestroyDB(name, options->rep));
805 */
806}
807
808pub fn leveldb_repair_db(
809 options: *const LevelDBOptions,
810 name: *const u8,
811 errptr: *mut *mut u8) {
812
813 todo!();
814 /*
815 SaveError(errptr, RepairDB(name, options->rep));
816 */
817}
818
819pub fn leveldb_iter_destroy(iter: *mut LevelDBIterator) {
820
821 todo!();
822 /*
823 delete iter->rep;
824 delete iter;
825 */
826}
827
828pub fn leveldb_iter_valid(iter: *const LevelDBIterator) -> u8 {
829
830 todo!();
831 /*
832 return iter->rep->Valid();
833 */
834}
835
836pub fn leveldb_iter_seek_to_first(iter: *mut LevelDBIterator) {
837
838 todo!();
839 /*
840 iter->rep->SeekToFirst();
841 */
842}
843
844pub fn leveldb_iter_seek_to_last(iter: *mut LevelDBIterator) {
845
846 todo!();
847 /*
848 iter->rep->SeekToLast();
849 */
850}
851
852pub fn leveldb_iter_seek(
853 iter: *mut LevelDBIterator,
854 k: *const u8,
855 klen: usize) {
856
857 todo!();
858 /*
859 iter->rep->Seek(Slice(k, klen));
860 */
861}
862
863pub fn leveldb_iter_next(iter: *mut LevelDBIterator) {
864
865 todo!();
866 /*
867 iter->rep->Next();
868 */
869}
870
871pub fn leveldb_iter_prev(iter: *mut LevelDBIterator) {
872
873 todo!();
874 /*
875 iter->rep->Prev();
876 */
877}
878
879pub fn leveldb_iter_key(
880 iter: *const LevelDBIterator,
881 klen: *mut usize) -> *const u8 {
882
883 todo!();
884 /*
885 Slice s = iter->rep->key();
886 *klen = s.size();
887 return s.data();
888 */
889}
890
891pub fn leveldb_iter_value(
892 iter: *const LevelDBIterator,
893 vlen: *mut usize) -> *const u8 {
894
895 todo!();
896 /*
897 Slice s = iter->rep->value();
898 *vlen = s.size();
899 return s.data();
900 */
901}
902
903pub fn leveldb_iter_get_error(
904 iter: *const LevelDBIterator,
905 errptr: *mut *mut u8) {
906
907 todo!();
908 /*
909 SaveError(errptr, iter->rep->status());
910 */
911}
912
913pub fn leveldb_writebatch_create() -> *mut LevelDBWriteBatch {
914
915 todo!();
916 /*
917 return new leveldb_writebatch_t;
918 */
919}
920
921pub fn leveldb_writebatch_destroy(b: *mut LevelDBWriteBatch) {
922
923 todo!();
924 /*
925 delete b;
926 */
927}
928
929pub fn leveldb_writebatch_clear(b: *mut LevelDBWriteBatch) {
930
931 todo!();
932 /*
933 b->rep.Clear();
934 */
935}
936
937pub fn leveldb_writebatch_put(
938 b: *mut LevelDBWriteBatch,
939 key_: *const u8,
940 klen: usize,
941 val: *const u8,
942 vlen: usize) {
943
944 todo!();
945 /*
946 b->rep.Put(Slice(key, klen), Slice(val, vlen));
947 */
948}
949
950pub fn leveldb_writebatch_delete(
951 b: *mut LevelDBWriteBatch,
952 key_: *const u8,
953 klen: usize) {
954
955 todo!();
956 /*
957 b->rep.Delete(Slice(key, klen));
958 */
959}
960
961pub fn leveldb_writebatch_iterate(
962 b: *const LevelDBWriteBatch,
963 state: *mut c_void,
964 put: fn(
965 _0: *mut c_void,
966 k: *const u8,
967 klen: usize,
968 v: *const u8,
969 vlen: usize
970 ) -> c_void,
971 deleted: fn(
972 _0: *mut c_void,
973 k: *const u8,
974 klen: usize
975 ) -> c_void) {
976
977 todo!();
978 /*
979 class H : public WriteBatch::Handler {
980
981 c_void* state_;
982 c_void (*put_)(c_void*, const char* k, size_t klen, const char* v, size_t vlen);
983 c_void (*deleted_)(c_void*, const char* k, size_t klen);
984 c_void Put(const Slice& key, const Slice& value) override {
985 (*put_)(state_, key.data(), key.size(), value.data(), value.size());
986 }
987 c_void Delete(const Slice& key) override {
988 (*deleted_)(state_, key.data(), key.size());
989 }
990 };
991 H handler;
992 handler.state_ = state;
993 handler.put_ = put;
994 handler.deleted_ = deleted;
995 b->rep.Iterate(&handler);
996 */
997}
998
999pub fn leveldb_writebatch_append(
1000 destination: *mut LevelDBWriteBatch,
1001 source: *const LevelDBWriteBatch) {
1002
1003 todo!();
1004 /*
1005 destination->rep.Append(source->rep);
1006 */
1007}
1008
1009pub fn leveldb_options_create() -> *mut LevelDBOptions {
1010
1011 todo!();
1012 /*
1013 return new leveldb_options_t;
1014 */
1015}
1016
1017pub fn leveldb_options_destroy(options: *mut LevelDBOptions) {
1018
1019 todo!();
1020 /*
1021 delete options;
1022 */
1023}
1024
1025pub fn leveldb_options_set_comparator(
1026 opt: *mut LevelDBOptions,
1027 cmp: *mut LevelDBComparator) {
1028
1029 todo!();
1030 /*
1031 opt->rep.comparator = cmp;
1032 */
1033}
1034
1035pub fn leveldb_options_set_filter_policy(
1036 opt: *mut LevelDBOptions,
1037 policy: *mut LevelDBFilterPolicy) {
1038
1039 todo!();
1040 /*
1041 opt->rep.filter_policy = policy;
1042 */
1043}
1044
1045pub fn leveldb_options_set_create_if_missing(
1046 opt: *mut LevelDBOptions,
1047 v: u8) {
1048
1049 todo!();
1050 /*
1051 opt->rep.create_if_missing = v;
1052 */
1053}
1054
1055pub fn leveldb_options_set_error_if_exists(
1056 opt: *mut LevelDBOptions,
1057 v: u8) {
1058
1059 todo!();
1060 /*
1061 opt->rep.error_if_exists = v;
1062 */
1063}
1064
1065pub fn leveldb_options_set_paranoid_checks(
1066 opt: *mut LevelDBOptions,
1067 v: u8) {
1068
1069 todo!();
1070 /*
1071 opt->rep.paranoid_checks = v;
1072 */
1073}
1074
1075pub fn leveldb_options_set_env(
1076 opt: *mut LevelDBOptions,
1077 env: *mut LevelDBEnv) {
1078
1079 todo!();
1080 /*
1081 opt->rep.env = (env ? env->rep : nullptr);
1082 */
1083}
1084
1085pub fn leveldb_options_set_info_log(
1086 opt: *mut LevelDBOptions,
1087 l: *mut LevelDBLogger) {
1088
1089 todo!();
1090 /*
1091 opt->rep.info_log = (l ? l->rep : nullptr);
1092 */
1093}
1094
1095pub fn leveldb_options_set_write_buffer_size(
1096 opt: *mut LevelDBOptions,
1097 s: usize) {
1098
1099 todo!();
1100 /*
1101 opt->rep.write_buffer_size = s;
1102 */
1103}
1104
1105pub fn leveldb_options_set_max_open_files(
1106 opt: *mut LevelDBOptions,
1107 n: i32) {
1108
1109 todo!();
1110 /*
1111 opt->rep.max_open_files = n;
1112 */
1113}
1114
1115pub fn leveldb_options_set_cache(
1116 opt: *mut LevelDBOptions,
1117 c: *mut LevelDBCache) {
1118
1119 todo!();
1120 /*
1121 opt->rep.block_cache = c->rep;
1122 */
1123}
1124
1125pub fn leveldb_options_set_block_size(
1126 opt: *mut LevelDBOptions,
1127 s: usize) {
1128
1129 todo!();
1130 /*
1131 opt->rep.block_size = s;
1132 */
1133}
1134
1135pub fn leveldb_options_set_block_restart_interval(
1136 opt: *mut LevelDBOptions,
1137 n: i32) {
1138
1139 todo!();
1140 /*
1141 opt->rep.block_restart_interval = n;
1142 */
1143}
1144
1145pub fn leveldb_options_set_max_file_size(
1146 opt: *mut LevelDBOptions,
1147 s: usize) {
1148
1149 todo!();
1150 /*
1151 opt->rep.max_file_size = s;
1152 */
1153}
1154
1155pub fn leveldb_options_set_compression(
1156 opt: *mut LevelDBOptions,
1157 t: i32) {
1158
1159 todo!();
1160 /*
1161 opt->rep.compression = static_cast<CompressionType>(t);
1162 */
1163}
1164
1165pub fn leveldb_comparator_create(
1166 state: *mut c_void,
1167 destructor: fn(_0: *mut c_void) -> c_void,
1168 compare: fn(
1169 _0: *mut c_void,
1170 a: *const u8,
1171 alen: usize,
1172 b: *const u8,
1173 blen: usize
1174 ) -> i32,
1175 name: fn(_0: *mut c_void) -> *const u8) -> *mut LevelDBComparator {
1176
1177 todo!();
1178 /*
1179 leveldb_comparator_t* result = new leveldb_comparator_t;
1180 result->state_ = state;
1181 result->destructor_ = destructor;
1182 result->compare_ = compare;
1183 result->name_ = name;
1184 return result;
1185 */
1186}
1187
1188pub fn leveldb_comparator_destroy(cmp: *mut LevelDBComparator) {
1189
1190 todo!();
1191 /*
1192 delete cmp;
1193 */
1194}
1195
1196pub fn leveldb_filterpolicy_create(
1197 state: *mut c_void,
1198 destructor: fn(_0: *mut c_void) -> c_void,
1199 create_filter: fn(
1200 _0: *mut c_void,
1201 key_array: *const *const u8,
1202 key_length_array: *const usize,
1203 num_keys: i32,
1204 filter_length: *mut usize
1205 ) -> *mut u8,
1206 key_may_match: fn(
1207 _0: *mut c_void,
1208 key_: *const u8,
1209 length: usize,
1210 filter: *const u8,
1211 filter_length: usize
1212 ) -> u8,
1213 name: fn(_0: *mut c_void) -> *mut u8) -> *mut LevelDBFilterPolicy {
1214
1215 todo!();
1216 /*
1217 leveldb_filterpolicy_t* result = new leveldb_filterpolicy_t;
1218 result->state_ = state;
1219 result->destructor_ = destructor;
1220 result->create_ = create_filter;
1221 result->key_match_ = key_may_match;
1222 result->name_ = name;
1223 return result;
1224 */
1225}
1226
1227pub fn leveldb_filterpolicy_destroy(filter: *mut LevelDBFilterPolicy) {
1228
1229 todo!();
1230 /*
1231 delete filter;
1232 */
1233}
1234
1235pub fn leveldb_filterpolicy_create_bloom(bits_per_key_: i32) -> *mut LevelDBFilterPolicy {
1236
1237 todo!();
1238 /*
1239 // Make a leveldb_filterpolicy_t, but override all of its methods so
1240 // they delegate to a NewBloomFilterPolicy() instead of user
1241 // supplied C functions.
1242 struct Wrapper : public leveldb_filterpolicy_t {
1243 static c_void DoNothing(c_void*) {}
1244
1245 ~Wrapper() { delete rep_; }
1246 const char* Name() const { return rep_->Name(); }
1247 c_void CreateFilter(const Slice* keys, int n, std::string* dst) const {
1248 return rep_->CreateFilter(keys, n, dst);
1249 }
1250 bool KeyMayMatch(const Slice& key, const Slice& filter) const {
1251 return rep_->KeyMayMatch(key, filter);
1252 }
1253
1254 const FilterPolicy* rep_;
1255 };
1256 Wrapper* wrapper = new Wrapper;
1257 wrapper->rep_ = NewBloomFilterPolicy(bits_per_key);
1258 wrapper->state_ = nullptr;
1259 wrapper->destructor_ = &Wrapper::DoNothing;
1260 return wrapper;
1261 */
1262}
1263
1264pub fn leveldb_readoptions_create() -> *mut LevelDBReadOptions {
1265
1266 todo!();
1267 /*
1268 return new leveldb_readoptions_t;
1269 */
1270}
1271
1272pub fn leveldb_readoptions_destroy(opt: *mut LevelDBReadOptions) {
1273
1274 todo!();
1275 /*
1276 delete opt;
1277 */
1278}
1279
1280pub fn leveldb_readoptions_set_verify_checksums(
1281 opt: *mut LevelDBReadOptions,
1282 v: u8) {
1283
1284 todo!();
1285 /*
1286 opt->rep.verify_checksums = v;
1287 */
1288}
1289
1290pub fn leveldb_readoptions_set_fill_cache(
1291 opt: *mut LevelDBReadOptions,
1292 v: u8) {
1293
1294 todo!();
1295 /*
1296 opt->rep.fill_cache = v;
1297 */
1298}
1299
1300pub fn leveldb_readoptions_set_snapshot(
1301 opt: *mut LevelDBReadOptions,
1302 snap: *const LevelDBSnapshot) {
1303
1304 todo!();
1305 /*
1306 opt->rep.snapshot = (snap ? snap->rep : nullptr);
1307 */
1308}
1309
1310pub fn leveldb_writeoptions_create() -> *mut LevelDBWriteOptions {
1311
1312 todo!();
1313 /*
1314 return new leveldb_writeoptions_t;
1315 */
1316}
1317
1318pub fn leveldb_writeoptions_destroy(opt: *mut LevelDBWriteOptions) {
1319
1320 todo!();
1321 /*
1322 delete opt;
1323 */
1324}
1325
1326pub fn leveldb_writeoptions_set_sync(
1327 opt: *mut LevelDBWriteOptions,
1328 v: u8) {
1329
1330 todo!();
1331 /*
1332 opt->rep.sync = v;
1333 */
1334}
1335
1336pub fn leveldb_cache_create_lru(capacity: usize) -> *mut LevelDBCache {
1337
1338 todo!();
1339 /*
1340 leveldb_cache_t* c = new leveldb_cache_t;
1341 c->rep = NewLRUCache(capacity);
1342 return c;
1343 */
1344}
1345
1346pub fn leveldb_cache_destroy(cache: *mut LevelDBCache) {
1347
1348 todo!();
1349 /*
1350 delete cache->rep;
1351 delete cache;
1352 */
1353}
1354
1355pub fn leveldb_create_default_env() -> *mut LevelDBEnv {
1356
1357 todo!();
1358 /*
1359 leveldb_env_t* result = new leveldb_env_t;
1360 result->rep = Env::Default();
1361 result->is_default = true;
1362 return result;
1363 */
1364}
1365
1366pub fn leveldb_env_destroy(env: *mut LevelDBEnv) {
1367
1368 todo!();
1369 /*
1370 if (!env->is_default) delete env->rep;
1371 delete env;
1372 */
1373}
1374
1375pub fn leveldb_env_get_test_directory(env: *mut LevelDBEnv) -> *mut u8 {
1376
1377 todo!();
1378 /*
1379 std::string result;
1380 if (!env->rep->GetTestDirectory(&result).ok()) {
1381 return nullptr;
1382 }
1383
1384 char* buffer = static_cast<char*>(malloc(result.size() + 1));
1385 memcpy(buffer, result.data(), result.size());
1386 buffer[result.size()] = '\0';
1387 return buffer;
1388 */
1389}
1390
1391pub fn leveldb_free(ptr: *mut c_void) {
1392
1393 todo!();
1394 /*
1395 free(ptr);
1396 */
1397}
1398
1399pub fn leveldb_major_version() -> i32 {
1400
1401 todo!();
1402 /*
1403 return kMajorVersion;
1404 */
1405}
1406
1407pub fn leveldb_minor_version() -> i32 {
1408
1409 todo!();
1410 /*
1411 return kMinorVersion;
1412 */
1413}