Run clang-format
[junction.git] / junction / MapTraits.h
1 /*------------------------------------------------------------------------
2   Junction: Concurrent data structures in C++
3   Copyright (c) 2016 Jeff Preshing
4
5   Distributed under the Simplified BSD License.
6   Original location: https://github.com/preshing/junction
7
8   This software is distributed WITHOUT ANY WARRANTY; without even the
9   implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10   See the LICENSE file for more information.
11 ------------------------------------------------------------------------*/
12
13 #ifndef JUNCTION_MAPTRAITS_H
14 #define JUNCTION_MAPTRAITS_H
15
16 #include <junction/Core.h>
17 #include <turf/Util.h>
18
19 namespace junction {
20
21 template <class T>
22 struct DefaultKeyTraits {
23     typedef T Key;
24     typedef typename turf::util::BestFit<T>::Unsigned Hash;
25     static const Hash NullHash = Hash(0);
26     static Hash hash(T key) {
27         return turf::util::avalanche(Hash(key));
28     }
29     static Key dehash(Hash hash) {
30         return (T) turf::util::deavalanche(hash);
31     }
32 };
33
34 template <class T>
35 struct DefaultValueTraits {
36     typedef T Value;
37     typedef typename turf::util::BestFit<T>::Unsigned IntType;
38     static const IntType NullValue = 0;
39     static const IntType Redirect = 1;
40 };
41
42 } // namespace junction
43
44 #endif // JUNCTION_MAPTRAITS_H