taco-db  0.1.0
VolatileTree.h
Go to the documentation of this file.
1 #ifndef INDEX_VOLATILETREE_VOLATILETREE_H
2 #define INDEX_VOLATILETREE_VOLATILETREE_H
3 
4 #include "tdb.h"
5 
6 #include <map>
7 
8 #include "index/Index.h"
9 
10 namespace taco {
11 
15 void InitVolatileTree();
16 
20 void CleanVolatileTree();
21 
28  std::vector<FunctionInfo> m_lt_funcs;
29  std::vector<FunctionInfo> m_eq_funcs;
30 };
31 
33  VolatileTreeLess(std::shared_ptr<VolatileTreeFuncs> funcs):
34  m_funcs(std::move(funcs)) {}
35 
36  bool operator()(char *buf1, char *buf2) const;
37 
38 private:
39  std::shared_ptr<VolatileTreeFuncs> m_funcs;
40 };
41 
43  // key: some tuplebuf, value: record id
44  typedef std::multimap<char*, RecordId, VolatileTreeLess> tree_type;
45 
46  VolatileTreeBase(std::shared_ptr<VolatileTreeFuncs> funcs);
47 
49 
50  std::shared_ptr<VolatileTreeFuncs> m_funcs;
51 
52  std::vector<maxaligned_char_buf> m_tuplebufs;
53 };
54 
59 class VolatileTree: public Index {
60 public:
62 
63  class Iterator;
64 
65  static void Initialize(const IndexDesc *idxdesc);
66 
67  static std::unique_ptr<VolatileTree> Create(
68  std::shared_ptr<const IndexDesc> idxdesc);
69 
70 private:
71  VolatileTree(std::shared_ptr<const IndexDesc> idxdesc,
72  std::shared_ptr<VolatileTreeBase> base);
73 
74  std::shared_ptr<VolatileTreeBase> m_base;
75 
76 public:
77  virtual ~VolatileTree();
78 
79  bool InsertKey(const IndexKey *key, RecordId rid) override;
80 
81  bool DeleteKey(const IndexKey *key, RecordId &rid) override;
82 
83  std::unique_ptr<Index::Iterator> StartScan(const IndexKey *lower,
84  bool lower_isstrict,
85  const IndexKey *upper,
86  bool upper_isstrict) override;
87 public:
88  typedef typename std::decay<
89  decltype(std::declval<VolatileTreeBase>().m_tree.begin())>::type
91 
92  class Iterator: public Index::Iterator {
93  public:
94  bool Next() override;
95 
96  bool IsAtValidItem() override;
97 
98  const Record &
99  GetCurrentItem() override {
100  return m_rec;
101  }
102 
103  RecordId
104  GetCurrentRecordId() override {
105  return m_rec.GetRecordId();
106  }
107 
108  void
109  EndScan() override {
110  }
111 
112  private:
114  const IndexKey *upper, bool upper_isstrict);
115 
117 
119 
121 
122  std::vector<Datum> m_upper_data_buffer;
123 
125 
127 
128  friend class VolatileTree;
129  };
130 
131  friend class Iterator;
132 };
133 
134 } // namespace taco
135 
136 #endif // INDEX_VOLATILETREE_VOLATILETREE_H
Definition: IndexDesc.h:11
A forward-iterator for the items in the index.
Definition: Index.h:181
An interface class for index implementations.
Definition: Index.h:19
Definition: Record.h:87
RecordId & GetRecordId()
Definition: Record.h:131
A Schema object stores the information for accessing an ordered set of typed fields either from a dis...
Definition: Schema.h:39
Definition: VolatileTree.h:92
bool Next() override
Moves the iterator to the next indexed item if any.
Definition: VolatileTree.cpp:313
UniqueIndexKey m_upper
Definition: VolatileTree.h:120
void EndScan() override
Ends the index scan.
Definition: VolatileTree.h:109
RecordId GetCurrentRecordId() override
Returns the record id of the indexed item the iterator is currently at.
Definition: VolatileTree.h:104
bool IsAtValidItem() override
Returns whether the iterator is currently at a valid indexed item.
Definition: VolatileTree.cpp:351
std::vector< Datum > m_upper_data_buffer
Definition: VolatileTree.h:122
Record m_rec
Definition: VolatileTree.h:118
bool m_is_first
Definition: VolatileTree.h:124
VolatileTree::map_iterator m_iter
Definition: VolatileTree.h:116
bool m_upper_isstrict
Definition: VolatileTree.h:126
const Record & GetCurrentItem() override
Returns the current indexed item the iterator is currently at, where the GetData() and GetLength() pa...
Definition: VolatileTree.h:99
An in-memory tree index that is stored only in memory.
Definition: VolatileTree.h:59
virtual ~VolatileTree()
Definition: VolatileTree.cpp:156
std::decay< decltype(std::declval< VolatileTreeBase >).m_tree.begin())>::type map_iterator
Definition: VolatileTree.h:90
std::unique_ptr< Index::Iterator > StartScan(const IndexKey *lower, bool lower_isstrict, const IndexKey *upper, bool upper_isstrict) override
Returns a forward-iterator for all the indexed items in the specified range defined by the arguments.
Definition: VolatileTree.cpp:234
bool InsertKey(const IndexKey *key, RecordId rid) override
Inserts the (key, rid) pair into the index.
Definition: VolatileTree.cpp:160
std::shared_ptr< VolatileTreeBase > m_base
Definition: VolatileTree.h:74
VolatileTree(std::shared_ptr< const IndexDesc > idxdesc, std::shared_ptr< VolatileTreeBase > base)
Definition: VolatileTree.cpp:150
VolatileTreeBase::tree_type tree_type
Definition: VolatileTree.h:61
static void Initialize(const IndexDesc *idxdesc)
Definition: VolatileTree.cpp:90
bool DeleteKey(const IndexKey *key, RecordId &rid) override
Deletes an arbitrary data entry with matching key if rid is invalid.
Definition: VolatileTree.cpp:200
static std::unique_ptr< VolatileTree > Create(std::shared_ptr< const IndexDesc > idxdesc)
Definition: VolatileTree.cpp:140
Definition: Record.h:148
Definition: datum.h:28
void InitVolatileTree()
Initializes the internal state of the in-memory tree index.
Definition: VolatileTree.cpp:71
void CleanVolatileTree()
Cleans up the internal state of the in-memory tree index.
Definition: VolatileTree.cpp:80
std::unique_ptr< IndexKey, AlignedAllocImpl::FreeMem > UniqueIndexKey
The returned smart pointer of IndexKey::Create().
Definition: IndexKey.h:10
An IndexKey stores references to a few data (Datum objects) that comprise a key tuple to in an index.
Definition: IndexKey.h:35
The record ID of a record on a page is a pair of ‘(PageNumber, SlotId)’.
Definition: Record.h:17
Definition: VolatileTree.h:42
tree_type m_tree
Definition: VolatileTree.h:48
std::vector< maxaligned_char_buf > m_tuplebufs
Definition: VolatileTree.h:52
VolatileTreeBase(std::shared_ptr< VolatileTreeFuncs > funcs)
Definition: VolatileTree.cpp:84
std::multimap< char *, RecordId, VolatileTreeLess > tree_type
Definition: VolatileTree.h:44
std::shared_ptr< VolatileTreeFuncs > m_funcs
Definition: VolatileTree.h:50
Definition: VolatileTree.h:22
std::vector< FunctionInfo > m_eq_funcs
Definition: VolatileTree.h:29
Schema m_key_schema
This is a copy of the index's key schema to be used by std::multimap's comparator to dissemble a reco...
Definition: VolatileTree.h:27
std::vector< FunctionInfo > m_lt_funcs
Definition: VolatileTree.h:28
Definition: VolatileTree.h:32
VolatileTreeLess(std::shared_ptr< VolatileTreeFuncs > funcs)
Definition: VolatileTree.h:33
bool operator()(char *buf1, char *buf2) const
Definition: VolatileTree.cpp:265
std::shared_ptr< VolatileTreeFuncs > m_funcs
Definition: VolatileTree.h:39