作者: 韩晨旭 10225101440 李畅 10225102463
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

246 rindas
8.2 KiB

  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. C bindings for leveldb. May be useful as a stable ABI that can be
  5. used by programs that keep leveldb in a shared library, or for
  6. a JNI api.
  7. Does not support:
  8. . getters for the option types
  9. . custom comparators that implement key shortening
  10. . capturing post-write-snapshot
  11. . custom iter, db, env, cache implementations using just the C bindings
  12. Some conventions:
  13. (1) We expose just opaque struct pointers and functions to clients.
  14. This allows us to change internal representations without having to
  15. recompile clients.
  16. (2) For simplicity, there is no equivalent to the Slice type. Instead,
  17. the caller has to pass the pointer and length as separate
  18. arguments.
  19. (3) Errors are represented by a null-terminated c string. NULL
  20. means no error. All operations that can raise an error are passed
  21. a "char** errptr" as the last argument. One of the following must
  22. be true on entry:
  23. *errptr == NULL
  24. *errptr points to a malloc()ed null-terminated error message
  25. On success, a leveldb routine leaves *errptr unchanged.
  26. On failure, leveldb frees the old value of *errptr and
  27. set *errptr to a malloc()ed error message.
  28. (4) Bools have the type unsigned char (0 == false; rest == true)
  29. (5) All of the pointer arguments must be non-NULL.
  30. */
  31. #ifndef STORAGE_LEVELDB_INCLUDE_C_H_
  32. #define STORAGE_LEVELDB_INCLUDE_C_H_
  33. #ifdef __cplusplus
  34. extern "C" {
  35. #endif
  36. #include <stdarg.h>
  37. #include <stddef.h>
  38. #include <stdint.h>
  39. /* Exported types */
  40. typedef struct leveldb_t leveldb_t;
  41. typedef struct leveldb_cache_t leveldb_cache_t;
  42. typedef struct leveldb_comparator_t leveldb_comparator_t;
  43. typedef struct leveldb_env_t leveldb_env_t;
  44. typedef struct leveldb_filelock_t leveldb_filelock_t;
  45. typedef struct leveldb_iterator_t leveldb_iterator_t;
  46. typedef struct leveldb_logger_t leveldb_logger_t;
  47. typedef struct leveldb_options_t leveldb_options_t;
  48. typedef struct leveldb_randomfile_t leveldb_randomfile_t;
  49. typedef struct leveldb_readoptions_t leveldb_readoptions_t;
  50. typedef struct leveldb_seqfile_t leveldb_seqfile_t;
  51. typedef struct leveldb_snapshot_t leveldb_snapshot_t;
  52. typedef struct leveldb_writablefile_t leveldb_writablefile_t;
  53. typedef struct leveldb_writebatch_t leveldb_writebatch_t;
  54. typedef struct leveldb_writeoptions_t leveldb_writeoptions_t;
  55. /* DB operations */
  56. extern leveldb_t* leveldb_open(
  57. const leveldb_options_t* options,
  58. const char* name,
  59. char** errptr);
  60. extern void leveldb_close(leveldb_t* db);
  61. extern void leveldb_put(
  62. leveldb_t* db,
  63. const leveldb_writeoptions_t* options,
  64. const char* key, size_t keylen,
  65. const char* val, size_t vallen,
  66. char** errptr);
  67. extern void leveldb_delete(
  68. leveldb_t* db,
  69. const leveldb_writeoptions_t* options,
  70. const char* key, size_t keylen,
  71. char** errptr);
  72. extern void leveldb_write(
  73. leveldb_t* db,
  74. const leveldb_writeoptions_t* options,
  75. leveldb_writebatch_t* batch,
  76. char** errptr);
  77. /* Returns NULL if not found. A malloc()ed array otherwise.
  78. Stores the length of the array in *vallen. */
  79. extern char* leveldb_get(
  80. leveldb_t* db,
  81. const leveldb_readoptions_t* options,
  82. const char* key, size_t keylen,
  83. size_t* vallen,
  84. char** errptr);
  85. extern leveldb_iterator_t* leveldb_create_iterator(
  86. leveldb_t* db,
  87. const leveldb_readoptions_t* options);
  88. extern const leveldb_snapshot_t* leveldb_create_snapshot(
  89. leveldb_t* db);
  90. extern void leveldb_release_snapshot(
  91. leveldb_t* db,
  92. const leveldb_snapshot_t* snapshot);
  93. /* Returns NULL if property name is unknown.
  94. Else returns a pointer to a malloc()-ed null-terminated value. */
  95. extern char* leveldb_property_value(
  96. leveldb_t* db,
  97. const char* propname);
  98. extern void leveldb_approximate_sizes(
  99. leveldb_t* db,
  100. int num_ranges,
  101. const char* const* range_start_key, const size_t* range_start_key_len,
  102. const char* const* range_limit_key, const size_t* range_limit_key_len,
  103. uint64_t* sizes);
  104. /* Management operations */
  105. extern void leveldb_destroy_db(
  106. const leveldb_options_t* options,
  107. const char* name,
  108. char** errptr);
  109. extern void leveldb_repair_db(
  110. const leveldb_options_t* options,
  111. const char* name,
  112. char** errptr);
  113. /* Iterator */
  114. extern void leveldb_iter_destroy(leveldb_iterator_t*);
  115. extern unsigned char leveldb_iter_valid(const leveldb_iterator_t*);
  116. extern void leveldb_iter_seek_to_first(leveldb_iterator_t*);
  117. extern void leveldb_iter_seek_to_last(leveldb_iterator_t*);
  118. extern void leveldb_iter_seek(leveldb_iterator_t*, const char* k, size_t klen);
  119. extern void leveldb_iter_next(leveldb_iterator_t*);
  120. extern void leveldb_iter_prev(leveldb_iterator_t*);
  121. extern const char* leveldb_iter_key(const leveldb_iterator_t*, size_t* klen);
  122. extern const char* leveldb_iter_value(const leveldb_iterator_t*, size_t* vlen);
  123. extern void leveldb_iter_get_error(const leveldb_iterator_t*, char** errptr);
  124. /* Write batch */
  125. extern leveldb_writebatch_t* leveldb_writebatch_create();
  126. extern void leveldb_writebatch_destroy(leveldb_writebatch_t*);
  127. extern void leveldb_writebatch_clear(leveldb_writebatch_t*);
  128. extern void leveldb_writebatch_put(
  129. leveldb_writebatch_t*,
  130. const char* key, size_t klen,
  131. const char* val, size_t vlen);
  132. extern void leveldb_writebatch_delete(
  133. leveldb_writebatch_t*,
  134. const char* key, size_t klen);
  135. extern void leveldb_writebatch_iterate(
  136. leveldb_writebatch_t*,
  137. void* state,
  138. void (*put)(void*, const char* k, size_t klen, const char* v, size_t vlen),
  139. void (*deleted)(void*, const char* k, size_t klen));
  140. /* Options */
  141. extern leveldb_options_t* leveldb_options_create();
  142. extern void leveldb_options_destroy(leveldb_options_t*);
  143. extern void leveldb_options_set_comparator(
  144. leveldb_options_t*,
  145. leveldb_comparator_t*);
  146. extern void leveldb_options_set_create_if_missing(
  147. leveldb_options_t*, unsigned char);
  148. extern void leveldb_options_set_error_if_exists(
  149. leveldb_options_t*, unsigned char);
  150. extern void leveldb_options_set_paranoid_checks(
  151. leveldb_options_t*, unsigned char);
  152. extern void leveldb_options_set_env(leveldb_options_t*, leveldb_env_t*);
  153. extern void leveldb_options_set_info_log(leveldb_options_t*, leveldb_logger_t*);
  154. extern void leveldb_options_set_write_buffer_size(leveldb_options_t*, size_t);
  155. extern void leveldb_options_set_max_open_files(leveldb_options_t*, int);
  156. extern void leveldb_options_set_cache(leveldb_options_t*, leveldb_cache_t*);
  157. extern void leveldb_options_set_block_size(leveldb_options_t*, size_t);
  158. extern void leveldb_options_set_block_restart_interval(leveldb_options_t*, int);
  159. enum {
  160. leveldb_no_compression = 0,
  161. leveldb_snappy_compression = 1
  162. };
  163. extern void leveldb_options_set_compression(leveldb_options_t*, int);
  164. /* Comparator */
  165. extern leveldb_comparator_t* leveldb_comparator_create(
  166. void* state,
  167. void (*destructor)(void*),
  168. int (*compare)(
  169. void*,
  170. const char* a, size_t alen,
  171. const char* b, size_t blen),
  172. const char* (*name)(void*));
  173. extern void leveldb_comparator_destroy(leveldb_comparator_t*);
  174. /* Read options */
  175. extern leveldb_readoptions_t* leveldb_readoptions_create();
  176. extern void leveldb_readoptions_destroy(leveldb_readoptions_t*);
  177. extern void leveldb_readoptions_set_verify_checksums(
  178. leveldb_readoptions_t*,
  179. unsigned char);
  180. extern void leveldb_readoptions_set_fill_cache(
  181. leveldb_readoptions_t*, unsigned char);
  182. extern void leveldb_readoptions_set_snapshot(
  183. leveldb_readoptions_t*,
  184. const leveldb_snapshot_t*);
  185. /* Write options */
  186. extern leveldb_writeoptions_t* leveldb_writeoptions_create();
  187. extern void leveldb_writeoptions_destroy(leveldb_writeoptions_t*);
  188. extern void leveldb_writeoptions_set_sync(
  189. leveldb_writeoptions_t*, unsigned char);
  190. /* Cache */
  191. extern leveldb_cache_t* leveldb_cache_create_lru(size_t capacity);
  192. extern void leveldb_cache_destroy(leveldb_cache_t* cache);
  193. /* Env */
  194. extern leveldb_env_t* leveldb_create_default_env();
  195. extern void leveldb_env_destroy(leveldb_env_t*);
  196. #ifdef __cplusplus
  197. } /* end extern "C" */
  198. #endif
  199. #endif /* STORAGE_LEVELDB_INCLUDE_C_H_ */