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

The interfaces of chapter 1 of Morin's book for the sets, beyond the book, as concepts of C++20 [see ADT.h for the SET of the book], and their realizations on a vector that exercise 1.6 asks for, the oracles of the tests of the faster ones: More...

#include "ADS/Contract.h"
#include "ADS/Portable.h"
#include <algorithm>
#include <concepts>
#include <cstddef>
#include <functional>
#include <utility>
#include <vector>
#include "ADS/set/impl/SetInterfaces.tpp"

Go to the source code of this file.

Classes

class  ADS::ArrayUSet< T, Eq >
 a USet on a vector in no order, the items equal by Eq More...
class  ADS::ArraySSet< T, C >
 an SSet on a sorted vector, ordered by C More...

Namespaces

namespace  ADS

Concepts

concept  ADS::USet
 the unordered set of Morin, whose find() gives the item equal to the one asked
concept  ADS::SSet
 the sorted set of Morin, a USet with the successor search
concept  ADS::KeyedDictionary
 a dictionary that gives the address of the key equal to the one asked, on which DictionarySet is a USet; the search may change the dictionary (a splay tree), not the set of its keys
concept  ADS::OrderedDictionary
 a KeyedDictionary that gives the address of the smallest key not smaller than the one asked, on which DictionarySet is an SSet

Detailed description

The interfaces of chapter 1 of Morin's book for the sets, beyond the book, as concepts of C++20 [see ADT.h for the SET of the book], and their realizations on a vector that exercise 1.6 asks for, the oracles of the tests of the faster ones:

  • USet, the unordered set of section 1.2.3 of Morin: size(), insert( x ) (Morin's add( x )), true if no item equal to \( x \) was there, remove( x ), true if one was, and find( x ), the address of the item equal to \( x \) or nil, an item that may carry more than its key;
  • SSet, the sorted set of section 1.2.4: a USet whose items are ordered, with lowerBound( x ), the address of the least item not smaller than \( x \) or nil (Morin's find( x ) of an SSet, the successor search);
  • KeyedDictionary and OrderedDictionary, the dictionaries that show their keys as a set: findKey( k ) the address of the key \( k \) they hold, and lowerBoundKey( k ) that of the smallest key not smaller than \( k \), both nil if none; DictionarySet over the first is a USet and over the second an SSet [see DictionarySet.h], the one way in which every hash table, search tree, skip list and B-tree of the library, whose lowerBound() gives a pair or an iterator, is a set of Morin;
  • ArrayUSet, a USet on a vector in no order: find() scans it in \( O( n ) \), remove() moves the last item into the place freed in \( O( 1 ) \) after the scan;
  • ArraySSet, an SSet on a sorted vector: find() and lowerBound() by binary search in \( O( \log n ) \), insert() and remove() move the items after the place by one place, as one block (the insert() and the erase() of std::vector, a single memmove() for the items that are trivially copyable), in \( O( n ) \) (the improvements of exercise 1.7: the binary search for the find(), the block move for the changes).

The contracts [see Contract.h]: after insert() the item is there and after remove() it is not; the invariant of ArraySSet is the strict order of its vector, an \( O( n ) \) check. The operations are defined in SetInterfaces.tpp.

See also
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 and exercises 1.6 and 1.7
Author
Donato Meoli
Dipartimento di Informatica
Università di Pisa