mutable
A Database System for Research and Fast Prototyping
Loading...
Searching...
No Matches
RowStore.hpp
Go to the documentation of this file.
1#pragma once
2
6
7
8namespace m {
9
12{
13#ifndef NDEBUG
14 static constexpr std::size_t ALLOCATION_SIZE = 1UL << 30;
15#else
16 static constexpr std::size_t ALLOCATION_SIZE = 1UL << 37;
17#endif
18
19 private:
22 std::size_t num_rows_ = 0;
23 std::size_t capacity_;
24 uint32_t *offsets_;
25 uint32_t row_size_;
26
27 public:
28 RowStore(const Table &table);
29 ~RowStore();
30
31 virtual std::size_t num_rows() const override { return num_rows_; }
32
33 int offset(uint32_t idx) const {
34 M_insist(idx <= table().num_attrs(), "index out of range");
35 return offsets_[idx];
36 }
37 int offset(const Attribute &attr) const { return offset(attr.id); }
38
40 std::size_t row_size() const { return row_size_; }
41
42 void append() override {
43 if (num_rows_ == capacity_)
44 throw std::logic_error("row store exceeds capacity");
45 ++num_rows_;
46 }
47
48 void drop() override {
50 --num_rows_;
51 }
52
54 const memory::Memory & memory() const override { return data_; }
56 void memory(memory::Memory memory) { data_ = std::move(memory); }
57
58 void dump(std::ostream &out) const override;
59 using Store::dump;
60
61 private:
64 void compute_offsets();
65
67 uintptr_t at(std::size_t idx) const { return data_.as<uintptr_t>() + row_size_/8 * idx; }
68};
69
70}
#define M_insist(...)
Definition: macro.hpp:129
‍mutable namespace
Definition: Backend.hpp:10
An attribute of a table.
Definition: Schema.hpp:289
std::size_t id
the internal identifier of the attribute, unique within its table
Definition: Schema.hpp:292
This class implements a row store.
Definition: RowStore.hpp:12
void drop() override
Drop the most recently appended row.
Definition: RowStore.hpp:48
int offset(const Attribute &attr) const
Definition: RowStore.hpp:37
memory::Memory data_
the underlying memory containing the data
Definition: RowStore.hpp:21
std::size_t row_size() const
Returns the effective size of a row, in bits.
Definition: RowStore.hpp:40
void dump() const
Definition: Store.cpp:14
std::size_t num_rows_
the number of rows in use
Definition: RowStore.hpp:22
uint32_t * offsets_
the offsets from the first column, in bits, of all columns
Definition: RowStore.hpp:24
memory::LinearAllocator allocator_
the memory allocator
Definition: RowStore.hpp:20
const memory::Memory & memory() const override
Returns the memory of the store.
Definition: RowStore.hpp:54
int offset(uint32_t idx) const
Definition: RowStore.hpp:33
void append() override
Append a row to the store.
Definition: RowStore.hpp:42
std::size_t capacity_
the number of available rows
Definition: RowStore.hpp:23
uint32_t row_size_
the size of a row, in bits; includes NULL bitmap and other meta data
Definition: RowStore.hpp:25
static constexpr std::size_t ALLOCATION_SIZE
1 GiB
Definition: RowStore.hpp:14
void memory(memory::Memory memory)
Sets the memory of the store to memory.
Definition: RowStore.hpp:56
void compute_offsets()
Computes the offsets of the attributes within a row.
Definition: RowStore.cpp:31
virtual std::size_t num_rows() const override
Return the number of rows in this store.
Definition: RowStore.hpp:31
uintptr_t at(std::size_t idx) const
Return a pointer to the idxth row.
Definition: RowStore.hpp:67
Defines a generic store interface.
Definition: Store.hpp:22
void dump() const
Definition: Store.cpp:14
const Table & table() const
Definition: Store.hpp:36
A table is a sorted set of attributes.
Definition: Schema.hpp:388
This is the simplest kind of allocator.
Definition: memory.hpp:139
Represents a mapping created by a memory::Allocator.
Definition: memory.hpp:78
T as()
Returns a pointer to the beginning of the virtual address space where this allocation is mapped to,...
Definition: memory.hpp:118