orbtree
Classes | Protected Types | Protected Member Functions | Protected Attributes | Static Protected Attributes | List of all members
orbtree::NodeAllocatorPtr< KeyValueT, NVTypeT, simple > Class Template Reference

Basic allocator that allocates each node individually, using C++ new / delete and pointers. Can throw exception if out of memory. More...

#include <orbtree_node.h>

Collaboration diagram for orbtree::NodeAllocatorPtr< KeyValueT, NVTypeT, simple >:
Collaboration graph
[legend]

Classes

struct  Node
 node class More...
 

Protected Types

typedef KeyValueT KeyValue
 
typedef NVTypeT NVType
 
typedef const NodeNodeHandle
 Node handle type to be used by tree implementation. More...
 

Protected Member Functions

unsigned int get_nv_per_node () const
 
 NodeAllocatorPtr (unsigned int nv_per_node_)
 
Nodeget_node (NodeHandle x)
 get reference to a modifiable node
 
const Nodeget_node (const NodeHandle x) const
 get reference to a const node
 
Nodenew_node ()
 get new node More...
 
Nodenew_node (const KeyValue &kv)
 get new node More...
 
Nodenew_node (KeyValue &&kv)
 get new node More...
 
template<class... T>
Nodenew_node (T &&... kv)
 get new node More...
 
void free_node (NodeHandle n)
 delete node – tree is not traversed, the caller must arrange to "cut" out the node in question (otherwise the referenced nodes will be lost)
 
void clear_tree ()
 clear tree, i.e. free all nodes, but keep root (sentinel) and nil, so that tree can be used again
 
void free_tree_nodes_r (Node *n)
 free whole tree (starting from root)
 
template<bool simple_ = simple>
void init_node (typename std::enable_if< simple_, Node *>::type n)
 safely initialize new node, throw an exception if memory allocation failed
 
template<bool simple_ = simple>
void init_node (typename std::enable_if<!simple_, Node *>::type n)
 safely initialize new node, throw an exception if memory allocation failed
 
template<bool simple_ = simple>
void get_node_sum (NodeHandle n, typename std::enable_if< simple_, NVType *>::type s) const
 get the value of the partial sum of weights stored in this node – simple case when the weight function returns only one value
 
template<bool simple_ = simple>
void get_node_sum (NodeHandle n, typename std::enable_if<!simple_, NVType *>::type s) const
 get the value of the partial sum of weights stored in this node – case when the weight function returns a vector
 
template<bool simple_ = simple>
void set_node_sum (NodeHandle n1, typename std::enable_if< simple_, const NVType *>::type s)
 set the value of the partial sum stored in this node – simple case when the weight function returns only one value
 
template<bool simple_ = simple>
void set_node_sum (NodeHandle n1, typename std::enable_if<!simple_, const NVType *>::type s)
 set the value of the partial sum stored in this node – case when the weight function returns a vector
 

Protected Attributes

Noderoot
 Root sentinel, allocated automatically, used when freeing the tree.
 
Nodenil
 Sentinel for nil.
 
const unsigned int nv_per_node
 each node has nv_per_node values calculated and stored in it
 

Static Protected Attributes

static constexpr NodeInvalid = 0
 invalid handle
 
static const size_t max_nodes = 0
 maximum number of nodes – unlimited
 

Detailed Description

template<class KeyValueT, class NVTypeT, bool simple = false>
class orbtree::NodeAllocatorPtr< KeyValueT, NVTypeT, simple >

Basic allocator that allocates each node individually, using C++ new / delete and pointers. Can throw exception if out of memory.

Template Parameters
KeyValueTType of stored data, should be either KeyOnly or KeyValue
NVTypeTType of extra data stored along in nodes (i.e. the return value of the function whose sum can be calculated).

Member Typedef Documentation

◆ NodeHandle

template<class KeyValueT , class NVTypeT , bool simple = false>
typedef const Node* orbtree::NodeAllocatorPtr< KeyValueT, NVTypeT, simple >::NodeHandle
protected

Node handle type to be used by tree implementation.

Note: NodeHandle is always const to make it easier to return it from const nodes; whether a node can be modified depends if this class is const.

Member Function Documentation

◆ new_node() [1/4]

template<class KeyValueT , class NVTypeT , bool simple = false>
Node* orbtree::NodeAllocatorPtr< KeyValueT, NVTypeT, simple >::new_node ( )
inlineprotected

get new node

It is the callers responsibility to store the handle in the tree or otherwise remember and free it later. Will throw an exception if allocation failed.

◆ new_node() [2/4]

template<class KeyValueT , class NVTypeT , bool simple = false>
Node* orbtree::NodeAllocatorPtr< KeyValueT, NVTypeT, simple >::new_node ( const KeyValue &  kv)
inlineprotected

get new node

It is the callers responsibility to store the handle in the tree or otherwise remember and free it later. Will throw an exception if allocation failed.

◆ new_node() [3/4]

template<class KeyValueT , class NVTypeT , bool simple = false>
Node* orbtree::NodeAllocatorPtr< KeyValueT, NVTypeT, simple >::new_node ( KeyValue &&  kv)
inlineprotected

get new node

It is the callers responsibility to store the handle in the tree or otherwise remember and free it later. Will throw an exception if allocation failed.

◆ new_node() [4/4]

template<class KeyValueT , class NVTypeT , bool simple = false>
template<class... T>
Node* orbtree::NodeAllocatorPtr< KeyValueT, NVTypeT, simple >::new_node ( T &&...  kv)
inlineprotected

get new node

It is the callers responsibility to store the handle in the tree or otherwise remember and free it later. Will throw an exception if allocation failed.


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