Aleph-w 3.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...
 

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) noexcept
 Set the random number generator seed.
 
IntervalCmp key_comp () const noexcept
 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(std::swap(r, 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.
 
 Gen_Interval_Tree (const Compare &_cmp=Compare())
 Construct with default seed (from system time).
 
 Gen_Interval_Tree (const Gen_Interval_Tree &)=delete
 Deleted copy constructor.
 
Gen_Interval_Treeoperator= (const Gen_Interval_Tree &)=delete
 Deleted copy assignment.
 
 Gen_Interval_Tree (Gen_Interval_Tree &&)=delete
 Deleted move constructor.
 
Gen_Interval_Treeoperator= (Gen_Interval_Tree &&)=delete
 Deleted move assignment.
 
 ~Gen_Interval_Tree ()
 
gsl_rnggsl_rng_object () const noexcept
 Get a pointer to the GSL random number generator.
 
Node *& getRoot () noexcept
 Return the tree's root.
 
const NodegetRoot () 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 Nodesearch (const Key &key) const
 Search for an exact interval in the tree.
 
Nodeinsert (Node *p)
 Insert a node (no duplicates).
 
Nodeinsert_dup (Node *p)
 Insert a node (duplicates allowed).
 
Noderemove (const Key &key)
 Remove an interval from the tree.
 
const Nodeoverlap_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< Keyfind_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< Keyfind_stab (const T &p) const
 Find all intervals containing point p.
 
bool verify () const
 Verify BST, heap, and max_endpoint invariants.
 

Private Member Functions

void init (const unsigned int seed)
 
Nodeinsert (Node *root, Node *p)
 
Nodeinsert_dup (Node *root, Node *p)
 
Noderemove (Node *&root, const Key &key)
 

Static Private Member Functions

static void update_max (Node *p, const Compare &cmp)
 Recalculate max_endpoint from node's own high and children.
 
static Noderotate_to_right_it (Node *p, const Compare &cmp)
 Rotate right with augmented field update.
 
static Noderotate_to_left_it (Node *p, const Compare &cmp)
 Rotate left with augmented field update.
 
static Nodejoin_exclusive (Node *t1, Node *t2, const Compare &cmp)
 
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
 
Nodehead_ptr
 
Node *& tree_root
 
gsl_rngr
 
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 513 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 517 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 516 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 518 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.

Parameters
[in]seedRandom seed.
[in]_cmpComparison functor.
Exceptions
ah_bad_alloc_ifif random number generator allocation fails.

Definition at line 761 of file tpl_interval_tree.H.

References Aleph::init, and seed.

◆ 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 with default seed (from system time).

Parameters
[in]_cmpComparison functor.
Exceptions
ah_bad_alloc_ifif random number generator allocation fails.

Definition at line 773 of file tpl_interval_tree.H.

◆ 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.

◆ ~Gen_Interval_Tree()

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

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 903 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]

◆ check_max()

◆ 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()

◆ 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_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 940 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().

◆ 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 741 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 801 of file tpl_interval_tree.H.

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

◆ getRoot() [2/2]

◆ gsl_rng_object()

template<template< typename > class NodeType, typename T , class Compare = Aleph::less<T>>
gsl_rng * Aleph::Gen_Interval_Tree< NodeType, T, Compare >::gsl_rng_object ( ) const
inlinenoexcept

Get a pointer to the GSL random number generator.

Definition at line 795 of file tpl_interval_tree.H.

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

◆ init()

◆ 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() [2/2]

◆ 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_dup() [2/2]

◆ 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 807 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_exclusive()

◆ 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)

Definition at line 735 of file tpl_interval_tree.H.

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

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

◆ 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 878 of file tpl_interval_tree.H.

References Aleph::and, Aleph::Gen_Interval_Tree< NodeType, T, Compare >::cmp, Aleph::divide_and_conquer_partition_dp(), 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().

◆ 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

Definition at line 861 of file tpl_interval_tree.H.

References Aleph::divide_and_conquer_partition_dp(), 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]

◆ 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 810 of file tpl_interval_tree.H.

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

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

◆ rotate_to_left_it()

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

◆ rotate_to_right_it()

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

◆ 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
inline

Search for an exact interval in the tree.

Parameters
keythe interval to search for
Returns
pointer to the node if found, nullptr otherwise

Definition at line 817 of file tpl_interval_tree.H.

References Aleph::divide_and_conquer_partition_dp(), 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)
inlinenoexcept

Set the random number generator seed.

Definition at line 732 of file tpl_interval_tree.H.

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

Referenced by IntervalTreeRawTest::SetUp().

◆ 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 804 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 929 of file tpl_interval_tree.H.

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

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

◆ swap()

◆ update_max()

◆ 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 521 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: