ADS
Algorithms and Data Structures
Loading...
Searching...
No Matches
DictionarySet.h File Reference

The SET on any DICTIONARY with a foreach (sections 8.4 and 8.5): ChainedHashSet and OpenHashSet on the hash tables, contains(), insert() and remove() in \( O( 1 ) \) expected time and forEach() in \( O( m + n ) \) and \( O( m ) \), \( m \) the size of the table; TreeSet on a Red-Black tree, the three in \( O( \log n ) \) and forEach() in \( O( n ) \), in order. More...

#include "ADS/Contract.h"
#include "ADS/Iterators.h"
#include "ADS/dictionary/ChainedHashTable.h"
#include "ADS/dictionary/OpenHashTable.h"
#include "ADS/set/SetInterfaces.h"
#include "ADS/set/SetOperations.h"
#include "ADS/tree/SearchTree.h"
#include <algorithm>
#include <concepts>
#include <cstddef>
#include <functional>
#include <optional>
#include <ranges>
#include <stdexcept>
#include <utility>
#include <vector>
#include "ADS/set/impl/DictionarySet.tpp"

Go to the source code of this file.

Classes

class  ADS::DictionarySet< D >
 a set on a DICTIONARY D, an item being a key: a USet of Morin if D is a KeyedDictionary, an SSet if it is an OrderedDictionary More...

Namespaces

namespace  ADS

Typedefs

template<class T, class H = std::hash< T >>
using ADS::ChainedHashSet
 the set on a hash table with lists of overflow
template<class T, class H = std::hash< T >>
using ADS::OpenHashSet = DictionarySet< OpenHashTable< T , bool , H > >
 the set on a hash table with open addressing
template<std::totally_ordered T>
using ADS::TreeSet = DictionarySet< RedBlackTree< T , bool > >
 the set on a Red-Black tree

Detailed description

The SET on any DICTIONARY with a foreach (sections 8.4 and 8.5): ChainedHashSet and OpenHashSet on the hash tables, contains(), insert() and remove() in \( O( 1 ) \) expected time and forEach() in \( O( m + n ) \) and \( O( m ) \), \( m \) the size of the table; TreeSet on a Red-Black tree, the three in \( O( \log n ) \) and forEach() in \( O( n ) \), in order.

Their operations of two sets are the generic ones [see SetOperations.h].

It is also the one adaptor that makes every dictionary of the library a set of Morin [see SetInterfaces.h], beyond the book: on a KeyedDictionary, whose findKey( k ) gives the address of the key \( k \) it holds, it is a USet, find( x ) being that address, and on an OrderedDictionary, whose lowerBoundKey( k ) gives the address of the smallest key not smaller than \( k \), it is an SSet, with lowerBound( x ); the hash tables are of the first kind, and the search trees, the skip lists, the B-trees and the sorted array of the second. insert() and remove() say whether they changed the set, by the answer of the dictionary when its own insert() and remove() give one, and otherwise by one search more. The dictionary is mutable, since the searches of a splay tree move its nodes while the set they hold stays the same, and find() of a USet is constant.

The contracts [see Contract.h]: after insert() the item is there and after remove() it is not; the dictionary keeps its own invariant. The operations are defined in DictionarySet.tpp.

See also
A. Montresor, Algoritmi e Strutture Dati, 2025, sections 8.4 and 8.5, https://algoritmicamente.it/materiali/libro/capitoli/cap08.pdf
P. Morin, Open Data Structures (in C++), Edition 0.1G, 2013, https://opendatastructures.org/ods-cpp.pdf, sections 1.2.3 and 1.2.4
Author
Donato Meoli
Dipartimento di Informatica
Università di Pisa