1 /*
2 * Copyright 2014 Google Inc. All rights reserved.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 #ifndef FRUIT_HASH_HELPERS_DEFN_H
18 #define FRUIT_HASH_HELPERS_DEFN_H
19
20 #include <fruit/impl/meta/vector.h>
21 #include <fruit/impl/util/hash_helpers.h>
22
23 namespace fruit {
24 namespace impl {
25
26 template <typename T>
createHashSet()27 inline HashSet<T> createHashSet() {
28 return createHashSet<T>(10);
29 }
30
31 template <typename T>
createHashSet(size_t capacity)32 inline HashSet<T> createHashSet(size_t capacity) {
33 return HashSet<T>(capacity, std::hash<T>());
34 }
35
36 template <typename T>
createHashSetWithArenaAllocator(size_t capacity,MemoryPool & memory_pool)37 inline HashSetWithArenaAllocator<T> createHashSetWithArenaAllocator(size_t capacity, MemoryPool& memory_pool) {
38 return HashSetWithArenaAllocator<T>(capacity, std::hash<T>(), std::equal_to<T>(), ArenaAllocator<T>(memory_pool));
39 }
40
41 template <typename T, typename Hasher, typename EqualityComparator>
42 inline HashSetWithArenaAllocator<T, Hasher, EqualityComparator>
createHashSetWithArenaAllocatorAndCustomFunctors(size_t capacity,MemoryPool & memory_pool,Hasher hasher,EqualityComparator equality_comparator)43 createHashSetWithArenaAllocatorAndCustomFunctors(size_t capacity, MemoryPool& memory_pool, Hasher hasher,
44 EqualityComparator equality_comparator) {
45 return HashSetWithArenaAllocator<T, Hasher, EqualityComparator>(capacity, hasher, equality_comparator,
46 ArenaAllocator<T>(memory_pool));
47 }
48
49 template <typename Key, typename Value>
createHashMap()50 inline HashMap<Key, Value> createHashMap() {
51 return createHashMap<Key, Value>(10);
52 }
53
54 template <typename Key, typename Value>
createHashMap(size_t capacity)55 inline HashMap<Key, Value> createHashMap(size_t capacity) {
56 return HashMap<Key, Value>(capacity, std::hash<Key>());
57 }
58
59 template <typename Key, typename Value>
createHashMapWithArenaAllocator(std::size_t capacity,MemoryPool & memory_pool)60 inline HashMapWithArenaAllocator<Key, Value> createHashMapWithArenaAllocator(std::size_t capacity,
61 MemoryPool& memory_pool) {
62 return createHashMapWithArenaAllocatorAndCustomFunctors<Key, Value>(capacity, memory_pool, std::hash<Key>(),
63 std::equal_to<Key>());
64 }
65
66 template <typename Key, typename Value, typename Hasher, typename EqualityComparator>
67 inline HashMapWithArenaAllocator<Key, Value, Hasher, EqualityComparator>
createHashMapWithArenaAllocatorAndCustomFunctors(size_t capacity,MemoryPool & memory_pool,Hasher hasher,EqualityComparator equality_comparator)68 createHashMapWithArenaAllocatorAndCustomFunctors(size_t capacity, MemoryPool& memory_pool, Hasher hasher,
69 EqualityComparator equality_comparator) {
70 return HashMapWithArenaAllocator<Key, Value, Hasher, EqualityComparator>(
71 capacity, hasher, equality_comparator, ArenaAllocator<std::pair<const Key, Value>>{memory_pool});
72 }
73
74 } // namespace impl
75 } // namespace fruit
76
77 #endif // FRUIT_HASH_HELPERS_DEFN_H
78