LCOV - code coverage report
Current view: top level - src/storage - ColumnStore.hpp (source / functions) Hit Total Coverage
Test: coverage.info Lines: 12 12 100.0 %
Date: 2025-03-25 01:19:55 Functions: 5 5 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 column store. */
      11                 :            : struct ColumnStore : 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_;
      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);
      28                 :            :     ~ColumnStore();
      29                 :            : 
      30                 :     526877 :     virtual std::size_t num_rows() const override { return num_rows_; }
      31                 :            : 
      32                 :            :     /** Returns the effective size of a row, in bits. */
      33                 :          1 :     std::size_t row_size() const { return row_size_; }
      34                 :            : 
      35                 :     708423 :     void append() override {
      36         [ +  + ]:     708423 :         if (num_rows_ == capacity_)
      37         [ +  - ]:          1 :             throw std::logic_error("row store exceeds capacity");
      38                 :     708422 :         ++num_rows_;
      39                 :     708422 :     }
      40                 :            : 
      41                 :          2 :     void drop() override {
      42                 :          2 :         M_insist(num_rows_);
      43                 :          2 :         --num_rows_;
      44                 :          2 :     }
      45                 :            : 
      46                 :            :     /** Returns the memory of the store. */
      47                 :        776 :     const memory::Memory & memory() const override { return data_; }
      48                 :            :     /** Returns the memory address where the column assigned to the attribute with id `attr_id` starts.
      49                 :            :      * Return the address of the NULL bitmap column if `attr_id == table().size()`. */
      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                 :            : }

Generated by: LCOV version 1.16