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

Generic domain class based on hash set. More...

#include <al-domain.H>

Inheritance diagram for Aleph::AlDomain< T >:
[legend]
Collaboration diagram for Aleph::AlDomain< T >:
[legend]

Public Types

using Base = Aleph::HashSet< T, SetODhash >
 
typedef HashSetTable< Key, Cmp > Base
 
- Public Types inherited from Aleph::HashSet< Key, HashSetTable, Cmp >
typedef HashSetTable< Key, Cmp > Base
 

Public Member Functions

const DynList< T > & keys () const
 Get sorted list of all elements in the domain.
 
T * insert (const T &key)
 Insert key, as HashSet::insert(), and forget the sorted keys.
 
T * insert (T &&key)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
T * search_or_insert (const T &key)
 Search or insert key, as HashSet::search_or_insert(), and forget the sorted keys.
 
T * search_or_insert (T &&key)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
std::pair< T *, bool > contains_or_insert (const T &key)
 Search or insert key, as HashSet::contains_or_insert(), and forget the sorted keys.
 
std::pair< T *, bool > contains_or_insert (T &&key)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
T * append (const T &key)
 Insert key, as HashSet::append(), and forget the sorted keys.
 
T * append (T &&key)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
void add (const DynList< T > &l)
 Insert the keys of l, as HashSet::add(), and forget the sorted keys.
 
void remove (const T &key)
 Remove key, as HashSet::remove(), and forget the sorted keys.
 
void remove_ptr (T *key)
 Remove the key that key points to, as HashSet::remove_ptr(), and forget the sorted keys.
 
void empty ()
 Remove every key, as HashSet::empty(), and forget the sorted keys.
 
void clear ()
 Remove every key, as HashSet::clear(), and forget the sorted keys.
 
void swap (AlDomain &other) noexcept
 Swap the keys, and the sorted keys, with other.
 
DynList< T > to_list () const
 Convert domain to sorted list.
 
std::string to_str () const and AlStreamable< T >
 Convert domain to string representation.
 
- Public Member Functions inherited from Aleph::HashSet< Key, HashSetTable, Cmp >
void add (const DynList< Key > &l)
 
template<template< typename > class List>
 HashSet (const List< Key > &l)
 
template<class It >
requires (not std::is_arithmetic_v<It> and requires (It it) { *it; ++it; it != it; })
 HashSet (It b, It e)
 
 HashSet (std::initializer_list< Key > l)
 
 HashSet ()
 
const Key & get_first () const
 
const Key & get_last () const
 
void clear ()
 Empties the container.
 
bool is_empty () const noexcept
 Checks if the container is empty.
 

Static Public Member Functions

template<typename... Items>
requires requires (Items &&... items) { AlDomain ::template build_as< AlDomain >(std::forward<Items>(items)...); }
static AlDomain build (Items &&... items)
 
- Static Public Member Functions inherited from Aleph::HashSet< Key, HashSetTable, Cmp >
template<typename... Items>
requires requires (Items &&... items) { HashSet ::template build_as< HashSet >(std::forward<Items>(items)...); }
static HashSet build (Items &&... items)
 

Private Attributes

bool keys_build = false
 Lazy cache flag.
 
DynList< T > domain
 Cached sorted keys.
 

Detailed Description

template<typename T = int>
requires AlDomainKey<T>
class Aleph::AlDomain< T >

Generic domain class based on hash set.

Stores a set of unique elements with O(1) lookup. Provides sorted iteration via the keys() method.

keys() keeps the sorted elements until the domain changes: the members of AlDomain that insert or remove forget them, and keys() sorts them again also when the number of elements changed by other means, as the removal through an iterator.

Template Parameters
TElement type (default: int)

Definition at line 131 of file al-domain.H.

Member Typedef Documentation

◆ Base [1/2]

template<typename T = int>
using Aleph::AlDomain< T >::Base = Aleph::HashSet<T, SetODhash>

Definition at line 138 of file al-domain.H.

◆ Base [2/2]

template<typename T = int>
typedef HashSetTable<Key, Cmp> Aleph::HashSet< Key, HashSetTable, Cmp >::Base

Definition at line 64 of file tpl_hash.H.

Member Function Documentation

◆ add()

template<typename T = int>
void Aleph::AlDomain< T >::add ( const DynList< T > &  l)
inline

Insert the keys of l, as HashSet::add(), and forget the sorted keys.

Definition at line 220 of file al-domain.H.

References Aleph::HashSet< Key, HashSetTable, Cmp >::add(), Aleph::AlDomain< T >::keys_build, and l.

Referenced by TEST().

◆ append() [1/2]

template<typename T = int>
T * Aleph::AlDomain< T >::append ( const T &  key)
inline

Insert key, as HashSet::append(), and forget the sorted keys.

Definition at line 206 of file al-domain.H.

References Aleph::AlDomain< T >::keys_build.

Referenced by TEST().

◆ append() [2/2]

template<typename T = int>
T * Aleph::AlDomain< T >::append ( T &&  key)
inline

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 213 of file al-domain.H.

References Aleph::AlDomain< T >::keys_build.

◆ build()

template<typename T = int>
template<typename... Items>
requires requires (Items &&... items) { AlDomain ::template build_as< AlDomain >(std::forward<Items>(items)...); }
static AlDomain Aleph::AlDomain< T >::build ( Items &&...  items)
inlinestatic

Definition at line 140 of file al-domain.H.

Referenced by TEST().

◆ clear()

template<typename T = int>
void Aleph::AlDomain< T >::clear ( )
inline

Remove every key, as HashSet::clear(), and forget the sorted keys.

Definition at line 249 of file al-domain.H.

References Aleph::AlDomain< T >::empty().

Referenced by TEST().

◆ contains_or_insert() [1/2]

template<typename T = int>
std::pair< T *, bool > Aleph::AlDomain< T >::contains_or_insert ( const T &  key)
inline

Search or insert key, as HashSet::contains_or_insert(), and forget the sorted keys.

Definition at line 192 of file al-domain.H.

References Aleph::AlDomain< T >::keys_build.

Referenced by TEST().

◆ contains_or_insert() [2/2]

template<typename T = int>
std::pair< T *, bool > Aleph::AlDomain< T >::contains_or_insert ( T &&  key)
inline

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 199 of file al-domain.H.

References Aleph::AlDomain< T >::keys_build.

◆ empty()

template<typename T = int>
void Aleph::AlDomain< T >::empty ( )
inline

Remove every key, as HashSet::empty(), and forget the sorted keys.

Definition at line 242 of file al-domain.H.

References Aleph::AlDomain< T >::keys_build.

Referenced by Aleph::AlDomain< T >::clear(), and TEST().

◆ insert() [1/2]

template<typename T = int>
T * Aleph::AlDomain< T >::insert ( const T &  key)
inline

Insert key, as HashSet::insert(), and forget the sorted keys.

Definition at line 162 of file al-domain.H.

References Aleph::AlDomain< T >::keys_build.

Referenced by VectorTest::SetUp(), TEST(), TEST(), TEST(), and TEST().

◆ insert() [2/2]

template<typename T = int>
T * Aleph::AlDomain< T >::insert ( T &&  key)
inline

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 169 of file al-domain.H.

References Aleph::AlDomain< T >::keys_build.

◆ keys()

template<typename T = int>
const DynList< T > & Aleph::AlDomain< T >::keys ( ) const
inline

Get sorted list of all elements in the domain.

Lazily builds and caches the sorted key list, which a later change of the domain rebuilds.

Returns
Const reference to sorted DynList of elements, valid until the domain changes

Definition at line 151 of file al-domain.H.

References Aleph::AlDomain< T >::domain, Aleph::AlDomain< T >::keys_build, Aleph::DynList< T >::size(), and Aleph::sort().

Referenced by TEST_F(), and Aleph::AlDomain< T >::to_list().

◆ remove()

template<typename T = int>
void Aleph::AlDomain< T >::remove ( const T &  key)
inline

Remove key, as HashSet::remove(), and forget the sorted keys.

Definition at line 227 of file al-domain.H.

References Aleph::AlDomain< T >::keys_build.

Referenced by TEST().

◆ remove_ptr()

template<typename T = int>
void Aleph::AlDomain< T >::remove_ptr ( T *  key)
inline

Remove the key that key points to, as HashSet::remove_ptr(), and forget the sorted keys.

Definition at line 235 of file al-domain.H.

References Aleph::AlDomain< T >::keys_build.

Referenced by TEST().

◆ search_or_insert() [1/2]

template<typename T = int>
T * Aleph::AlDomain< T >::search_or_insert ( const T &  key)
inline

Search or insert key, as HashSet::search_or_insert(), and forget the sorted keys.

Definition at line 177 of file al-domain.H.

References Aleph::AlDomain< T >::keys_build.

Referenced by TEST().

◆ search_or_insert() [2/2]

template<typename T = int>
T * Aleph::AlDomain< T >::search_or_insert ( T &&  key)
inline

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 184 of file al-domain.H.

References Aleph::AlDomain< T >::keys_build.

◆ swap()

template<typename T = int>
void Aleph::AlDomain< T >::swap ( AlDomain< T > &  other)
inlinenoexcept

Swap the keys, and the sorted keys, with other.

Definition at line 252 of file al-domain.H.

References Aleph::AlDomain< T >::domain, Aleph::AlDomain< T >::keys_build, and Aleph::DynList< T >::swap().

Referenced by TEST().

◆ to_list()

template<typename T = int>
DynList< T > Aleph::AlDomain< T >::to_list ( ) const
inline

Convert domain to sorted list.

Returns
Sorted DynList of all elements

Definition at line 263 of file al-domain.H.

References Aleph::AlDomain< T >::keys().

Referenced by TEST_F(), and Aleph::AlDomain< T >::to_str().

◆ to_str()

template<typename T = int>
std::string Aleph::AlDomain< T >::to_str ( ) const
inline

Convert domain to string representation.

Returns
Space-separated string of sorted elements

Definition at line 269 of file al-domain.H.

References Aleph::sort(), Aleph::AlDomain< T >::to_list(), and Aleph::to_str().

Referenced by Aleph::operator<<().

Member Data Documentation

◆ domain

template<typename T = int>
DynList<T> Aleph::AlDomain< T >::domain
mutableprivate

Cached sorted keys.

Definition at line 134 of file al-domain.H.

Referenced by Aleph::AlDomain< T >::keys(), and Aleph::AlDomain< T >::swap().

◆ keys_build


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