47 virtual void dump(std::ostream &out)
const = 0;
48 virtual void dump()
const = 0;
80 template<
typename T,
typename U>
81 requires (std::same_as<T, key_type> or std::same_as<T, entry_type>)
and
82 (std::same_as<U, key_type> or std::same_as<U, entry_type>)
83 bool operator()(
const T &_lhs,
const U &_rhs)
const {
86 if constexpr(std::same_as<key_type, const char*>)
87 return std::strcmp(lhs,
rhs) < 0;
156 void dump(std::ostream &out)
const override { out <<
"ArrayIndex<" <<
typeid(
key_type).name() <<
'>' << std::endl; }
161template<arithmetic Key>
182 const std::size_t offset = 0,
const double compression_factor = 1.0)
184 std::size_t n = std::distance(first, last);
185 if (n == 0)
return { 0.0, 0.0 };
186 if (n == 1)
return { 0.0,
static_cast<double>(offset) * compression_factor };
187 double numerator =
static_cast<double>(n);
188 double denominator =
static_cast<double>((*(last - 1)).first - (*first).first);
189 double slope = denominator != 0 ? numerator/denominator * compression_factor : 0.0;
190 double intercept = offset * compression_factor -
slope * (*first).first;
197 const std::size_t offset = 0,
const double compression_factor = 1.0)
199 std::size_t n = std::distance(first, last);
200 if (n == 0)
return { 0.0, 0.0 };
201 if (n == 1)
return { 0.0,
static_cast<double>(offset) * compression_factor };
208 for (std::size_t i = 0; i != n; ++i) {
209 auto x = (*(first + i)).first;
210 std::size_t y = offset + i;
212 double dx = x - mean_x;
213 mean_x += dx / (i + 1);
214 mean_y += (y - mean_y) / (i + 1);
215 c += dx * (y - mean_y);
217 double dx2 = x - mean_x;
221 double cov = c / (n - 1);
222 double var = m2 / (n - 1);
224 if (var == 0.f)
return { 0.0, mean_y };
226 double slope = cov / var * compression_factor;
266 void dump(std::ostream &out)
const override { out <<
"RecursiveModelIndex<" <<
typeid(
key_type).name() <<
'>' << std::endl; }
271 auto segment_id = std::clamp<double>(
models_[0](key), 0,
models_.size() - 2);
273 return static_cast<std::size_t
>(pred);
278 std::size_t bound = 1;
281 auto curr = prev + bound;
290 auto curr = prev - bound;
302 std::size_t bound = 1;
305 auto curr = prev + bound;
314 auto curr = prev - bound;
325#define M_INDEX_LIST_TEMPLATED(X) \
326 X(m::idx::ArrayIndex<bool>) \
327 X(m::idx::ArrayIndex<int8_t>) \
328 X(m::idx::ArrayIndex<int16_t>) \
329 X(m::idx::ArrayIndex<int32_t>) \
330 X(m::idx::ArrayIndex<int64_t>) \
331 X(m::idx::ArrayIndex<float>) \
332 X(m::idx::ArrayIndex<double>) \
333 X(m::idx::ArrayIndex<const char*>) \
334 X(m::idx::RecursiveModelIndex<int8_t>) \
335 X(m::idx::RecursiveModelIndex<int16_t>) \
336 X(m::idx::RecursiveModelIndex<int32_t>) \
337 X(m::idx::RecursiveModelIndex<int64_t>) \
338 X(m::idx::RecursiveModelIndex<float>) \
339 X(m::idx::RecursiveModelIndex<double>)
346#define DECLARE(CLASS) \
347 extern template struct CLASS;
#define M_INDEX_LIST_TEMPLATED(X)
#define M_CONSTEXPR_COND(COND, IF_TRUE, IF_FALSE)
IndexMethod
An enum class that lists all supported index methods.
and arithmetic< U > and same_signedness< T, U > U
A Schema represents a sequence of identifiers, optionally with a prefix, and their associated types.
A table is a sorted set of attributes.
A simple index based on a sorted array that maps keys to their tuple_id.
const_iterator cend() const
static constexpr std::size_t ALLOCATION_SIZE
1 GiB
bool finalized() const
Returns true iff the index is currently finalized.
const memory::Memory & memory() const override
Returns the underlying memory of the index.
IndexMethod method() const override
Returns the IndexMethod of the index.
virtual const_iterator upper_bound(const key_type key) const
Returns an iterator pointing to the first entry of the vector such that entry.key < key is true,...
std::size_t num_entries() const override
Returns the number of entries in the index.
const entry_type * const_iterator
memory::Memory memory_
the underlying memory for a vector holding the index entries consisting of pairs of key and value
void bulkload(const Table &table, const Schema &key_schema) override
Bulkloads the index from table on the key contained in key_schema by executing a query and adding one...
const_iterator end() const
const_iterator cbegin() const
std::pair< key_type, value_type > entry_type
iterator begin()
Returns an iterator pointing to the first entry of the index.
void dump(std::ostream &out) const override
std::size_t size_in_bytes() const override
void add(const key_type key, const value_type value)
Adds a single pair of key and value to the index.
struct m::idx::ArrayIndex::@3 cmp
Custom comparator class to handle the special case of.
std::size_t num_entries_
number of entries
bool finalized_
flag to signalize whether index is finalized, i.e. array is sorted
const_iterator begin() const
virtual const_iterator lower_bound(const key_type key) const
Returns an iterator pointing to the first entry of the vector such that entry.key < key is false,...
iterator end()
Returns an interator pointing to the first element following the last entry of the index.
virtual void finalize()
Sorts the underlying vector and flags the index as finalized.
void dump() const override
The base class for indexes.
IndexBase(IndexBase &&)=default
virtual void dump() const =0
virtual const memory::Memory & memory() const =0
Returns the underlying memory of the index.
virtual void dump(std::ostream &out) const =0
virtual std::size_t num_entries() const =0
static std::string build_query(const Table &table, const Schema &schema)
Constructs a query string to select all attributes in schema from table.
virtual std::size_t size_in_bytes() const =0
virtual void bulkload(const Table &table, const Schema &key_schema)=0
Bulkloads the index by executing a query on table using key_schema.
virtual IndexMethod method() const =0
Returns the IndexMethod of the index.
LinearModel(double slope, double intercept)
static LinearModel train_linear_regression(const_iterator first, const_iterator last, const std::size_t offset=0, const double compression_factor=1.0)
Builds a linear regression model from all data points between the first and last .
static LinearModel train_linear_spline(const_iterator first, const_iterator last, const std::size_t offset=0, const double compression_factor=1.0)
Builds a linear spline model between the first and last data point.
double operator()(const key_type x) const
A recursive model index with two layers consiting only of linear monels that maps keys to their tuple...
std::size_t size_in_bytes() const override
const_iterator lower_bound(const key_type key) const override
Returns an iterator pointing to the first entry of the vector such that entry.key < key is false,...
void finalize() override
Sorts the underlying vector, builds the linear models, and flags the index as finalized.
const memory::Memory & memory() const override
Returns the underlying memory of the index.
base_type::entry_type entry_type
base_type::value_type value_type
base_type::key_type key_type
std::vector< LinearModel > models_
A vector of linear models to index the underlying data.
const_iterator lower_bound_exponential_search(const_iterator pred, const key_type value) const
const_iterator upper_bound(const key_type key) const override
Returns an iterator pointing to the first entry of the vector such that entry.key < key is true,...
void dump(std::ostream &out) const override
const_iterator upper_bound_exponential_search(const_iterator pred, const key_type value) const
base_type::const_iterator const_iterator
std::size_t predict(const key_type key) const
IndexMethod method() const override
Returns the IndexMethod of the index.
void dump() const override
Represents a mapping created by a memory::Allocator.
void * addr() const
Returns a pointer to the beginning of the virtual address space where this allocation is mapped to.
Signals a runtime error that mu*t*able is not responsible for and that mu*t*able was not able to reco...