-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdif1
1988 lines (1987 loc) · 70 KB
/
dif1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
diff --git a/Makefile b/Makefile
index 776d6be..3b08998 100644
--- a/Makefile
+++ b/Makefile
@@ -1,6 +1,6 @@
PROJECT := lamebtc
VERSION := $(shell cat .semver)
-COMPILER := g++-6
+COMPILER := g++
INCLUDE_FOLDERS := $(wildcard lib/*/include)
INCLUDE_FLAGS := $(foreach folder,$(INCLUDE_FOLDERS),-I$(folder))
diff --git a/install_dependencies.sh b/install_dependencies.sh
new file mode 100644
index 0000000..72eba49
--- /dev/null
+++ b/install_dependencies.sh
@@ -0,0 +1,13 @@
+#!/usr/bin/env bash
+apt-get install libsnappy-dev -y
+export VER="1.20"
+wget https://github.com/google/leveldb/archive/v${VER}.tar.gz
+tar xvf v${VER}.tar.gz
+rm -f v${VER}.tar.gz
+cd leveldb-${VER}
+make
+scp -r out-static/lib* out-shared/lib* "/usr/local/lib"
+cd include
+scp -r leveldb /usr/local/include
+ldconfig
+rm -rf leveldb-${VER}
diff --git a/lib/leveldb/include/c.h b/lib/leveldb/include/c.h
deleted file mode 100644
index 1048fe3..0000000
--- a/lib/leveldb/include/c.h
+++ /dev/null
@@ -1,290 +0,0 @@
-/* Copyright (c) 2011 The LevelDB Authors. All rights reserved.
- Use of this source code is governed by a BSD-style license that can be
- found in the LICENSE file. See the AUTHORS file for names of contributors.
-
- C bindings for leveldb. May be useful as a stable ABI that can be
- used by programs that keep leveldb in a shared library, or for
- a JNI api.
-
- Does not support:
- . getters for the option types
- . custom comparators that implement key shortening
- . custom iter, db, env, cache implementations using just the C bindings
-
- Some conventions:
-
- (1) We expose just opaque struct pointers and functions to clients.
- This allows us to change internal representations without having to
- recompile clients.
-
- (2) For simplicity, there is no equivalent to the Slice type. Instead,
- the caller has to pass the pointer and length as separate
- arguments.
-
- (3) Errors are represented by a null-terminated c string. NULL
- means no error. All operations that can raise an error are passed
- a "char** errptr" as the last argument. One of the following must
- be true on entry:
- *errptr == NULL
- *errptr points to a malloc()ed null-terminated error message
- (On Windows, *errptr must have been malloc()-ed by this library.)
- On success, a leveldb routine leaves *errptr unchanged.
- On failure, leveldb frees the old value of *errptr and
- set *errptr to a malloc()ed error message.
-
- (4) Bools have the type unsigned char (0 == false; rest == true)
-
- (5) All of the pointer arguments must be non-NULL.
-*/
-
-#ifndef STORAGE_LEVELDB_INCLUDE_C_H_
-#define STORAGE_LEVELDB_INCLUDE_C_H_
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#include <stdarg.h>
-#include <stddef.h>
-#include <stdint.h>
-
-/* Exported types */
-
-typedef struct leveldb_t leveldb_t;
-typedef struct leveldb_cache_t leveldb_cache_t;
-typedef struct leveldb_comparator_t leveldb_comparator_t;
-typedef struct leveldb_env_t leveldb_env_t;
-typedef struct leveldb_filelock_t leveldb_filelock_t;
-typedef struct leveldb_filterpolicy_t leveldb_filterpolicy_t;
-typedef struct leveldb_iterator_t leveldb_iterator_t;
-typedef struct leveldb_logger_t leveldb_logger_t;
-typedef struct leveldb_options_t leveldb_options_t;
-typedef struct leveldb_randomfile_t leveldb_randomfile_t;
-typedef struct leveldb_readoptions_t leveldb_readoptions_t;
-typedef struct leveldb_seqfile_t leveldb_seqfile_t;
-typedef struct leveldb_snapshot_t leveldb_snapshot_t;
-typedef struct leveldb_writablefile_t leveldb_writablefile_t;
-typedef struct leveldb_writebatch_t leveldb_writebatch_t;
-typedef struct leveldb_writeoptions_t leveldb_writeoptions_t;
-
-/* DB operations */
-
-extern leveldb_t* leveldb_open(
- const leveldb_options_t* options,
- const char* name,
- char** errptr);
-
-extern void leveldb_close(leveldb_t* db);
-
-extern void leveldb_put(
- leveldb_t* db,
- const leveldb_writeoptions_t* options,
- const char* key, size_t keylen,
- const char* val, size_t vallen,
- char** errptr);
-
-extern void leveldb_delete(
- leveldb_t* db,
- const leveldb_writeoptions_t* options,
- const char* key, size_t keylen,
- char** errptr);
-
-extern void leveldb_write(
- leveldb_t* db,
- const leveldb_writeoptions_t* options,
- leveldb_writebatch_t* batch,
- char** errptr);
-
-/* Returns NULL if not found. A malloc()ed array otherwise.
- Stores the length of the array in *vallen. */
-extern char* leveldb_get(
- leveldb_t* db,
- const leveldb_readoptions_t* options,
- const char* key, size_t keylen,
- size_t* vallen,
- char** errptr);
-
-extern leveldb_iterator_t* leveldb_create_iterator(
- leveldb_t* db,
- const leveldb_readoptions_t* options);
-
-extern const leveldb_snapshot_t* leveldb_create_snapshot(
- leveldb_t* db);
-
-extern void leveldb_release_snapshot(
- leveldb_t* db,
- const leveldb_snapshot_t* snapshot);
-
-/* Returns NULL if property name is unknown.
- Else returns a pointer to a malloc()-ed null-terminated value. */
-extern char* leveldb_property_value(
- leveldb_t* db,
- const char* propname);
-
-extern void leveldb_approximate_sizes(
- leveldb_t* db,
- int num_ranges,
- const char* const* range_start_key, const size_t* range_start_key_len,
- const char* const* range_limit_key, const size_t* range_limit_key_len,
- uint64_t* sizes);
-
-extern void leveldb_compact_range(
- leveldb_t* db,
- const char* start_key, size_t start_key_len,
- const char* limit_key, size_t limit_key_len);
-
-/* Management operations */
-
-extern void leveldb_destroy_db(
- const leveldb_options_t* options,
- const char* name,
- char** errptr);
-
-extern void leveldb_repair_db(
- const leveldb_options_t* options,
- const char* name,
- char** errptr);
-
-/* Iterator */
-
-extern void leveldb_iter_destroy(leveldb_iterator_t*);
-extern unsigned char leveldb_iter_valid(const leveldb_iterator_t*);
-extern void leveldb_iter_seek_to_first(leveldb_iterator_t*);
-extern void leveldb_iter_seek_to_last(leveldb_iterator_t*);
-extern void leveldb_iter_seek(leveldb_iterator_t*, const char* k, size_t klen);
-extern void leveldb_iter_next(leveldb_iterator_t*);
-extern void leveldb_iter_prev(leveldb_iterator_t*);
-extern const char* leveldb_iter_key(const leveldb_iterator_t*, size_t* klen);
-extern const char* leveldb_iter_value(const leveldb_iterator_t*, size_t* vlen);
-extern void leveldb_iter_get_error(const leveldb_iterator_t*, char** errptr);
-
-/* Write batch */
-
-extern leveldb_writebatch_t* leveldb_writebatch_create();
-extern void leveldb_writebatch_destroy(leveldb_writebatch_t*);
-extern void leveldb_writebatch_clear(leveldb_writebatch_t*);
-extern void leveldb_writebatch_put(
- leveldb_writebatch_t*,
- const char* key, size_t klen,
- const char* val, size_t vlen);
-extern void leveldb_writebatch_delete(
- leveldb_writebatch_t*,
- const char* key, size_t klen);
-extern void leveldb_writebatch_iterate(
- leveldb_writebatch_t*,
- void* state,
- void (*put)(void*, const char* k, size_t klen, const char* v, size_t vlen),
- void (*deleted)(void*, const char* k, size_t klen));
-
-/* Options */
-
-extern leveldb_options_t* leveldb_options_create();
-extern void leveldb_options_destroy(leveldb_options_t*);
-extern void leveldb_options_set_comparator(
- leveldb_options_t*,
- leveldb_comparator_t*);
-extern void leveldb_options_set_filter_policy(
- leveldb_options_t*,
- leveldb_filterpolicy_t*);
-extern void leveldb_options_set_create_if_missing(
- leveldb_options_t*, unsigned char);
-extern void leveldb_options_set_error_if_exists(
- leveldb_options_t*, unsigned char);
-extern void leveldb_options_set_paranoid_checks(
- leveldb_options_t*, unsigned char);
-extern void leveldb_options_set_env(leveldb_options_t*, leveldb_env_t*);
-extern void leveldb_options_set_info_log(leveldb_options_t*, leveldb_logger_t*);
-extern void leveldb_options_set_write_buffer_size(leveldb_options_t*, size_t);
-extern void leveldb_options_set_max_open_files(leveldb_options_t*, int);
-extern void leveldb_options_set_cache(leveldb_options_t*, leveldb_cache_t*);
-extern void leveldb_options_set_block_size(leveldb_options_t*, size_t);
-extern void leveldb_options_set_block_restart_interval(leveldb_options_t*, int);
-
-enum {
- leveldb_no_compression = 0,
- leveldb_snappy_compression = 1
-};
-extern void leveldb_options_set_compression(leveldb_options_t*, int);
-
-/* Comparator */
-
-extern leveldb_comparator_t* leveldb_comparator_create(
- void* state,
- void (*destructor)(void*),
- int (*compare)(
- void*,
- const char* a, size_t alen,
- const char* b, size_t blen),
- const char* (*name)(void*));
-extern void leveldb_comparator_destroy(leveldb_comparator_t*);
-
-/* Filter policy */
-
-extern leveldb_filterpolicy_t* leveldb_filterpolicy_create(
- void* state,
- void (*destructor)(void*),
- char* (*create_filter)(
- void*,
- const char* const* key_array, const size_t* key_length_array,
- int num_keys,
- size_t* filter_length),
- unsigned char (*key_may_match)(
- void*,
- const char* key, size_t length,
- const char* filter, size_t filter_length),
- const char* (*name)(void*));
-extern void leveldb_filterpolicy_destroy(leveldb_filterpolicy_t*);
-
-extern leveldb_filterpolicy_t* leveldb_filterpolicy_create_bloom(
- int bits_per_key);
-
-/* Read options */
-
-extern leveldb_readoptions_t* leveldb_readoptions_create();
-extern void leveldb_readoptions_destroy(leveldb_readoptions_t*);
-extern void leveldb_readoptions_set_verify_checksums(
- leveldb_readoptions_t*,
- unsigned char);
-extern void leveldb_readoptions_set_fill_cache(
- leveldb_readoptions_t*, unsigned char);
-extern void leveldb_readoptions_set_snapshot(
- leveldb_readoptions_t*,
- const leveldb_snapshot_t*);
-
-/* Write options */
-
-extern leveldb_writeoptions_t* leveldb_writeoptions_create();
-extern void leveldb_writeoptions_destroy(leveldb_writeoptions_t*);
-extern void leveldb_writeoptions_set_sync(
- leveldb_writeoptions_t*, unsigned char);
-
-/* Cache */
-
-extern leveldb_cache_t* leveldb_cache_create_lru(size_t capacity);
-extern void leveldb_cache_destroy(leveldb_cache_t* cache);
-
-/* Env */
-
-extern leveldb_env_t* leveldb_create_default_env();
-extern void leveldb_env_destroy(leveldb_env_t*);
-
-/* Utility */
-
-/* Calls free(ptr).
- REQUIRES: ptr was malloc()-ed and returned by one of the routines
- in this file. Note that in certain cases (typically on Windows), you
- may need to call this routine instead of free(ptr) to dispose of
- malloc()-ed memory returned by this library. */
-extern void leveldb_free(void* ptr);
-
-/* Return the major version number for this release. */
-extern int leveldb_major_version();
-
-/* Return the minor version number for this release. */
-extern int leveldb_minor_version();
-
-#ifdef __cplusplus
-} /* end extern "C" */
-#endif
-
-#endif /* STORAGE_LEVELDB_INCLUDE_C_H_ */
diff --git a/lib/leveldb/include/cache.h b/lib/leveldb/include/cache.h
deleted file mode 100644
index 6819d5b..0000000
--- a/lib/leveldb/include/cache.h
+++ /dev/null
@@ -1,110 +0,0 @@
-// Copyright (c) 2011 The LevelDB Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file. See the AUTHORS file for names of contributors.
-//
-// A Cache is an interface that maps keys to values. It has internal
-// synchronization and may be safely accessed concurrently from
-// multiple threads. It may automatically evict entries to make room
-// for new entries. Values have a specified charge against the cache
-// capacity. For example, a cache where the values are variable
-// length strings, may use the length of the string as the charge for
-// the string.
-//
-// A builtin cache implementation with a least-recently-used eviction
-// policy is provided. Clients may use their own implementations if
-// they want something more sophisticated (like scan-resistance, a
-// custom eviction policy, variable cache sizing, etc.)
-
-#ifndef STORAGE_LEVELDB_INCLUDE_CACHE_H_
-#define STORAGE_LEVELDB_INCLUDE_CACHE_H_
-
-#include <stdint.h>
-#include "leveldb/slice.h"
-
-namespace leveldb {
-
-class Cache;
-
-// Create a new cache with a fixed size capacity. This implementation
-// of Cache uses a least-recently-used eviction policy.
-extern Cache* NewLRUCache(size_t capacity);
-
-class Cache {
- public:
- Cache() { }
-
- // Destroys all existing entries by calling the "deleter"
- // function that was passed to the constructor.
- virtual ~Cache();
-
- // Opaque handle to an entry stored in the cache.
- struct Handle { };
-
- // Insert a mapping from key->value into the cache and assign it
- // the specified charge against the total cache capacity.
- //
- // Returns a handle that corresponds to the mapping. The caller
- // must call this->Release(handle) when the returned mapping is no
- // longer needed.
- //
- // When the inserted entry is no longer needed, the key and
- // value will be passed to "deleter".
- virtual Handle* Insert(const Slice& key, void* value, size_t charge,
- void (*deleter)(const Slice& key, void* value)) = 0;
-
- // If the cache has no mapping for "key", returns NULL.
- //
- // Else return a handle that corresponds to the mapping. The caller
- // must call this->Release(handle) when the returned mapping is no
- // longer needed.
- virtual Handle* Lookup(const Slice& key) = 0;
-
- // Release a mapping returned by a previous Lookup().
- // REQUIRES: handle must not have been released yet.
- // REQUIRES: handle must have been returned by a method on *this.
- virtual void Release(Handle* handle) = 0;
-
- // Return the value encapsulated in a handle returned by a
- // successful Lookup().
- // REQUIRES: handle must not have been released yet.
- // REQUIRES: handle must have been returned by a method on *this.
- virtual void* Value(Handle* handle) = 0;
-
- // If the cache contains entry for key, erase it. Note that the
- // underlying entry will be kept around until all existing handles
- // to it have been released.
- virtual void Erase(const Slice& key) = 0;
-
- // Return a new numeric id. May be used by multiple clients who are
- // sharing the same cache to partition the key space. Typically the
- // client will allocate a new id at startup and prepend the id to
- // its cache keys.
- virtual uint64_t NewId() = 0;
-
- // Remove all cache entries that are not actively in use. Memory-constrained
- // applications may wish to call this method to reduce memory usage.
- // Default implementation of Prune() does nothing. Subclasses are strongly
- // encouraged to override the default implementation. A future release of
- // leveldb may change Prune() to a pure abstract method.
- virtual void Prune() {}
-
- // Return an estimate of the combined charges of all elements stored in the
- // cache.
- virtual size_t TotalCharge() const = 0;
-
- private:
- void LRU_Remove(Handle* e);
- void LRU_Append(Handle* e);
- void Unref(Handle* e);
-
- struct Rep;
- Rep* rep_;
-
- // No copying allowed
- Cache(const Cache&);
- void operator=(const Cache&);
-};
-
-} // namespace leveldb
-
-#endif // STORAGE_LEVELDB_INCLUDE_CACHE_H_
diff --git a/lib/leveldb/include/comparator.h b/lib/leveldb/include/comparator.h
deleted file mode 100644
index 556b984..0000000
--- a/lib/leveldb/include/comparator.h
+++ /dev/null
@@ -1,63 +0,0 @@
-// Copyright (c) 2011 The LevelDB Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file. See the AUTHORS file for names of contributors.
-
-#ifndef STORAGE_LEVELDB_INCLUDE_COMPARATOR_H_
-#define STORAGE_LEVELDB_INCLUDE_COMPARATOR_H_
-
-#include <string>
-
-namespace leveldb {
-
-class Slice;
-
-// A Comparator object provides a total order across slices that are
-// used as keys in an sstable or a database. A Comparator implementation
-// must be thread-safe since leveldb may invoke its methods concurrently
-// from multiple threads.
-class Comparator {
- public:
- virtual ~Comparator();
-
- // Three-way comparison. Returns value:
- // < 0 iff "a" < "b",
- // == 0 iff "a" == "b",
- // > 0 iff "a" > "b"
- virtual int Compare(const Slice& a, const Slice& b) const = 0;
-
- // The name of the comparator. Used to check for comparator
- // mismatches (i.e., a DB created with one comparator is
- // accessed using a different comparator.
- //
- // The client of this package should switch to a new name whenever
- // the comparator implementation changes in a way that will cause
- // the relative ordering of any two keys to change.
- //
- // Names starting with "leveldb." are reserved and should not be used
- // by any clients of this package.
- virtual const char* Name() const = 0;
-
- // Advanced functions: these are used to reduce the space requirements
- // for internal data structures like index blocks.
-
- // If *start < limit, changes *start to a short string in [start,limit).
- // Simple comparator implementations may return with *start unchanged,
- // i.e., an implementation of this method that does nothing is correct.
- virtual void FindShortestSeparator(
- std::string* start,
- const Slice& limit) const = 0;
-
- // Changes *key to a short string >= *key.
- // Simple comparator implementations may return with *key unchanged,
- // i.e., an implementation of this method that does nothing is correct.
- virtual void FindShortSuccessor(std::string* key) const = 0;
-};
-
-// Return a builtin comparator that uses lexicographic byte-wise
-// ordering. The result remains the property of this module and
-// must not be deleted.
-extern const Comparator* BytewiseComparator();
-
-} // namespace leveldb
-
-#endif // STORAGE_LEVELDB_INCLUDE_COMPARATOR_H_
diff --git a/lib/leveldb/include/db.h b/lib/leveldb/include/db.h
deleted file mode 100644
index bfab10a..0000000
--- a/lib/leveldb/include/db.h
+++ /dev/null
@@ -1,163 +0,0 @@
-// Copyright (c) 2011 The LevelDB Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file. See the AUTHORS file for names of contributors.
-
-#ifndef STORAGE_LEVELDB_INCLUDE_DB_H_
-#define STORAGE_LEVELDB_INCLUDE_DB_H_
-
-#include <stdint.h>
-#include <stdio.h>
-#include "leveldb/iterator.h"
-#include "leveldb/options.h"
-
-namespace leveldb {
-
-// Update Makefile if you change these
-static const int kMajorVersion = 1;
-static const int kMinorVersion = 20;
-
-struct Options;
-struct ReadOptions;
-struct WriteOptions;
-class WriteBatch;
-
-// Abstract handle to particular state of a DB.
-// A Snapshot is an immutable object and can therefore be safely
-// accessed from multiple threads without any external synchronization.
-class Snapshot {
- protected:
- virtual ~Snapshot();
-};
-
-// A range of keys
-struct Range {
- Slice start; // Included in the range
- Slice limit; // Not included in the range
-
- Range() { }
- Range(const Slice& s, const Slice& l) : start(s), limit(l) { }
-};
-
-// A DB is a persistent ordered map from keys to values.
-// A DB is safe for concurrent access from multiple threads without
-// any external synchronization.
-class DB {
- public:
- // Open the database with the specified "name".
- // Stores a pointer to a heap-allocated database in *dbptr and returns
- // OK on success.
- // Stores NULL in *dbptr and returns a non-OK status on error.
- // Caller should delete *dbptr when it is no longer needed.
- static Status Open(const Options& options,
- const std::string& name,
- DB** dbptr);
-
- DB() { }
- virtual ~DB();
-
- // Set the database entry for "key" to "value". Returns OK on success,
- // and a non-OK status on error.
- // Note: consider setting options.sync = true.
- virtual Status Put(const WriteOptions& options,
- const Slice& key,
- const Slice& value) = 0;
-
- // Remove the database entry (if any) for "key". Returns OK on
- // success, and a non-OK status on error. It is not an error if "key"
- // did not exist in the database.
- // Note: consider setting options.sync = true.
- virtual Status Delete(const WriteOptions& options, const Slice& key) = 0;
-
- // Apply the specified updates to the database.
- // Returns OK on success, non-OK on failure.
- // Note: consider setting options.sync = true.
- virtual Status Write(const WriteOptions& options, WriteBatch* updates) = 0;
-
- // If the database contains an entry for "key" store the
- // corresponding value in *value and return OK.
- //
- // If there is no entry for "key" leave *value unchanged and return
- // a status for which Status::IsNotFound() returns true.
- //
- // May return some other Status on an error.
- virtual Status Get(const ReadOptions& options,
- const Slice& key, std::string* value) = 0;
-
- // Return a heap-allocated iterator over the contents of the database.
- // The result of NewIterator() is initially invalid (caller must
- // call one of the Seek methods on the iterator before using it).
- //
- // Caller should delete the iterator when it is no longer needed.
- // The returned iterator should be deleted before this db is deleted.
- virtual Iterator* NewIterator(const ReadOptions& options) = 0;
-
- // Return a handle to the current DB state. Iterators created with
- // this handle will all observe a stable snapshot of the current DB
- // state. The caller must call ReleaseSnapshot(result) when the
- // snapshot is no longer needed.
- virtual const Snapshot* GetSnapshot() = 0;
-
- // Release a previously acquired snapshot. The caller must not
- // use "snapshot" after this call.
- virtual void ReleaseSnapshot(const Snapshot* snapshot) = 0;
-
- // DB implementations can export properties about their state
- // via this method. If "property" is a valid property understood by this
- // DB implementation, fills "*value" with its current value and returns
- // true. Otherwise returns false.
- //
- //
- // Valid property names include:
- //
- // "leveldb.num-files-at-level<N>" - return the number of files at level <N>,
- // where <N> is an ASCII representation of a level number (e.g. "0").
- // "leveldb.stats" - returns a multi-line string that describes statistics
- // about the internal operation of the DB.
- // "leveldb.sstables" - returns a multi-line string that describes all
- // of the sstables that make up the db contents.
- // "leveldb.approximate-memory-usage" - returns the approximate number of
- // bytes of memory in use by the DB.
- virtual bool GetProperty(const Slice& property, std::string* value) = 0;
-
- // For each i in [0,n-1], store in "sizes[i]", the approximate
- // file system space used by keys in "[range[i].start .. range[i].limit)".
- //
- // Note that the returned sizes measure file system space usage, so
- // if the user data compresses by a factor of ten, the returned
- // sizes will be one-tenth the size of the corresponding user data size.
- //
- // The results may not include the sizes of recently written data.
- virtual void GetApproximateSizes(const Range* range, int n,
- uint64_t* sizes) = 0;
-
- // Compact the underlying storage for the key range [*begin,*end].
- // In particular, deleted and overwritten versions are discarded,
- // and the data is rearranged to reduce the cost of operations
- // needed to access the data. This operation should typically only
- // be invoked by users who understand the underlying implementation.
- //
- // begin==NULL is treated as a key before all keys in the database.
- // end==NULL is treated as a key after all keys in the database.
- // Therefore the following call will compact the entire database:
- // db->CompactRange(NULL, NULL);
- virtual void CompactRange(const Slice* begin, const Slice* end) = 0;
-
- private:
- // No copying allowed
- DB(const DB&);
- void operator=(const DB&);
-};
-
-// Destroy the contents of the specified database.
-// Be very careful using this method.
-Status DestroyDB(const std::string& name, const Options& options);
-
-// If a DB cannot be opened, you may attempt to call this method to
-// resurrect as much of the contents of the database as possible.
-// Some data may be lost, so be careful when calling this function
-// on a database that contains important information.
-Status RepairDB(const std::string& dbname, const Options& options);
-
-} // namespace leveldb
-
-#endif // STORAGE_LEVELDB_INCLUDE_DB_H_
diff --git a/lib/leveldb/include/dumpfile.h b/lib/leveldb/include/dumpfile.h
deleted file mode 100644
index 3f97fda..0000000
--- a/lib/leveldb/include/dumpfile.h
+++ /dev/null
@@ -1,25 +0,0 @@
-// Copyright (c) 2014 The LevelDB Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file. See the AUTHORS file for names of contributors.
-
-#ifndef STORAGE_LEVELDB_INCLUDE_DUMPFILE_H_
-#define STORAGE_LEVELDB_INCLUDE_DUMPFILE_H_
-
-#include <string>
-#include "leveldb/env.h"
-#include "leveldb/status.h"
-
-namespace leveldb {
-
-// Dump the contents of the file named by fname in text format to
-// *dst. Makes a sequence of dst->Append() calls; each call is passed
-// the newline-terminated text corresponding to a single item found
-// in the file.
-//
-// Returns a non-OK result if fname does not name a leveldb storage
-// file, or if the file cannot be read.
-Status DumpFile(Env* env, const std::string& fname, WritableFile* dst);
-
-} // namespace leveldb
-
-#endif // STORAGE_LEVELDB_INCLUDE_DUMPFILE_H_
diff --git a/lib/leveldb/include/env.h b/lib/leveldb/include/env.h
deleted file mode 100644
index 99b6c21..0000000
--- a/lib/leveldb/include/env.h
+++ /dev/null
@@ -1,351 +0,0 @@
-// Copyright (c) 2011 The LevelDB Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file. See the AUTHORS file for names of contributors.
-//
-// An Env is an interface used by the leveldb implementation to access
-// operating system functionality like the filesystem etc. Callers
-// may wish to provide a custom Env object when opening a database to
-// get fine gain control; e.g., to rate limit file system operations.
-//
-// All Env implementations are safe for concurrent access from
-// multiple threads without any external synchronization.
-
-#ifndef STORAGE_LEVELDB_INCLUDE_ENV_H_
-#define STORAGE_LEVELDB_INCLUDE_ENV_H_
-
-#include <string>
-#include <vector>
-#include <stdarg.h>
-#include <stdint.h>
-#include "leveldb/status.h"
-
-namespace leveldb {
-
-class FileLock;
-class Logger;
-class RandomAccessFile;
-class SequentialFile;
-class Slice;
-class WritableFile;
-
-class Env {
- public:
- Env() { }
- virtual ~Env();
-
- // Return a default environment suitable for the current operating
- // system. Sophisticated users may wish to provide their own Env
- // implementation instead of relying on this default environment.
- //
- // The result of Default() belongs to leveldb and must never be deleted.
- static Env* Default();
-
- // Create a brand new sequentially-readable file with the specified name.
- // On success, stores a pointer to the new file in *result and returns OK.
- // On failure stores NULL in *result and returns non-OK. If the file does
- // not exist, returns a non-OK status.
- //
- // The returned file will only be accessed by one thread at a time.
- virtual Status NewSequentialFile(const std::string& fname,
- SequentialFile** result) = 0;
-
- // Create a brand new random access read-only file with the
- // specified name. On success, stores a pointer to the new file in
- // *result and returns OK. On failure stores NULL in *result and
- // returns non-OK. If the file does not exist, returns a non-OK
- // status.
- //
- // The returned file may be concurrently accessed by multiple threads.
- virtual Status NewRandomAccessFile(const std::string& fname,
- RandomAccessFile** result) = 0;
-
- // Create an object that writes to a new file with the specified
- // name. Deletes any existing file with the same name and creates a
- // new file. On success, stores a pointer to the new file in
- // *result and returns OK. On failure stores NULL in *result and
- // returns non-OK.
- //
- // The returned file will only be accessed by one thread at a time.
- virtual Status NewWritableFile(const std::string& fname,
- WritableFile** result) = 0;
-
- // Create an object that either appends to an existing file, or
- // writes to a new file (if the file does not exist to begin with).
- // On success, stores a pointer to the new file in *result and
- // returns OK. On failure stores NULL in *result and returns
- // non-OK.
- //
- // The returned file will only be accessed by one thread at a time.
- //
- // May return an IsNotSupportedError error if this Env does
- // not allow appending to an existing file. Users of Env (including
- // the leveldb implementation) must be prepared to deal with
- // an Env that does not support appending.
- virtual Status NewAppendableFile(const std::string& fname,
- WritableFile** result);
-
- // Returns true iff the named file exists.
- virtual bool FileExists(const std::string& fname) = 0;
-
- // Store in *result the names of the children of the specified directory.
- // The names are relative to "dir".
- // Original contents of *results are dropped.
- virtual Status GetChildren(const std::string& dir,
- std::vector<std::string>* result) = 0;
-
- // Delete the named file.
- virtual Status DeleteFile(const std::string& fname) = 0;
-
- // Create the specified directory.
- virtual Status CreateDir(const std::string& dirname) = 0;
-
- // Delete the specified directory.
- virtual Status DeleteDir(const std::string& dirname) = 0;
-
- // Store the size of fname in *file_size.
- virtual Status GetFileSize(const std::string& fname, uint64_t* file_size) = 0;
-
- // Rename file src to target.
- virtual Status RenameFile(const std::string& src,
- const std::string& target) = 0;
-
- // Lock the specified file. Used to prevent concurrent access to
- // the same db by multiple processes. On failure, stores NULL in
- // *lock and returns non-OK.
- //
- // On success, stores a pointer to the object that represents the
- // acquired lock in *lock and returns OK. The caller should call
- // UnlockFile(*lock) to release the lock. If the process exits,
- // the lock will be automatically released.
- //
- // If somebody else already holds the lock, finishes immediately
- // with a failure. I.e., this call does not wait for existing locks
- // to go away.
- //
- // May create the named file if it does not already exist.
- virtual Status LockFile(const std::string& fname, FileLock** lock) = 0;
-
- // Release the lock acquired by a previous successful call to LockFile.
- // REQUIRES: lock was returned by a successful LockFile() call
- // REQUIRES: lock has not already been unlocked.
- virtual Status UnlockFile(FileLock* lock) = 0;
-
- // Arrange to run "(*function)(arg)" once in a background thread.
- //
- // "function" may run in an unspecified thread. Multiple functions
- // added to the same Env may run concurrently in different threads.
- // I.e., the caller may not assume that background work items are
- // serialized.
- virtual void Schedule(
- void (*function)(void* arg),
- void* arg) = 0;
-
- // Start a new thread, invoking "function(arg)" within the new thread.
- // When "function(arg)" returns, the thread will be destroyed.
- virtual void StartThread(void (*function)(void* arg), void* arg) = 0;
-
- // *path is set to a temporary directory that can be used for testing. It may
- // or many not have just been created. The directory may or may not differ
- // between runs of the same process, but subsequent calls will return the
- // same directory.
- virtual Status GetTestDirectory(std::string* path) = 0;
-
- // Create and return a log file for storing informational messages.
- virtual Status NewLogger(const std::string& fname, Logger** result) = 0;
-
- // Returns the number of micro-seconds since some fixed point in time. Only
- // useful for computing deltas of time.
- virtual uint64_t NowMicros() = 0;
-
- // Sleep/delay the thread for the prescribed number of micro-seconds.
- virtual void SleepForMicroseconds(int micros) = 0;
-
- private:
- // No copying allowed
- Env(const Env&);
- void operator=(const Env&);
-};
-
-// A file abstraction for reading sequentially through a file
-class SequentialFile {
- public:
- SequentialFile() { }
- virtual ~SequentialFile();
-
- // Read up to "n" bytes from the file. "scratch[0..n-1]" may be
- // written by this routine. Sets "*result" to the data that was
- // read (including if fewer than "n" bytes were successfully read).
- // May set "*result" to point at data in "scratch[0..n-1]", so
- // "scratch[0..n-1]" must be live when "*result" is used.
- // If an error was encountered, returns a non-OK status.
- //
- // REQUIRES: External synchronization
- virtual Status Read(size_t n, Slice* result, char* scratch) = 0;
-
- // Skip "n" bytes from the file. This is guaranteed to be no
- // slower that reading the same data, but may be faster.
- //
- // If end of file is reached, skipping will stop at the end of the
- // file, and Skip will return OK.
- //
- // REQUIRES: External synchronization
- virtual Status Skip(uint64_t n) = 0;
-
- private:
- // No copying allowed
- SequentialFile(const SequentialFile&);
- void operator=(const SequentialFile&);
-};
-
-// A file abstraction for randomly reading the contents of a file.
-class RandomAccessFile {
- public:
- RandomAccessFile() { }
- virtual ~RandomAccessFile();
-
- // Read up to "n" bytes from the file starting at "offset".
- // "scratch[0..n-1]" may be written by this routine. Sets "*result"
- // to the data that was read (including if fewer than "n" bytes were
- // successfully read). May set "*result" to point at data in
- // "scratch[0..n-1]", so "scratch[0..n-1]" must be live when
- // "*result" is used. If an error was encountered, returns a non-OK
- // status.
- //
- // Safe for concurrent use by multiple threads.
- virtual Status Read(uint64_t offset, size_t n, Slice* result,
- char* scratch) const = 0;
-
- private:
- // No copying allowed
- RandomAccessFile(const RandomAccessFile&);
- void operator=(const RandomAccessFile&);
-};
-
-// A file abstraction for sequential writing. The implementation
-// must provide buffering since callers may append small fragments
-// at a time to the file.
-class WritableFile {
- public:
- WritableFile() { }
- virtual ~WritableFile();
-
- virtual Status Append(const Slice& data) = 0;
- virtual Status Close() = 0;
- virtual Status Flush() = 0;
- virtual Status Sync() = 0;
-
- private:
- // No copying allowed
- WritableFile(const WritableFile&);
- void operator=(const WritableFile&);
-};
-
-// An interface for writing log messages.
-class Logger {
- public:
- Logger() { }
- virtual ~Logger();
-
- // Write an entry to the log file with the specified format.
- virtual void Logv(const char* format, va_list ap) = 0;
-
- private:
- // No copying allowed
- Logger(const Logger&);
- void operator=(const Logger&);
-};
-
-
-// Identifies a locked file.
-class FileLock {
- public:
- FileLock() { }
- virtual ~FileLock();
- private:
- // No copying allowed
- FileLock(const FileLock&);
- void operator=(const FileLock&);
-};
-
-// Log the specified data to *info_log if info_log is non-NULL.
-extern void Log(Logger* info_log, const char* format, ...)
-# if defined(__GNUC__) || defined(__clang__)
- __attribute__((__format__ (__printf__, 2, 3)))
-# endif
- ;
-
-// A utility routine: write "data" to the named file.
-extern Status WriteStringToFile(Env* env, const Slice& data,
- const std::string& fname);
-
-// A utility routine: read contents of named file into *data
-extern Status ReadFileToString(Env* env, const std::string& fname,