Aleph-w 7.10.0
A C++ Library for Data Structures and Algorithms
Loading...
Searching...
No Matches
Aleph::Gen_Interval_Tree< NodeType, T, Compare > Class Template Reference

Augmented treap storing intervals with overlap/stabbing queries. More...

#include <tpl_interval_tree.H>

Inheritance diagram for Aleph::Gen_Interval_Tree< NodeType, T, Compare >:
[legend]
Collaboration diagram for Aleph::Gen_Interval_Tree< NodeType, T, Compare >:
[legend]

Classes

struct  Iterator
 Inorder iterator over nodes. More...
 
struct  Step
 A step of the way down from the root: a node, and the side taken there. More...
 

Public Types

using Key = Interval< T >
 
using IntervalCmp = Interval_Less< T, Compare >
 
using Node = NodeType< Key >
 

Public Member Functions

void set_seed (const unsigned long seed)
 Seeds the Mersenne Twister of the tree, as gsl_rng_set() did: the priorities are from then on those of GSL for the seed.
 
IntervalCmp key_comp () const noexcept(std::is_nothrow_copy_constructible_v< Compare >)
 Return the interval comparison functor (over Interval<T> keys).
 
const Compare & endpoint_comp () const noexcept
 Return the endpoint comparison functor (const)
 
const Compare & get_compare () const noexcept
 Backwards-compatible accessor for the endpoint comparator.
 
void swap (Gen_Interval_Tree &tree) noexcept(noexcept(std::swap(tree_root, tree.tree_root)) and noexcept(std::swap(cmp, tree.cmp)) and noexcept(r.swap(tree.r)) and noexcept(std::swap(num_nodes, tree.num_nodes)))
 Swap all state with tree in O(1)
 
 Gen_Interval_Tree (const unsigned long seed, const Compare &_cmp=Compare())
 Construct with explicit seed and comparator: the priorities are those of GSL for the seed, drawn from a Mersenne Twister in dynamic memory.
 
 Gen_Interval_Tree (const Compare &_cmp=Compare())
 Construct without a seed: the priorities are drawn from a SplitMix64 with a seed of its own, inside the tree, which allocates nothing.
 
 Gen_Interval_Tree (const Gen_Interval_Tree &)=delete
 Deleted copy constructor.
 
Gen_Interval_Tree & operator= (const Gen_Interval_Tree &)=delete
 Deleted copy assignment.
 
 Gen_Interval_Tree (Gen_Interval_Tree &&)=delete
 Deleted move constructor.
 
Gen_Interval_Tree & operator= (Gen_Interval_Tree &&)=delete
 Deleted move assignment.
 
Random_Source & random_source () noexcept
 The source of random numbers, which gives the priorities.
 
const Random_Source & random_source () const noexcept
 The source of random numbers, to look at it: its engine, or whether it is equal to another one.
 
Gsl_Compatible_Rng & rng () const
 The Mersenne Twister of the tree, which a tree that was given no seed makes here, and draws from it from then on.
 
Node *& getRoot () noexcept
 Return the tree's root.
 
const Node * getRoot () const
 Return the tree's root (const)
 
size_t size () const noexcept
 Return the number of nodes.
 
bool is_empty () const noexcept
 Return true if the tree is empty.
 
void reset_num_nodes () noexcept
 Reset the node count (used after manual tree destruction)
 
const Node * search (const Key &key) const noexcept(std::is_nothrow_copy_constructible_v< Compare > and NothrowPredicateWith< const Compare &, const T &, const T & >)
 Search for an exact interval in the tree.
 
Node * insert (Node *p)
 Insert a node (no duplicates).
 
Node * insert_dup (Node *p)
 Insert a node (duplicates allowed).
 
Node * remove (const Key &key)
 Remove an interval from the tree.
 
const Node * overlap_search (const Key &query) const
 Find any interval that overlaps with query (CLRS algorithm).
 
template<class Op >
void all_overlaps (const Key &query, Op &&op) const
 Apply op to every interval overlapping query.
 
DynList< Key > find_all_overlaps (const Key &query) const
 Find all intervals overlapping query.
 
template<class Op >
void stab (const T &p, Op &&op) const
 Apply op to every interval containing point p.
 
DynList< Key > find_stab (const T &p) const
 Find all intervals containing point p.
 
bool verify () const
 Verify BST, heap, and max_endpoint invariants.
 

Private Types

using Pending = interval_tree_detail::Pending_Max< T >
 

Private Member Functions

Node *& link_from (Step *step) noexcept
 The link that hangs from a step: that of the root if there is none.
 
void place (Node *p, Step *bottom)
 Put a node in its place, at the end of the way down.
 
Node * insert (Node *root, Node *p, Step *up)
 Go down to the place of p and put it there, unless its interval is in the tree, which then gives Node::NullPtr and does not change.
 
void insert_dup (Node *root, Node *p, Step *up)
 Go down to the place of p and put it there, after the intervals that are the same as its own.
 
Node * join (Node *t1, Node *t2, Step *up, const Step *whole, Step *spine)
 Join two trees, every interval of the first one before those of the second one.
 
void unlink (Node *p, Step *up)
 Take a node out of the tree: its two subtrees, joined, take its place.
 
Node * remove (Node *root, const Key &key, Step *up)
 Go down to the node of the interval key and take it out of the tree.
 

Static Private Member Functions

static unsigned long generator_seed (const unsigned long seed) noexcept
 
static bool goes_before (const Key &a, const Key &b, const Compare &cmp)
 True if a goes before b: by its low endpoint, then by its high one.
 
static int side_of (const Key &a, const Key &b, const Compare &cmp)
 The side of b where a goes: -1 before it, 1 after it, and 0 if they are the same interval.
 
template<class Op >
static void all_overlaps (Node *root, const Key &query, Op &op, const Compare &cmp)
 Recursive: find all intervals overlapping query.
 
static bool check_max (Node *root, const Compare &cmp)
 Verify max_endpoint invariant.
 
static size_t count_nodes (Node *root) noexcept
 

Private Attributes

Node head
 
Node * head_ptr
 
Node *& tree_root
 
Random_Source r
 
Compare cmp
 
size_t num_nodes
 

Detailed Description

template<template< typename > class NodeType, typename T, class Compare = Aleph::less<T>>
requires StrictWeakOrder<Compare, T>
class Aleph::Gen_Interval_Tree< NodeType, T, Compare >

Augmented treap storing intervals with overlap/stabbing queries.

Gen_Interval_Tree is a standalone augmented treap that stores Interval<T> values and maintains a max_endpoint field in each node for efficient interval query pruning.

This is a low-level class managing raw node pointers. For automatic memory management, use DynIntervalTree.

Template Parameters
NodeTypeNode template (Interval_Tree_Node or Interval_Tree_NodeVtl).
TEndpoint type.
CompareComparison functor for endpoints.
Complexity:
  • Insert: O(log n) expected
  • Remove: O(log n) expected
  • overlap_search: O(log n) expected
  • all_overlaps: O(k log n) where k = number of results
  • stab: O(k log n)

Definition at line 604 of file tpl_interval_tree.H.

Member Typedef Documentation

◆ IntervalCmp

template<template< typename > class NodeType, typename T , class Compare = Aleph::less<T>>
using Aleph::Gen_Interval_Tree< NodeType, T, Compare >::IntervalCmp = Interval_Less<T, Compare>

Definition at line 608 of file tpl_interval_tree.H.

◆ Key

template<template< typename > class NodeType, typename T , class Compare = Aleph::less<T>>
using Aleph::Gen_Interval_Tree< NodeType, T, Compare >::Key = Interval<T>

Definition at line 607 of file tpl_interval_tree.H.

◆ Node

template<template< typename > class NodeType, typename T , class Compare = Aleph::less<T>>
using Aleph::Gen_Interval_Tree< NodeType, T, Compare >::Node = NodeType<Key>

Definition at line 609 of file tpl_interval_tree.H.

◆ Pending

template<template< typename > class NodeType, typename T , class Compare = Aleph::less<T>>
using Aleph::Gen_Interval_Tree< NodeType, T, Compare >::Pending = interval_tree_detail::Pending_Max<T>
private

Definition at line 627 of file tpl_interval_tree.H.

Constructor & Destructor Documentation

◆ Gen_Interval_Tree() [1/4]

template<template< typename > class NodeType, typename T , class Compare = Aleph::less<T>>
Aleph::Gen_Interval_Tree< NodeType, T, Compare >::Gen_Interval_Tree ( const unsigned long  seed,
const Compare &  _cmp = Compare() 
)
inline

Construct with explicit seed and comparator: the priorities are those of GSL for the seed, drawn from a Mersenne Twister in dynamic memory.

Parameters
[in]seedRandom seed, taken through an unsigned int, modulo 2^32 - 1, as it was for GSL.
[in]_cmpComparison functor.
Exceptions
std::bad_allocif the Mersenne Twister cannot be allocated.

Definition at line 1006 of file tpl_interval_tree.H.

References Aleph::Gen_Interval_Tree< NodeType, T, Compare >::head_ptr, Aleph::Min_Priority, and Aleph::PRIO().

◆ Gen_Interval_Tree() [2/4]

template<template< typename > class NodeType, typename T , class Compare = Aleph::less<T>>
Aleph::Gen_Interval_Tree< NodeType, T, Compare >::Gen_Interval_Tree ( const Compare &  _cmp = Compare())
inline

Construct without a seed: the priorities are drawn from a SplitMix64 with a seed of its own, inside the tree, which allocates nothing.

Parameters
[in]_cmpComparison functor.

Definition at line 1020 of file tpl_interval_tree.H.

References Aleph::Gen_Interval_Tree< NodeType, T, Compare >::head_ptr, Aleph::Min_Priority, and Aleph::PRIO().

◆ Gen_Interval_Tree() [3/4]

template<template< typename > class NodeType, typename T , class Compare = Aleph::less<T>>
Aleph::Gen_Interval_Tree< NodeType, T, Compare >::Gen_Interval_Tree ( const Gen_Interval_Tree< NodeType, T, Compare > &  )
delete

Deleted copy constructor.

◆ Gen_Interval_Tree() [4/4]

template<template< typename > class NodeType, typename T , class Compare = Aleph::less<T>>
Aleph::Gen_Interval_Tree< NodeType, T, Compare >::Gen_Interval_Tree ( Gen_Interval_Tree< NodeType, T, Compare > &&  )
delete

Deleted move constructor.

Member Function Documentation

◆ all_overlaps() [1/2]

template<template< typename > class NodeType, typename T , class Compare = Aleph::less<T>>
template<class Op >
void Aleph::Gen_Interval_Tree< NodeType, T, Compare >::all_overlaps ( const Key &  query,
Op &&  op 
) const
inline

Apply op to every interval overlapping query.

Parameters
querythe query interval
opcallable with signature void(const Interval<T>&)
Complexity: O(k log n) where k = number of overlapping intervals

Definition at line 1202 of file tpl_interval_tree.H.

References Aleph::Gen_Interval_Tree< NodeType, T, Compare >::all_overlaps(), Aleph::Gen_Interval_Tree< NodeType, T, Compare >::cmp, and Aleph::Gen_Interval_Tree< NodeType, T, Compare >::tree_root.

◆ all_overlaps() [2/2]

template<template< typename > class NodeType, typename T , class Compare = Aleph::less<T>>
template<class Op >
static void Aleph::Gen_Interval_Tree< NodeType, T, Compare >::all_overlaps ( Node *  root,
const Key &  query,
Op &  op,
const Compare &  cmp 
)
inlinestaticprivate

◆ check_max()

template<template< typename > class NodeType, typename T , class Compare = Aleph::less<T>>
static bool Aleph::Gen_Interval_Tree< NodeType, T, Compare >::check_max ( Node *  root,
const Compare &  cmp 
)
inlinestaticprivate

◆ count_nodes()

template<template< typename > class NodeType, typename T , class Compare = Aleph::less<T>>
static size_t Aleph::Gen_Interval_Tree< NodeType, T, Compare >::count_nodes ( Node *  root)
inlinestaticprivatenoexcept

◆ endpoint_comp()

template<template< typename > class NodeType, typename T , class Compare = Aleph::less<T>>
const Compare & Aleph::Gen_Interval_Tree< NodeType, T, Compare >::endpoint_comp ( ) const
inlinenoexcept

◆ find_all_overlaps()

template<template< typename > class NodeType, typename T , class Compare = Aleph::less<T>>
DynList< Key > Aleph::Gen_Interval_Tree< NodeType, T, Compare >::find_all_overlaps ( const Key &  query) const
inline

Find all intervals overlapping query.

Parameters
querythe query interval
Returns
DynList of overlapping intervals

Definition at line 1212 of file tpl_interval_tree.H.

References Aleph::Gen_Interval_Tree< NodeType, T, Compare >::all_overlaps(), and Aleph::DynList< T >::append().

Referenced by Aleph::DynIntervalTree< T, Compare >::find_all_overlaps(), and Aleph::Gen_Interval_Tree< NodeType, T, Compare >::find_stab().

◆ find_stab()

template<template< typename > class NodeType, typename T , class Compare = Aleph::less<T>>
DynList< Key > Aleph::Gen_Interval_Tree< NodeType, T, Compare >::find_stab ( const T &  p) const
inline

Find all intervals containing point p.

Parameters
pthe query point
Returns
DynList of intervals containing p

Definition at line 1239 of file tpl_interval_tree.H.

References Aleph::Gen_Interval_Tree< NodeType, T, Compare >::find_all_overlaps(), and Aleph::Interval< T >::point().

Referenced by Aleph::DynIntervalTree< T, Compare >::find_stab().

◆ generator_seed()

template<template< typename > class NodeType, typename T , class Compare = Aleph::less<T>>
static unsigned long Aleph::Gen_Interval_Tree< NodeType, T, Compare >::generator_seed ( const unsigned long  seed)
inlinestaticprivatenoexcept

Definition at line 621 of file tpl_interval_tree.H.

References Aleph::Gsl_Compatible_Rng::max(), and seed.

◆ get_compare()

template<template< typename > class NodeType, typename T , class Compare = Aleph::less<T>>
const Compare & Aleph::Gen_Interval_Tree< NodeType, T, Compare >::get_compare ( ) const
inlinenoexcept

Backwards-compatible accessor for the endpoint comparator.

Definition at line 982 of file tpl_interval_tree.H.

References Aleph::Gen_Interval_Tree< NodeType, T, Compare >::endpoint_comp().

◆ getRoot() [1/2]

template<template< typename > class NodeType, typename T , class Compare = Aleph::less<T>>
const Node * Aleph::Gen_Interval_Tree< NodeType, T, Compare >::getRoot ( ) const
inline

Return the tree's root (const)

Definition at line 1075 of file tpl_interval_tree.H.

References Aleph::Gen_Interval_Tree< NodeType, T, Compare >::tree_root.

◆ getRoot() [2/2]

template<template< typename > class NodeType, typename T , class Compare = Aleph::less<T>>
Node *& Aleph::Gen_Interval_Tree< NodeType, T, Compare >::getRoot ( )
inlinenoexcept

◆ goes_before()

template<template< typename > class NodeType, typename T , class Compare = Aleph::less<T>>
static bool Aleph::Gen_Interval_Tree< NodeType, T, Compare >::goes_before ( const Key &  a,
const Key &  b,
const Compare &  cmp 
)
inlinestaticprivate

True if a goes before b: by its low endpoint, then by its high one.

It is Interval_Less, without a copy of the comparator.

Definition at line 648 of file tpl_interval_tree.H.

References Aleph::Gen_Interval_Tree< NodeType, T, Compare >::cmp, Aleph::Interval< T >::high, and Aleph::Interval< T >::low.

Referenced by Aleph::Gen_Interval_Tree< NodeType, T, Compare >::insert_dup().

◆ insert() [1/2]

template<template< typename > class NodeType, typename T , class Compare = Aleph::less<T>>
Node * Aleph::Gen_Interval_Tree< NodeType, T, Compare >::insert ( Node *  p)
inline

Insert a node (no duplicates).

Parameters
ppointer to the node to insert
Returns
p if inserted, nullptr if duplicate
Exceptions
whatthe comparison or the copy of an endpoint throw, with the tree as it was and p out of it.
Note
The maxima are given at the end, with assignments of endpoints that do not throw for most types. They may throw for an endpoint whose copy assignment may throw and whose move assignment may throw too, or that has none. Then no node has moved, and p is out of the tree, but the maxima of some nodes may be left changed: the queries may miss intervals, and neither an insertion nor a removal repairs them. Such a tree must be destroyed, or built again from its intervals.

Definition at line 1116 of file tpl_interval_tree.H.

References Aleph::Random_Source::get(), Aleph::Gen_Interval_Tree< NodeType, T, Compare >::insert(), KEY, Aleph::Gen_Interval_Tree< NodeType, T, Compare >::num_nodes, Aleph::PRIO(), Aleph::Gen_Interval_Tree< NodeType, T, Compare >::r, and Aleph::Gen_Interval_Tree< NodeType, T, Compare >::tree_root.

◆ insert() [2/2]

template<template< typename > class NodeType, typename T , class Compare = Aleph::less<T>>
Node * Aleph::Gen_Interval_Tree< NodeType, T, Compare >::insert ( Node *  root,
Node *  p,
Step *  up 
)
inlineprivate

◆ insert_dup() [1/2]

template<template< typename > class NodeType, typename T , class Compare = Aleph::less<T>>
Node * Aleph::Gen_Interval_Tree< NodeType, T, Compare >::insert_dup ( Node *  p)
inline

Insert a node (duplicates allowed).

Parameters
ppointer to the node to insert
Returns
the p pointer
Exceptions
whatthe comparison or the copy of an endpoint throw, with the tree as it was and p out of it.
Note
If an assignment of an endpoint throws when the maxima are given, the tree is left as insert() says.

Definition at line 1136 of file tpl_interval_tree.H.

References Aleph::Random_Source::get(), Aleph::Gen_Interval_Tree< NodeType, T, Compare >::insert_dup(), KEY, Aleph::Gen_Interval_Tree< NodeType, T, Compare >::num_nodes, Aleph::PRIO(), Aleph::Gen_Interval_Tree< NodeType, T, Compare >::r, and Aleph::Gen_Interval_Tree< NodeType, T, Compare >::tree_root.

◆ insert_dup() [2/2]

template<template< typename > class NodeType, typename T , class Compare = Aleph::less<T>>
void Aleph::Gen_Interval_Tree< NodeType, T, Compare >::insert_dup ( Node *  root,
Node *  p,
Step *  up 
)
inlineprivate

◆ is_empty()

template<template< typename > class NodeType, typename T , class Compare = Aleph::less<T>>
bool Aleph::Gen_Interval_Tree< NodeType, T, Compare >::is_empty ( ) const
inlinenoexcept

Return true if the tree is empty.

Definition at line 1081 of file tpl_interval_tree.H.

References Aleph::Gen_Interval_Tree< NodeType, T, Compare >::num_nodes.

Referenced by Aleph::DynIntervalTree< T, Compare >::is_empty().

◆ join()

template<template< typename > class NodeType, typename T , class Compare = Aleph::less<T>>
Node * Aleph::Gen_Interval_Tree< NodeType, T, Compare >::join ( Node *  t1,
Node *  t2,
Step *  up,
const Step *  whole,
Step *  spine 
)
inlineprivate

Join two trees, every interval of the first one before those of the second one.

It is the end of a removal. The comparisons are made on the way down, with the trees as they were. At the bottom, the removed node, those above it and those of the two inner spines take their new maxima; and on the way back each node of the spines takes its link.

Parameters
[in,out]t1the first tree.
[in,out]t2the second tree.
[in,out]upthe step of the removed node, with those of the nodes above it.
[in]wholethe first step, from up, whose maximum stays.
[in,out]spinethe nodes of the spines above these two trees, as steps, from the last one.
Returns
the root of the joined tree.
Exceptions
whatthe comparison or the copy of an endpoint throw, with the trees as they were.

Definition at line 800 of file tpl_interval_tree.H.

References Aleph::Gen_Interval_Tree< NodeType, T, Compare >::cmp, Aleph::Gen_Interval_Tree< NodeType, T, Compare >::join(), LLINK, Aleph::Gen_Interval_Tree< NodeType, T, Compare >::Step::max, Aleph::MAX_EP(), Aleph::PRIO(), RLINK, Aleph::interval_tree_detail::Pending_Max< T, bool >::set(), and Aleph::Gen_Interval_Tree< NodeType, T, Compare >::Step::up.

Referenced by Aleph::Gen_Interval_Tree< NodeType, T, Compare >::join(), and Aleph::Gen_Interval_Tree< NodeType, T, Compare >::unlink().

◆ key_comp()

template<template< typename > class NodeType, typename T , class Compare = Aleph::less<T>>
IntervalCmp Aleph::Gen_Interval_Tree< NodeType, T, Compare >::key_comp ( ) const
inlinenoexcept

Return the interval comparison functor (over Interval<T> keys).

It holds a copy of the endpoint comparator, so it throws what copying that comparator throws.

Definition at line 973 of file tpl_interval_tree.H.

References Aleph::Gen_Interval_Tree< NodeType, T, Compare >::cmp.

Referenced by Aleph::DynIntervalTree< T, Compare >::key_comp(), Aleph::Gen_Interval_Tree< NodeType, T, Compare >::search(), and Aleph::Gen_Interval_Tree< NodeType, T, Compare >::verify().

◆ link_from()

template<template< typename > class NodeType, typename T , class Compare = Aleph::less<T>>
Node *& Aleph::Gen_Interval_Tree< NodeType, T, Compare >::link_from ( Step *  step)
inlineprivatenoexcept

The link that hangs from a step: that of the root if there is none.

Definition at line 639 of file tpl_interval_tree.H.

References LLINK, RLINK, and Aleph::Gen_Interval_Tree< NodeType, T, Compare >::tree_root.

Referenced by Aleph::Gen_Interval_Tree< NodeType, T, Compare >::place(), and Aleph::Gen_Interval_Tree< NodeType, T, Compare >::unlink().

◆ operator=() [1/2]

template<template< typename > class NodeType, typename T , class Compare = Aleph::less<T>>
Gen_Interval_Tree & Aleph::Gen_Interval_Tree< NodeType, T, Compare >::operator= ( const Gen_Interval_Tree< NodeType, T, Compare > &  )
delete

Deleted copy assignment.

◆ operator=() [2/2]

template<template< typename > class NodeType, typename T , class Compare = Aleph::less<T>>
Gen_Interval_Tree & Aleph::Gen_Interval_Tree< NodeType, T, Compare >::operator= ( Gen_Interval_Tree< NodeType, T, Compare > &&  )
delete

Deleted move assignment.

◆ overlap_search()

template<template< typename > class NodeType, typename T , class Compare = Aleph::less<T>>
const Node * Aleph::Gen_Interval_Tree< NodeType, T, Compare >::overlap_search ( const Key &  query) const
inline

Find any interval that overlaps with query (CLRS algorithm).

Parameters
querythe query interval
Returns
pointer to a node whose interval overlaps query, or nullptr
Complexity: O(log n) expected

Definition at line 1177 of file tpl_interval_tree.H.

References Aleph::and, Aleph::Gen_Interval_Tree< NodeType, T, Compare >::cmp, KEY, LLINK, Aleph::Interval< T >::low, Aleph::MAX_EP(), RLINK, and Aleph::Gen_Interval_Tree< NodeType, T, Compare >::tree_root.

Referenced by Aleph::DynIntervalTree< T, Compare >::overlap_search().

◆ place()

template<template< typename > class NodeType, typename T , class Compare = Aleph::less<T>>
void Aleph::Gen_Interval_Tree< NodeType, T, Compare >::place ( Node *  p,
Step *  bottom 
)
inlineprivate

Put a node in its place, at the end of the way down.

The tree that it leaves is the one that the rotations of a treap give. Every comparison, and every copy of an endpoint that may throw, comes before the tree changes: if one throws, the tree is as it was, and p is not in it.

Parameters
[in,out]pthe node, with its priority and its maximum, the high endpoint of its interval.
[in,out]bottomthe last step of the way, whose link p would hang from as a leaf; nullptr in an empty tree.
Exceptions
whatthe comparison or the copy of an endpoint throw.

Definition at line 683 of file tpl_interval_tree.H.

References Aleph::and, Aleph::Gen_Interval_Tree< NodeType, T, Compare >::cmp, Aleph::interval_tree_detail::Pending_Max< T, bool >::give(), KEY, l, Aleph::Gen_Interval_Tree< NodeType, T, Compare >::Step::left, Aleph::Gen_Interval_Tree< NodeType, T, Compare >::link_from(), LLINK, max(), Aleph::Gen_Interval_Tree< NodeType, T, Compare >::Step::max, Aleph::MAX_EP(), Aleph::Gen_Interval_Tree< NodeType, T, Compare >::Step::node, Aleph::PRIO(), Aleph::Gen_Interval_Tree< NodeType, T, Compare >::r, RLINK, Aleph::interval_tree_detail::Pending_Max< T, bool >::set(), and Aleph::Gen_Interval_Tree< NodeType, T, Compare >::Step::up.

Referenced by Aleph::Gen_Interval_Tree< NodeType, T, Compare >::insert(), and Aleph::Gen_Interval_Tree< NodeType, T, Compare >::insert_dup().

◆ random_source() [1/2]

template<template< typename > class NodeType, typename T , class Compare = Aleph::less<T>>
const Random_Source & Aleph::Gen_Interval_Tree< NodeType, T, Compare >::random_source ( ) const
inlinenoexcept

The source of random numbers, to look at it: its engine, or whether it is equal to another one.

Definition at line 1040 of file tpl_interval_tree.H.

References Aleph::Gen_Interval_Tree< NodeType, T, Compare >::r.

◆ random_source() [2/2]

template<template< typename > class NodeType, typename T , class Compare = Aleph::less<T>>
Random_Source & Aleph::Gen_Interval_Tree< NodeType, T, Compare >::random_source ( )
inlinenoexcept

The source of random numbers, which gives the priorities.

Definition at line 1036 of file tpl_interval_tree.H.

References Aleph::Gen_Interval_Tree< NodeType, T, Compare >::r.

Referenced by TEST().

◆ remove() [1/2]

template<template< typename > class NodeType, typename T , class Compare = Aleph::less<T>>
Node * Aleph::Gen_Interval_Tree< NodeType, T, Compare >::remove ( const Key &  key)
inline

Remove an interval from the tree.

Parameters
keythe interval to remove
Returns
pointer to removed node if found, nullptr otherwise
Exceptions
whatthe comparison or the copy of an endpoint throw, with the tree as it was.
Note
The maxima are given at the end, with assignments of endpoints that do not throw for most types. They may throw for an endpoint whose copy assignment may throw and whose move assignment may throw too, or that has none. Then no node has moved, and the node is still in the tree, but the maxima of some nodes may be left changed: the queries may miss intervals, and neither an insertion nor a removal repairs them. Such a tree must be destroyed, or built again from its intervals.

Definition at line 1161 of file tpl_interval_tree.H.

References Aleph::Gen_Interval_Tree< NodeType, T, Compare >::num_nodes, Aleph::Gen_Interval_Tree< NodeType, T, Compare >::remove(), and Aleph::Gen_Interval_Tree< NodeType, T, Compare >::tree_root.

◆ remove() [2/2]

template<template< typename > class NodeType, typename T , class Compare = Aleph::less<T>>
Node * Aleph::Gen_Interval_Tree< NodeType, T, Compare >::remove ( Node *  root,
const Key &  key,
Step *  up 
)
inlineprivate

◆ reset_num_nodes()

template<template< typename > class NodeType, typename T , class Compare = Aleph::less<T>>
void Aleph::Gen_Interval_Tree< NodeType, T, Compare >::reset_num_nodes ( )
inlinenoexcept

Reset the node count (used after manual tree destruction)

Definition at line 1084 of file tpl_interval_tree.H.

References Aleph::Gen_Interval_Tree< NodeType, T, Compare >::num_nodes.

Referenced by Aleph::DynIntervalTree< T, Compare >::destroy_tree().

◆ rng()

template<template< typename > class NodeType, typename T , class Compare = Aleph::less<T>>
Gsl_Compatible_Rng & Aleph::Gen_Interval_Tree< NodeType, T, Compare >::rng ( ) const
inline

The Mersenne Twister of the tree, which a tree that was given no seed makes here, and draws from it from then on.

Deprecated:
It makes a generator of some 2500 bytes in a tree that has none; use random_source(). It goes in 8.0.0.
Returns
The Mersenne Twister: Random_Source::mersenne_twister().
Exceptions
std::bad_allocIf the tree has no Mersenne Twister and there is not enough memory for it.
Note
It changes a constant tree that has no Mersenne Twister, as gsl_rng_object() does: neither may run at the same time as another use of the tree.

Definition at line 1056 of file tpl_interval_tree.H.

References Aleph::Random_Source::mersenne_twister(), and Aleph::Gen_Interval_Tree< NodeType, T, Compare >::r.

Referenced by TEST().

◆ search()

template<template< typename > class NodeType, typename T , class Compare = Aleph::less<T>>
const Node * Aleph::Gen_Interval_Tree< NodeType, T, Compare >::search ( const Key &  key) const
inlinenoexcept

Search for an exact interval in the tree.

Parameters
keythe interval to search for
Returns
pointer to the node if found, nullptr otherwise
Exceptions
whatthe comparison or its copy throw; nothing when neither does.

Definition at line 1093 of file tpl_interval_tree.H.

References Aleph::Gen_Interval_Tree< NodeType, T, Compare >::key_comp(), Aleph::searchInBinTree(), and Aleph::Gen_Interval_Tree< NodeType, T, Compare >::tree_root.

Referenced by Aleph::DynIntervalTree< T, Compare >::search().

◆ set_seed()

template<template< typename > class NodeType, typename T , class Compare = Aleph::less<T>>
void Aleph::Gen_Interval_Tree< NodeType, T, Compare >::set_seed ( const unsigned long  seed)
inline

Seeds the Mersenne Twister of the tree, as gsl_rng_set() did: the priorities are from then on those of GSL for the seed.

A tree that was given no seed makes its Mersenne Twister here.

Parameters
[in]seedThe seed.
Exceptions
std::bad_allocif the tree has no Mersenne Twister and there is not enough memory for it; then it is unchanged.

Definition at line 965 of file tpl_interval_tree.H.

References Aleph::Random_Source::Mersenne_Twister, Aleph::Gen_Interval_Tree< NodeType, T, Compare >::r, Aleph::Random_Source::seed(), and seed.

Referenced by IntervalTreeRawTest::SetUp().

◆ side_of()

template<template< typename > class NodeType, typename T , class Compare = Aleph::less<T>>
static int Aleph::Gen_Interval_Tree< NodeType, T, Compare >::side_of ( const Key &  a,
const Key &  b,
const Compare &  cmp 
)
inlinestaticprivate

The side of b where a goes: -1 before it, 1 after it, and 0 if they are the same interval.

Definition at line 659 of file tpl_interval_tree.H.

References Aleph::Gen_Interval_Tree< NodeType, T, Compare >::cmp, Aleph::Interval< T >::high, and Aleph::Interval< T >::low.

Referenced by Aleph::Gen_Interval_Tree< NodeType, T, Compare >::insert(), and Aleph::Gen_Interval_Tree< NodeType, T, Compare >::remove().

◆ size()

template<template< typename > class NodeType, typename T , class Compare = Aleph::less<T>>
size_t Aleph::Gen_Interval_Tree< NodeType, T, Compare >::size ( ) const
inlinenoexcept

Return the number of nodes.

Definition at line 1078 of file tpl_interval_tree.H.

References Aleph::Gen_Interval_Tree< NodeType, T, Compare >::num_nodes.

Referenced by Aleph::DynIntervalTree< T, Compare >::size().

◆ stab()

template<template< typename > class NodeType, typename T , class Compare = Aleph::less<T>>
template<class Op >
void Aleph::Gen_Interval_Tree< NodeType, T, Compare >::stab ( const T &  p,
Op &&  op 
) const
inline

Apply op to every interval containing point p.

Parameters
pthe query point
opcallable with signature void(const Interval<T>&)
Exceptions
Maythrow if the provided callback throws.
Complexity: O(k log n)

Definition at line 1228 of file tpl_interval_tree.H.

References Aleph::Gen_Interval_Tree< NodeType, T, Compare >::all_overlaps(), and Aleph::Interval< T >::point().

Referenced by Aleph::DynIntervalTree< T, Compare >::stab().

◆ swap()

◆ unlink()

template<template< typename > class NodeType, typename T , class Compare = Aleph::less<T>>
void Aleph::Gen_Interval_Tree< NodeType, T, Compare >::unlink ( Node *  p,
Step *  up 
)
inlineprivate

Take a node out of the tree: its two subtrees, joined, take its place.

The node is left as its reset() leaves it.

Every comparison, and every copy of an endpoint that may throw, comes before the tree changes: if one throws, the tree is as it was.

Parameters
[in]pthe node.
[in,out]upthe step of its parent; nullptr if it is the root.
Exceptions
whatthe comparison or the copy of an endpoint throw.

Definition at line 840 of file tpl_interval_tree.H.

References Aleph::and, Aleph::Gen_Interval_Tree< NodeType, T, Compare >::cmp, Aleph::Gen_Interval_Tree< NodeType, T, Compare >::join(), KEY, Aleph::Gen_Interval_Tree< NodeType, T, Compare >::Step::left, Aleph::Gen_Interval_Tree< NodeType, T, Compare >::link_from(), LLINK, max(), Aleph::Gen_Interval_Tree< NodeType, T, Compare >::Step::max, Aleph::MAX_EP(), Aleph::Gen_Interval_Tree< NodeType, T, Compare >::Step::node, RLINK, Aleph::interval_tree_detail::Pending_Max< T, bool >::set(), and Aleph::Gen_Interval_Tree< NodeType, T, Compare >::Step::up.

Referenced by Aleph::Gen_Interval_Tree< NodeType, T, Compare >::remove().

◆ verify()

Member Data Documentation

◆ cmp

◆ head

template<template< typename > class NodeType, typename T , class Compare = Aleph::less<T>>
Node Aleph::Gen_Interval_Tree< NodeType, T, Compare >::head
private

Definition at line 612 of file tpl_interval_tree.H.

◆ head_ptr

template<template< typename > class NodeType, typename T , class Compare = Aleph::less<T>>
Node* Aleph::Gen_Interval_Tree< NodeType, T, Compare >::head_ptr
private

◆ num_nodes

◆ r

◆ tree_root


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