ScummVM API documentation
unordered_set.h
1
/* ScummVM - Graphic Adventure Engine
2
*
3
* ScummVM is the legal property of its developers, whose names
4
* are too numerous to list here. Please refer to the COPYRIGHT
5
* file distributed with this source distribution.
6
*
7
* This program is free software: you can redistribute it and/or modify
8
* it under the terms of the GNU General Public License as published by
9
* the Free Software Foundation, either version 3 of the License, or
10
* (at your option) any later version.
11
*
12
* This program is distributed in the hope that it will be useful,
13
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
* GNU General Public License for more details.
16
*
17
* You should have received a copy of the GNU General Public License
18
* along with this program. If not, see <http://www.gnu.org/licenses/>.
19
*
20
*/
21
22
/********************************************
23
DISCLAIMER:
24
25
This is a wrapper code to mimic the relevant std:: class
26
Please use it ONLY when porting an existing code e.g. from the original sources
27
28
For all new development please use classes from Common::
29
*********************************************/
30
31
#ifndef COMMON_STD_UNORDERED_SET_H
32
#define COMMON_STD_UNORDERED_SET_H
33
34
#include "common/array.h"
35
36
namespace
Std
{
37
42
template
<
class
T,
class
Hash = Common::Hash<T>,
class
Pred = Common::EqualTo<T> >
43
class
unordered_set
:
public
Common::Array
<T> {
44
private
:
45
Hash _hash;
46
Pred _comparitor;
47
public
:
48
struct
Entry
{
49
const
T &_value;
50
Entry
(
const
T &item) : _value(item) {}
51
};
52
public
:
53
using
iterator
=
typename
Common::Array<T>::iterator
;
54
using
const_iterator
=
typename
Common::Array<T>::const_iterator
;
55
56
unordered_set
() {}
57
61
iterator
find
(
const
T &item) {
62
iterator
it;
63
for
(it = this->
begin
(); it != this->
end
() && *it != item; ++it) {
64
}
65
66
return
it;
67
}
68
72
Entry
insert
(
const
T &item) {
73
this->
push_back
(item);
74
return
Entry(item);
75
}
76
80
size_t
count
(
const
T item)
const
{
81
size_t
total = 0;
82
for
(
const_iterator
it = this->
begin
(); it != this->
end
(); ++it) {
83
if
(*it == item)
84
++total;
85
else
if
(!_comparitor(item, *it))
86
// Passed beyond possibility of matches
87
break
;
88
}
89
90
return
total;
91
}
92
};
93
94
}
// namespace Std
95
96
#endif
Common::Array
Definition:
array.h:52
Common::Array::end
iterator end()
Definition:
array.h:379
Common::Array::begin
iterator begin()
Definition:
array.h:374
Common::Array::iterator
T * iterator
Definition:
array.h:54
Common::Rect
Definition:
rect.h:144
Common::Array::push_back
void push_back(const T &element)
Definition:
array.h:180
Common::Array::const_iterator
const T * const_iterator
Definition:
array.h:55
Std::unordered_set::insert
Entry insert(const T &item)
Definition:
unordered_set.h:72
Std::unordered_set::Entry
Definition:
unordered_set.h:48
Std::unordered_set::find
iterator find(const T &item)
Definition:
unordered_set.h:61
Std::unordered_set
Definition:
unordered_set.h:43
Std::unordered_set::count
size_t count(const T item) const
Definition:
unordered_set.h:80
Std
Definition:
algorithm.h:37
common
std
unordered_set.h
Generated on Sat Aug 31 2024 09:07:00 for ScummVM API documentation by
1.8.13