ADS
Algorithms and Data Structures
Loading...
Searching...
No Matches
ADT.h
Go to the documentation of this file.
1/*--------------------------------------------------------------------------*/
2/*------------------------------- File ADT.h -------------------------------*/
3/*--------------------------------------------------------------------------*/
75/*--------------------------------------------------------------------------*/
76/*----------------------------- DEFINITIONS --------------------------------*/
77/*--------------------------------------------------------------------------*/
78
79#ifndef __ADS_ADT
80 #define __ADS_ADT
81/* self-identification: #endif constant */
82
83/*--------------------------------------------------------------------------*/
84/*------------------------------ INCLUDES ----------------------------------*/
85/*--------------------------------------------------------------------------*/
86
87#include <concepts>
88#include <cstddef>
89#include <optional>
90
91/*--------------------------------------------------------------------------*/
92/*--------------------------- NAMESPACE ------------------------------------*/
93/*--------------------------------------------------------------------------*/
94
95namespace ADS
96{
97
98/*--------------------------------------------------------------------------*/
99/*------------------------------- CONCEPTS ---------------------------------*/
100/*--------------------------------------------------------------------------*/
101
110template< class S >
111concept Sequence =
112 requires( S s , const S cs , typename S::Pos p , const typename S::Item & v )
113{
114 typename S::Item;
115 typename S::Pos;
116 { cs.empty() } -> std::same_as< bool >;
117 { cs.finished( p ) } -> std::same_as< bool >;
118 { cs.head() } -> std::same_as< typename S::Pos >;
119 { cs.tail() } -> std::same_as< typename S::Pos >;
120 { cs.next( p ) } -> std::same_as< typename S::Pos >;
121 { cs.prev( p ) } -> std::same_as< typename S::Pos >;
122 { s.insert( p , v ) } -> std::same_as< typename S::Pos >;
123 { s.remove( p ) } -> std::same_as< typename S::Pos >;
124 { cs.read( p ) } -> std::convertible_to< typename S::Item >;
125 s.write( p , v );
126 };
127
139template< class S >
140concept Set = requires( S s , const S cs , const typename S::Item & x )
141{
142 typename S::Item;
143 { cs.size() } -> std::convertible_to< std::size_t >;
144 { cs.contains( x ) } -> std::same_as< bool >;
145 s.insert( x );
146 s.remove( x );
147 };
148
160template< class D >
161concept Dictionary = requires( D d , const D cd , const typename D::Key & k ,
162 const typename D::Value & v )
163{
164 typename D::Key;
165 typename D::Value;
166 { cd.lookup( k ) } -> std::same_as< std::optional< typename D::Value > >;
167 d.insert( k , v );
168 d.remove( k );
169 };
170
183template< class S >
184concept Stack = requires( S s , const S cs , const typename S::Item & v )
185{
186 typename S::Item;
187 { cs.empty() } -> std::same_as< bool >;
188 s.push( v );
189 { s.pop() } -> std::convertible_to< typename S::Item >;
190 { cs.top() } -> std::convertible_to< typename S::Item >;
191 };
192
193
205template< class Q >
206concept Queue = requires( Q q , const Q cq , const typename Q::Item & v )
207{
208 typename Q::Item;
209 { cq.empty() } -> std::same_as< bool >;
210 q.enqueue( v );
211 { q.dequeue() } -> std::convertible_to< typename Q::Item >;
212 { cq.top() } -> std::convertible_to< typename Q::Item >;
213 };
214
215/*--------------------------------------------------------------------------*/
216
217} // end( namespace ADS )
218
219/*--------------------------------------------------------------------------*/
220
221#endif /* ADT.h included */
222
223/*--------------------------------------------------------------------------*/
224/*---------------------------- End File ADT.h ------------------------------*/
225/*--------------------------------------------------------------------------*/
DICTIONARY (section 3.2.3): a univocal relation from keys to values; lookup() returns the value of a ...
Definition ADT.h:161
[Stack]
Definition ADT.h:206
SEQUENCE (section 3.2.1): a dynamic linear sequence of items; as axioms, (empty() is redundant),...
Definition ADT.h:111
SET (section 3.2.2): a finite collection of distinct items; union(), intersection() and difference() ...
Definition ADT.h:140
STACK (section 4.3.1): items are added and removed at the top (LIFO).
Definition ADT.h:184
Definition ADT.h:96