LCOV - code coverage report
Current view: top level - src/storage - RowStore.hpp (source / functions) Hit Total Coverage
Test: coverage.info Lines: 16 16 100.0 %
Date: 2025-03-25 01:19:55 Functions: 7 7 100.0 %
Branches: 3 4 75.0 %

           Branch data     Line data    Source code
       1                 :            : #pragma once
       2                 :            : 
       3                 :            : #include <mutable/catalog/Schema.hpp>
       4                 :            : #include <mutable/storage/Store.hpp>
       5                 :            : #include <mutable/util/memory.hpp>
       6                 :            : 
       7                 :            : 
       8                 :            : namespace m {
       9                 :            : 
      10                 :            : /** This class implements a row store. */
      11                 :            : struct RowStore : Store
      12                 :            : {
      13                 :            : #ifndef NDEBUG
      14                 :            :     static constexpr std::size_t ALLOCATION_SIZE = 1UL << 30; ///< 1 GiB
      15                 :            : #else
      16                 :            :     static constexpr std::size_t ALLOCATION_SIZE = 1UL << 37; ///< 128 GiB
      17                 :            : #endif
      18                 :            : 
      19                 :            :     private:
      20                 :            :     memory::LinearAllocator allocator_; ///< the memory allocator
      21                 :            :     memory::Memory data_; ///< the underlying memory containing the data
      22                 :            :     std::size_t num_rows_ = 0; ///< the number of rows in use
      23                 :            :     std::size_t capacity_; ///< the number of available rows
      24                 :            :     uint32_t *offsets_; ///< the offsets from the first column, in bits, of all columns
      25                 :            :     uint32_t row_size_; ///< the size of a row, in bits; includes NULL bitmap and other meta data
      26                 :            : 
      27                 :            :     public:
      28                 :            :     RowStore(const Table &table);
      29                 :            :     ~RowStore();
      30                 :            : 
      31                 :     524113 :     virtual std::size_t num_rows() const override { return num_rows_; }
      32                 :            : 
      33                 :         10 :     int offset(uint32_t idx) const {
      34                 :         10 :         M_insist(idx <= table().num_attrs(), "index out of range");
      35                 :         10 :         return offsets_[idx];
      36                 :            :     }
      37                 :         10 :     int offset(const Attribute &attr) const { return offset(attr.id); }
      38                 :            : 
      39                 :            :     /** Returns the effective size of a row, in bits. */
      40                 :          1 :     std::size_t row_size() const { return row_size_; }
      41                 :            : 
      42                 :     524102 :     void append() override {
      43         [ +  + ]:     524102 :         if (num_rows_ == capacity_)
      44         [ +  - ]:          1 :             throw std::logic_error("row store exceeds capacity");
      45                 :     524101 :         ++num_rows_;
      46                 :     524101 :     }
      47                 :            : 
      48                 :          5 :     void drop() override {
      49                 :          5 :         M_insist(num_rows_);
      50                 :          5 :         --num_rows_;
      51                 :          5 :     }
      52                 :            : 
      53                 :            :     /** Returns the memory of the store. */
      54                 :         42 :     const memory::Memory & memory() const override { return data_; }
      55                 :            :     /** Sets the memory of the store to `memory`. */
      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:
      62                 :            :     /** Computes the offsets of the attributes within a row.  Tries to minimize the row size by storing the attributes
      63                 :            :      * in descending order of their size, avoiding padding.  */
      64                 :            :     void compute_offsets();
      65                 :            : 
      66                 :            :     /** Return a pointer to the `idx`th row. */
      67                 :            :     uintptr_t at(std::size_t idx) const { return data_.as<uintptr_t>() + row_size_/8 * idx; }
      68                 :            : };
      69                 :            : 
      70                 :            : }

Generated by: LCOV version 1.16