ADS
Algorithms and Data Structures
Toggle main menu visibility
Loading...
Searching...
No Matches
Bag.h
Go to the documentation of this file.
1
/*--------------------------------------------------------------------------*/
2
/*------------------------------- File Bag.h -------------------------------*/
3
/*--------------------------------------------------------------------------*/
32
/*--------------------------------------------------------------------------*/
33
/*----------------------------- DEFINITIONS --------------------------------*/
34
/*--------------------------------------------------------------------------*/
35
36
#ifndef __ADS_Bag
37
#define __ADS_Bag
38
/* self-identification: #endif constant */
39
40
/*--------------------------------------------------------------------------*/
41
/*------------------------------ INCLUDES ----------------------------------*/
42
/*--------------------------------------------------------------------------*/
43
44
#include "
ADS/Contract.h
"
45
#include "
ADS/dictionary/FlatHashTable.h
"
46
47
#include <cstddef>
48
#include <functional>
49
#include <utility>
50
#include <vector>
51
52
/*--------------------------------------------------------------------------*/
53
/*--------------------------- NAMESPACE ------------------------------------*/
54
/*--------------------------------------------------------------------------*/
55
56
namespace
ADS
57
{
58
59
/*--------------------------------------------------------------------------*/
60
/*------------------------------- CLASS Bag --------------------------------*/
61
/*--------------------------------------------------------------------------*/
62
65
template
<
class
T ,
class
H = DefaultHash< T > ,
66
class
Eq = std::equal_to< T > >
67
class
Bag
68
{
69
70
/*--------------------------------------------------------------------------*/
71
public
:
72
using
Item
= T;
73
75
explicit
Bag
( H h = H() , Eq eq = Eq() ) : f_T( 0 , h , eq ) { }
76
78
[[nodiscard]] std::size_t
size
(
void
)
const
{
return
( f_n ); }
79
81
[[nodiscard]]
bool
empty
(
void
)
const
{
return
( f_n == 0 ); }
82
84
[[nodiscard]] std::size_t
distinct
(
void
)
const
{
return
( f_T.size() ); }
85
101
bool
insert
(
const
T & x );
102
119
bool
remove
(
const
T & x );
120
123
[[nodiscard]]
const
T *
find
(
const
T & x )
const
;
124
126
[[nodiscard]] std::vector< T >
findAll
(
const
T & x )
const
;
127
129
[[nodiscard]] std::size_t
count
(
const
T & x )
const
;
130
131
/*--------------------------------------------------------------------------*/
132
private
:
134
[[nodiscard]]
bool
counted(
void
)
const
;
135
136
FlatHashTable< T , std::vector< T >
, H , Eq > f_T;
137
std::size_t f_n = 0;
138
139
};
// end( class Bag )
140
141
/*--------------------------------------------------------------------------*/
142
143
}
// end( namespace ADS )
144
145
/*--------------------------------------------------------------------------*/
146
/*-------------------------- IMPLEMENTATION --------------------------------*/
147
/*--------------------------------------------------------------------------*/
148
149
#include "ADS/set/impl/Bag.tpp"
150
151
/*--------------------------------------------------------------------------*/
152
153
#endif
/* Bag.h included */
154
155
/*--------------------------------------------------------------------------*/
156
/*----------------------------- End File Bag.h -----------------------------*/
157
/*--------------------------------------------------------------------------*/
Contract.h
The contracts of ADS: the preconditions, the postconditions and the invariants of the operations,...
FlatHashTable.h
A hash table with open addressing and control bytes, beyond the book: the engineered DICTIONARY of AD...
ADS::Bag::empty
bool empty(void) const
true if there is no item
Definition
Bag.h:81
ADS::Bag::count
std::size_t count(const T &x) const
the number of items equal to
ADS::Bag::Item
T Item
the type of the items
Definition
Bag.h:72
ADS::Bag::distinct
std::size_t distinct(void) const
the number of groups of equal items
Definition
Bag.h:84
ADS::Bag::size
std::size_t size(void) const
the number of items, the equal ones counted each
Definition
Bag.h:78
ADS::Bag::find
const T * find(const T &x) const
an item equal to , the first one added, nil if none, expected
ADS::Bag::Bag
Bag(H h=H(), Eq eq=Eq())
the empty bag
Definition
Bag.h:75
ADS::Bag::insert
bool insert(const T &x)
adds , expected amortized; always true
ADS::Bag::remove
bool remove(const T &x)
removes the last item added equal to , expected amortized; true if there was one
ADS::Bag::findAll
std::vector< T > findAll(const T &x) const
all the items equal to , in the order of their insertions
ADS::FlatHashTable
a hash table with open addressing and control bytes in groups of 15
Definition
FlatHashTable.h:252
ADS
Definition
ADT.h:96
ADS
set
Bag.h
Generated by
1.17.0