ADS
Algorithms and Data Structures
Loading...
Searching...
No Matches
LinkedHashSet.h
Go to the documentation of this file.
1/*--------------------------------------------------------------------------*/
2/*-------------------------- File LinkedHashSet.h --------------------------*/
3/*--------------------------------------------------------------------------*/
24/*--------------------------------------------------------------------------*/
25/*----------------------------- DEFINITIONS --------------------------------*/
26/*--------------------------------------------------------------------------*/
27
28#ifndef __ADS_LinkedHashSet
29 #define __ADS_LinkedHashSet
30/* self-identification: #endif constant */
31
32/*--------------------------------------------------------------------------*/
33/*------------------------------ INCLUDES ----------------------------------*/
34/*--------------------------------------------------------------------------*/
35
36#include "ADS/Contract.h"
38#include "ADS/sequence/List.h"
40
41#include <algorithm>
42#include <concepts>
43#include <cstddef>
44#include <functional>
45#include <optional>
46#include <stdexcept>
47#include <utility>
48#include <vector>
49
50/*--------------------------------------------------------------------------*/
51/*--------------------------- NAMESPACE ------------------------------------*/
52/*--------------------------------------------------------------------------*/
53
54namespace ADS
55{
56
57/*--------------------------------------------------------------------------*/
58/*-------------------------- CLASS LinkedHashSet ---------------------------*/
59/*--------------------------------------------------------------------------*/
60
65template< class T , class H = std::hash< T > >
67{
68
69/*--------------------------------------------------------------------------*/
70 public:
71 using Item = T;
72
75
78
81 LinkedHashSet & operator=( const LinkedHashSet & ) = delete;
82
84 [[nodiscard]] std::size_t size( void ) const;
85
87 [[nodiscard]] bool empty( void ) const;
88
90 [[nodiscard]] bool contains( const T & x ) const;
91
110 void insert( const T & x );
111
125 void remove( const T & x );
126
128 template< class F >
129 void forEach( F && f ) const;
130
131/*------------------------- THE STANDARD INTERFACE -------------------------*/
132
133 // a constant view of the items in the order of their insertion,
134 // bidirectional
135
136 using value_type = T;
137 using size_type = std::size_t;
138 using difference_type = std::ptrdiff_t;
139 using reference = const T &;
140 using const_reference = const T &;
144
146 [[nodiscard]] const_iterator begin( void ) const {
147 return( f_order.begin() );
148 }
149
150 [[nodiscard]] const_iterator end( void ) const { return( f_order.end() ); }
152 [[nodiscard]] const_iterator cbegin( void ) const { return( begin() ); }
154 [[nodiscard]] const_iterator cend( void ) const { return( end() ); }
155
156/*--------------------------------------------------------------------------*/
157 private:
158 using Pos = typename List< T >::Pos;
159
162 [[nodiscard]] bool indexed( void ) const;
163
164 List< T > f_order;
166
167 }; // end( class LinkedHashSet )
168
169} // end( namespace ADS )
170
171/*--------------------------------------------------------------------------*/
172/*-------------------------- IMPLEMENTATION --------------------------------*/
173/*--------------------------------------------------------------------------*/
174
175#include "ADS/set/impl/LinkedHashSet.tpp"
176
177/*--------------------------------------------------------------------------*/
178
179#endif /* LinkedHashSet.h included */
180
181/*--------------------------------------------------------------------------*/
182/*------------------------ End File LinkedHashSet.h ------------------------*/
183/*--------------------------------------------------------------------------*/
The hash table with lists of overflow of section 7.2.1, a realization of the DICTIONARY [see ADT....
The contracts of ADS: the preconditions, the postconditions and the invariants of the operations,...
The LIST of the book: a SEQUENCE [see ADT.h] realized as a bidirectional circular list of cells with ...
The operations of chapter 8 on any SET that can be copied and has the foreach, forEach( f ): the unio...
a hash table with lists of overflow
Definition ChainedHashTable.h:103
void forEach(F &&f) const
f( x ) on the items in the order of insertion, time
void insert(const T &x)
into the set: a new item goes to the end of the order, and an item already there keeps its place
bool contains(const T &x) const
whether is in the set, by a search in the table
T value_type
the items
Definition LinkedHashSet.h:136
const_iterator cbegin(void) const
as begin()
Definition LinkedHashSet.h:152
const T & const_reference
a constant reference
Definition LinkedHashSet.h:140
const T & reference
a constant reference
Definition LinkedHashSet.h:139
std::ptrdiff_t difference_type
the distances
Definition LinkedHashSet.h:138
LinkedHashSet(void)
the empty set
const_iterator cend(void) const
as end()
Definition LinkedHashSet.h:154
const_iterator end(void) const
the iterator past the last item inserted
Definition LinkedHashSet.h:150
std::size_t size_type
the sizes
Definition LinkedHashSet.h:137
bool empty(void) const
whether the set has no item
const_iterator iterator
the same, constant
Definition LinkedHashSet.h:143
T Item
the type of the items
Definition LinkedHashSet.h:71
LinkedHashSet & operator=(const LinkedHashSet &)=delete
no assignment, which would copy the positions into the list of another set
LinkedHashSet(const LinkedHashSet &o)
a copy, with positions into its own list
typename List< T >::const_iterator const_iterator
the iterator of the list of the order, constant
Definition LinkedHashSet.h:142
const_iterator begin(void) const
the iterator on the first item inserted
Definition LinkedHashSet.h:146
std::size_t size(void) const
the number of items
void remove(const T &x)
out of the set, and out of the order
a SEQUENCE realized as a bidirectional circular list with a sentinel, its cells from a pool if Pooled
Definition List.h:118
Iterator< true > const_iterator
the iterator on the constant items
Definition List.h:324
Cell * Pos
a position is the address of a cell
Definition List.h:132
Definition ADT.h:96