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
36namespace Std {
37
42template <class T, class Hash = Common::Hash<T>, class Pred = Common::EqualTo<T> >
43class unordered_set : public Common::Array<T> {
44private:
45 Hash _hash;
46 Pred _comparitor;
47 public:
48 struct Entry {
49 const T &_value;
50 Entry(const T &item) : _value(item) {}
51 };
52public:
53 using iterator = typename Common::Array<T>::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
Definition: array.h:52
iterator end()
Definition: array.h:380
T * iterator
Definition: array.h:54
void push_back(const T &element)
Definition: array.h:181
iterator begin()
Definition: array.h:375
const T * const_iterator
Definition: array.h:55
Definition: unordered_set.h:43
iterator find(const T &item)
Definition: unordered_set.h:61
Entry insert(const T &item)
Definition: unordered_set.h:72
size_t count(const T item) const
Definition: unordered_set.h:80
Definition: unordered_set.h:48