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

A DICTIONARY [see ADT.h] realized with a vector of the pairs \( ( \mathit{key} , \mathit{value} ) \) sorted by key, beyond the book: lookup() is the binary search of section 1.2 [see BinarySearch.h], in \( O( \log n ) \) time, while insert() and remove() move the pairs after the place of the key, in \( O( n ) \). More...

#include "ADS/Contract.h"
#include <concepts>
#include <cstddef>
#include <optional>
#include <utility>
#include <vector>
#include "ADS/dictionary/impl/SortedArrayDictionary.tpp"

Go to the source code of this file.

Classes

class  ADS::SortedArrayDictionary< K, V >
 a DICTIONARY realized with a vector sorted by key More...

Namespaces

namespace  ADS

Detailed description

A DICTIONARY [see ADT.h] realized with a vector of the pairs \( ( \mathit{key} , \mathit{value} ) \) sorted by key, beyond the book: lookup() is the binary search of section 1.2 [see BinarySearch.h], in \( O( \log n ) \) time, while insert() and remove() move the pairs after the place of the key, in \( O( n ) \).

It is the realization to prefer when the lookups far outnumber the changes, and it also gives the keys in order, and the range of keys between two values, at no further cost.

The contracts [see Contract.h]: insert() ensures that \( k \) has the value \( v \), remove() that \( k \) is not there; the invariant is that the keys are strictly increasing. The operations are defined in SortedArrayDictionary.tpp.

See also
A. Montresor, Algoritmi e Strutture Dati, 2025, sections 1.2 and 3.2.3, https://algoritmicamente.it/materiali/libro/capitoli/cap01.pdf
Author
Donato Meoli
Dipartimento di Informatica
Università di Pisa