pstore2
Public Types | Public Member Functions | List of all members
pstore::index::details::linear_node Class Reference

A linear node. More...

#include <hamt_map_types.hpp>

Public Types

using iterator = address *
 
using const_iterator = address const *
 

Public Member Functions

void * operator new (std::size_t)=delete
 
void operator delete (void *p)
 
 linear_node (linear_node &&rhs) noexcept=delete
 
linear_nodeoperator= (linear_node const &rhs)=delete
 
linear_nodeoperator= (linear_node &&rhs) noexcept=delete
 
address flush (transaction_base &transaction) const
 Write this linear node to the store. More...
 
template<typename KeyType , typename OtherKeyType , typename KeyEqual , typename = typename std::enable_if< serialize::is_compatible<KeyType, OtherKeyType>::value>::type>
auto lookup (database const &db, OtherKeyType const &key, KeyEqual equal) const -> std::pair< index_pointer const, std::size_t >
 Search the linear node and return the child slot if the key exists. More...
 
Element access
address operator[] (std::size_t const i) const noexcept
 
addressoperator[] (std::size_t const i) noexcept
 
Iterators
iterator begin ()
 
const_iterator begin () const
 
const_iterator cbegin () const
 
iterator end ()
 
const_iterator end () const
 
const_iterator cend () const
 
Capacity
bool empty () const
 Checks whether the container is empty.
 
std::size_t size () const
 Returns the number of elements.
 

Static Public Member Functions

Construction
static std::unique_ptr< linear_nodeallocate_from (linear_node const &orig_node, std::size_t extra_children)
 Allocates a new linear node in memory and copy the contents of an existing node into it. More...
 
static std::unique_ptr< linear_nodeallocate_from (database const &db, index_pointer const node, std::size_t extra_children)
 Allocates a new in-memory linear node based on the contents of an existing store node. More...
 
static std::unique_ptr< linear_nodeallocate (address a, address b)
 Allocates a new linear node in memory with sufficient space for two leaf addresses. More...
 
static auto get_node (database const &db, index_pointer const node) -> std::pair< std::shared_ptr< linear_node const >, linear_node const *>
 Returns a pointer to a linear node which may be in-heap or in-store. More...
 

Storage

std::size_t size_bytes () const
 Returns the number of bytes of storage required for the node.
 
static constexpr std::size_t size_bytes (std::uint64_t const size)
 Returns the number of bytes of storage required for a linear node with 'size' children. More...
 

Detailed Description

A linear node.

Linear nodes as used as the place of last resort for entries which cannot be distinguished by their hash value.

Member Function Documentation

◆ allocate()

std::unique_ptr< linear_node > pstore::index::details::linear_node::allocate ( address  a,
address  b 
)
static

Allocates a new linear node in memory with sufficient space for two leaf addresses.

Parameters
aThe first leaf address for the new linear node.
bThe second leaf address for the new linear node.
Returns
A pointer to the newly allocated linear node.

◆ allocate_from() [1/2]

std::unique_ptr< linear_node > pstore::index::details::linear_node::allocate_from ( linear_node const &  orig_node,
std::size_t  extra_children 
)
static

Allocates a new linear node in memory and copy the contents of an existing node into it.

The new node is allocated with sufficient storage for the child of the supplied node plus the number passed in the 'extra_children' parameter.

Parameters
orig_nodeA node whose contents will be copied into the newly allocated linear node.
extra_childrenThe number of extra child for which space will be allocated. This number is added to the number of children in 'orig_node' in calculating the amount of storage to be allocated.
Returns
A pointer to the newly allocated linear node.

◆ allocate_from() [2/2]

std::unique_ptr< linear_node > pstore::index::details::linear_node::allocate_from ( database const &  db,
index_pointer const  node,
std::size_t  extra_children 
)
static

Allocates a new in-memory linear node based on the contents of an existing store node.

Parameters
dbThe database from which the source node should be loaded.
nodeA reference to the source node which may be either in-heap or in-store.
extra_childrenThe number of additional child nodes for which storage should be allocated.
Returns
A pointer to the newly allocated linear node.

◆ flush()

address pstore::index::details::linear_node::flush ( transaction_base transaction) const

Write this linear node to the store.

Parameters
transactionThe transaction to which the linear node will be appended.
Returns
The address at which the node was written.

◆ get_node()

auto pstore::index::details::linear_node::get_node ( database const &  db,
index_pointer const  node 
) -> std::pair<std::shared_ptr<linear_node const>, linear_node const *>
static

Returns a pointer to a linear node which may be in-heap or in-store.

If the supplied index_pointer points to a heap-resident linear node then returns a pair whose first member is nullptr and whose second member contains the node pointer. If the index_pointer references an in-store linear node then the node is fetched and the function returns a pair whose first member is the store's shared_ptr and whose second member is the equivalent raw pointer (i.e. result.first.get () == result.second). In this case, the second pointer is only valid as long as the first pointer is "live".

Parameters
dbThe database from which the node should be loaded.
nodeA pointer to the node location: either in the heap or in the store.
Returns
A pair holding a pointer to the node in-store memory (if necessary) and its raw pointer.

◆ lookup()

template<typename KeyType , typename OtherKeyType , typename KeyEqual , typename >
auto pstore::index::details::linear_node::lookup ( database const &  db,
OtherKeyType const &  key,
KeyEqual  equal 
) const -> std::pair<index_pointer const, std::size_t>

Search the linear node and return the child slot if the key exists.

Otherwise, return the {nullptr, not_found} pair.

Template Parameters
KeyTypeThe type of the keys stored in the linear node.
OtherKeyTypeA type whose serialized value is compatible with KeyType
KeyEqualThe type of the key-comparison function.
Parameters
dbThe dataase instance from which child nodes should be loaded.
keyThe key to be located.
equalA comparison function which will be called to compare child nodes to the supplied key value. It should return true if the keys match and false otherwise.
Returns
If found, returns an index_pointer reference to the child node and the position within the linear node instance of the child record. If not found, returns the pair index_pointer (), details::not_found.

◆ size_bytes()

static constexpr std::size_t pstore::index::details::linear_node::size_bytes ( std::uint64_t const  size)
inlinestatic

Returns the number of bytes of storage required for a linear node with 'size' children.


The documentation for this class was generated from the following files: