aboutsummaryrefslogtreecommitdiffstats
path: root/vespalib/src/vespa/vespalib/stllike/hash_set.hpp
blob: 332f0c8df69edb8c05355977be5d8d2f6ba42a10 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#pragma once

#include "hash_set_insert.hpp"
#include "hashtable.hpp"
#include "identity.h"

namespace vespalib {

template<typename K, typename H, typename EQ, typename M>
hash_set<K, H, EQ, M>::hash_set()
    : _ht(0)
{ }

template<typename K, typename H, typename EQ, typename M>
hash_set<K, H, EQ, M>::hash_set(size_t reserveSize)
    : _ht(reserveSize)
{ }

template<typename K, typename H, typename EQ, typename M>
hash_set<K, H, EQ, M>::hash_set(size_t reserveSize, const H &hasher, const EQ &equal)
    : _ht(reserveSize, hasher, equal)
{ }

template<typename K, typename H, typename EQ, typename M>
hash_set<K, H, EQ, M>::hash_set(std::initializer_list<K> input)
    : _ht(0)
{
    insert(input.begin(), input.end());
}

template<typename K, typename H, typename EQ, typename M>
hash_set<K, H, EQ, M>::~hash_set() = default;

template<typename K, typename H, typename EQ, typename M>
bool
hash_set<K, H, EQ, M>::operator==(const hash_set &rhs) const {
    bool equal = (size() == rhs.size());
    if (equal) {
        for (auto itr = begin(), endItr = end(); equal && itr != endItr; ++itr) {
            equal = (rhs.find(*itr) != rhs.end());
        }
    }
    return equal;
}

template<typename K, typename H, typename EQ, typename M>
void
hash_set<K, H, EQ, M>::clear() {
    _ht.clear();
}

template<typename K, typename H, typename EQ, typename M>
void
hash_set<K, H, EQ, M>::resize(size_t newSize) {
    _ht.resize(newSize);
}

template<typename K, typename H, typename EQ, typename M>
void
hash_set<K, H, EQ, M>::swap(hash_set &rhs) {
    _ht.swap(rhs._ht);
}

template<typename K, typename H, typename EQ, typename M>
size_t
hash_set<K, H, EQ, M>::getMemoryConsumption() const {
    return _ht.getMemoryConsumption();
}

template<typename K, typename H, typename EQ, typename M>
void
hash_set<K, H, EQ, M>::erase(const K &key) {
    return _ht.erase(key);
}

template<typename K, typename H, typename EQ, typename M>
typename hash_set<K, H, EQ, M>::insert_result
hash_set<K, H, EQ, M>::insert(const K & value) {
    return _ht.insert(value);
}

template<typename K, typename H, typename EQ, typename M>
typename hash_set<K, H, EQ, M>::insert_result
hash_set<K, H, EQ, M>::insert(K &&value) {
    return _ht.insert(std::move(value));
}

}

#define VESPALIB_HASH_SET_INSTANTIATE(K) \
    template class vespalib::hash_set<K>; \
    template class vespalib::hashtable<K, K, vespalib::hash<K>, std::equal_to<>, vespalib::Identity, vespalib::hashtable_base::and_modulator>;

#define VESPALIB_HASH_SET_INSTANTIATE_H(K, H) \
    template class vespalib::hash_set<K, H>; \
    template class vespalib::hashtable<K, K, H, std::equal_to<>, vespalib::Identity, vespalib::hashtable_base::and_modulator>;