1 #ifndef _ABSTRACT_ORDERED_INDEX_H_
2 #define _ABSTRACT_ORDERED_INDEX_H_
10 #include "../str_arena.h"
13 * The underlying index manages memory for keys/values, but
14 * may choose to expose the underlying memory to callers
15 * (see put() and inesrt()).
17 class abstract_ordered_index {
20 virtual ~abstract_ordered_index() {}
23 * Get a key of length keylen. The underlying DB does not manage
24 * the memory associated with key. Returns true if found, false otherwise
28 const std::string &key,
30 size_t max_bytes_read = std::string::npos) = 0;
34 virtual ~scan_callback() {}
35 // XXX(stephentu): key is passed as (const char *, size_t) pair
36 // because it really should be the string_type of the underlying
37 // tree, but since abstract_ordered_index is not templated we can't
38 // really do better than this for now
40 // we keep value as std::string b/c we have more control over how those
41 // strings are generated
42 virtual bool invoke(const char *keyp, size_t keylen,
43 const std::string &value) = 0;
47 * Search [start_key, *end_key) if end_key is not null, otherwise
48 * search [start_key, +infty)
52 const std::string &start_key,
53 const std::string *end_key,
54 scan_callback &callback,
55 str_arena *arena = nullptr) = 0;
58 * Search (*end_key, start_key] if end_key is not null, otherwise
59 * search (-infty, start_key] (starting at start_key and traversing
64 const std::string &start_key,
65 const std::string *end_key,
66 scan_callback &callback,
67 str_arena *arena = nullptr) = 0;
70 * Put a key of length keylen, with mapping of length valuelen.
71 * The underlying DB does not manage the memory pointed to by key or value
74 * If a record with key k exists, overwrites. Otherwise, inserts.
76 * If the return value is not NULL, then it points to the actual stable
77 * location in memory where the value is located. Thus, [ret, ret+valuelen)
78 * will be valid memory, bytewise equal to [value, value+valuelen), since the
79 * implementations have immutable values for the time being. The value
80 * returned is guaranteed to be valid memory until the key associated with
85 const std::string &key,
86 const std::string &value) = 0;
93 return put(txn, static_cast<const std::string &>(key),
94 static_cast<const std::string &>(value));
98 * Insert a key of length keylen.
100 * If a record with key k exists, behavior is unspecified- this function
101 * is only to be used when you can guarantee no such key exists (ie in loading phase)
103 * Default implementation calls put(). See put() for meaning of return value.
107 const std::string &key,
108 const std::string &value)
110 return put(txn, key, value);
118 return insert(txn, static_cast<const std::string &>(key),
119 static_cast<const std::string &>(value));
123 * Default implementation calls put() with NULL (zero-length) value
127 const std::string &key)
136 remove(txn, static_cast<const std::string &>(key));
140 * Only an estimate, not transactional!
142 virtual size_t size() const = 0;
145 * Not thread safe for now
147 virtual std::map<std::string, uint64_t> clear() = 0;
150 #endif /* _ABSTRACT_ORDERED_INDEX_H_ */