TPIE

11a2c2d
tpie::linear_memory_base< child_t > Struct Template Reference

Base class of data structures with linear memory usage. More...

#include <tpie/util.h>

Inherited by tpie::internal_stack_vector_base< T, child_t >.

Static Public Member Functions

static constexpr memory_size_type memory_usage (memory_size_type size) noexcept
 Return the number of bytes required to create a data structure supporting a given number of elements. More...
 
static constexpr memory_size_type memory_fits (memory_size_type memory) noexcept
 Return the maximum number of elements that can be contained in in the structure when it is allowed to fill a given number of bytes. More...
 
static constexpr linear_memory_usage memory_usage () noexcept
 

Detailed Description

template<typename child_t>
struct tpie::linear_memory_base< child_t >

Base class of data structures with linear memory usage.

Uses CRTP to defer the definition of memory_coefficient and memory_overhead which must be implemented in the subclass.

Defines two static methods, memory_usage and memory_fits, that determine the amount of memory used and the number of items for a given memory amount, respectively.

Definition at line 98 of file util.h.

Member Function Documentation

◆ memory_fits()

template<typename child_t >
static constexpr memory_size_type tpie::linear_memory_base< child_t >::memory_fits ( memory_size_type  memory)
inlinestaticconstexprnoexcept

Return the maximum number of elements that can be contained in in the structure when it is allowed to fill a given number of bytes.

Parameters
memoryThe number of bytes the structure is allowed to occupy
Returns
The number of elements that will fit in the structure

Definition at line 118 of file util.h.

118  {
119  return static_cast<memory_size_type>(
120  floor((memory - child_t::memory_overhead()) / child_t::memory_coefficient()));
121  }

◆ memory_usage()

template<typename child_t >
static constexpr memory_size_type tpie::linear_memory_base< child_t >::memory_usage ( memory_size_type  size)
inlinestaticconstexprnoexcept

Return the number of bytes required to create a data structure supporting a given number of elements.

Parameters
sizeThe number of elements to support
Returns
The amount of memory required in bytes

Definition at line 106 of file util.h.

106  {
107  return static_cast<memory_size_type>(
108  floor(static_cast<double>(size) * child_t::memory_coefficient() + child_t::memory_overhead()));
109  }

The documentation for this struct was generated from the following file: