mutable
A Database System for Research and Fast Prototyping
Loading...
Searching...
No Matches
ColumnStore.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 std::size_t row_size_ = 0;
25
26 public:
27 ColumnStore(const Table &table);
29
30 virtual std::size_t num_rows() const override { return num_rows_; }
31
33 std::size_t row_size() const { return row_size_; }
34
35 void append() override {
36 if (num_rows_ == capacity_)
37 throw std::logic_error("row store exceeds capacity");
38 ++num_rows_;
39 }
40
41 void drop() override {
43 --num_rows_;
44 }
45
47 const memory::Memory & memory() const override { return data_; }
50 void * memory(std::size_t attr_id) const {
51 M_insist(attr_id <= table().num_attrs());
52 auto offset = ALLOCATION_SIZE * attr_id;
53 return reinterpret_cast<uint8_t*>(data_.addr()) + offset;
54 }
55
56 void dump(std::ostream &out) const override;
57 using Store::dump;
58};
59
60}
#define M_insist(...)
Definition: macro.hpp:129
‍mutable namespace
Definition: Backend.hpp:10
This class implements a column store.
Definition: ColumnStore.hpp:12
void * memory(std::size_t attr_id) const
Returns the memory address where the column assigned to the attribute with id attr_id starts.
Definition: ColumnStore.hpp:50
void dump() const
Definition: Store.cpp:14
void append() override
Append a row to the store.
Definition: ColumnStore.hpp:35
static constexpr std::size_t ALLOCATION_SIZE
1 GiB
Definition: ColumnStore.hpp:14
std::size_t row_size() const
Returns the effective size of a row, in bits.
Definition: ColumnStore.hpp:33
std::size_t capacity_
Definition: ColumnStore.hpp:23
const memory::Memory & memory() const override
Returns the memory of the store.
Definition: ColumnStore.hpp:47
virtual std::size_t num_rows() const override
Return the number of rows in this store.
Definition: ColumnStore.hpp:30
std::size_t num_rows_
Definition: ColumnStore.hpp:22
memory::Memory data_
Definition: ColumnStore.hpp:21
void drop() override
Drop the most recently appended row.
Definition: ColumnStore.hpp:41
std::size_t row_size_
Definition: ColumnStore.hpp:24
memory::LinearAllocator allocator_
the memory allocator
Definition: ColumnStore.hpp:20
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
void * addr() const
Returns a pointer to the beginning of the virtual address space where this allocation is mapped to.
Definition: memory.hpp:109