Aleph-w 7.10.0
A C++ Library for Data Structures and Algorithms
Loading...
Searching...
No Matches
Aleph::negative_cycles_detail::Node_Index< Node > Class Template Reference

Map from node pointers to their positions, built once and never modified afterwards. More...

#include <Negative_Cycles.H>

Collaboration diagram for Aleph::negative_cycles_detail::Node_Index< Node >:
[legend]

Public Member Functions

 Node_Index (const size_t n)
 
void insert (Node *node, const size_t position)
 Record that node (not yet inserted) is at position.
 
size_t find (const Node *node) const
 Position of node.
 

Static Private Member Functions

static size_t slot_of (const Node *node) noexcept
 

Private Attributes

Array< Node * > keys_
 
Array< size_t > positions_
 
size_t mask_ = 0
 

Detailed Description

template<typename Node>
class Aleph::negative_cycles_detail::Node_Index< Node >

Map from node pointers to their positions, built once and never modified afterwards.

Open addressing with linear probing over two Arrays whose capacity is the first power of two not below 2 * n, so the load factor never exceeds one half and a lookup takes about 1.5 probes. Pointers are mixed with the SplitMix64 finalizer, a bijection of the 64-bit pointer, before the low bits select the slot: allocation patterns (nodes at a fixed stride, for instance) cannot cluster. Compared with an AVL map (DynMapTree) it makes four allocations instead of one per node, and a lookup does not chase pointers.

Template Parameters
NodeNode type; pointers to it are the keys and are never null.

Definition at line 847 of file Negative_Cycles.H.

Constructor & Destructor Documentation

◆ Node_Index()

template<typename Node >
Aleph::negative_cycles_detail::Node_Index< Node >::Node_Index ( const size_t  n)
inlineexplicit
Parameters
[in]nNumber of nodes that will be inserted.
Exceptions
std::overflow_errorIf the capacity does not fit size_t.

Definition at line 866 of file Negative_Cycles.H.

References ah_overflow_error_if, Aleph::negative_cycles_detail::Node_Index< Node >::keys_, Aleph::negative_cycles_detail::Node_Index< Node >::mask_, and Aleph::negative_cycles_detail::Node_Index< Node >::positions_.

Member Function Documentation

◆ find()

template<typename Node >
size_t Aleph::negative_cycles_detail::Node_Index< Node >::find ( const Node *  node) const
inline

Position of node.

Exceptions
std::domain_errorIf node is null or was not inserted. A null key has to be rejected before probing: it would match the first free slot and answer with a position of nobody.

Definition at line 896 of file Negative_Cycles.H.

References ah_domain_error_if, Aleph::negative_cycles_detail::Node_Index< Node >::keys_, Aleph::negative_cycles_detail::Node_Index< Node >::mask_, Aleph::negative_cycles_detail::Node_Index< Node >::positions_, and Aleph::negative_cycles_detail::Node_Index< Node >::slot_of().

Referenced by Aleph::negative_cycles_detail::index_graph().

◆ insert()

template<typename Node >
void Aleph::negative_cycles_detail::Node_Index< Node >::insert ( Node *  node,
const size_t  position 
)
inline

◆ slot_of()

template<typename Node >
static size_t Aleph::negative_cycles_detail::Node_Index< Node >::slot_of ( const Node *  node)
inlinestaticprivatenoexcept

Member Data Documentation

◆ keys_

◆ mask_

◆ positions_


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