Krita Source Code Documentation
Loading...
Searching...
No Matches
map_traits.h
Go to the documentation of this file.
1/*------------------------------------------------------------------------
2 Junction: Concurrent data structures in C++
3 Copyright (c) 2016 Jeff Preshing
4 Distributed under the Simplified BSD License.
5 Original location: https://github.com/preshing/junction
6 This software is distributed WITHOUT ANY WARRANTY; without even the
7 implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
8 See the LICENSE file for more information.
9------------------------------------------------------------------------*/
10
11#ifndef MAPTRAITS_H
12#define MAPTRAITS_H
13
14#include <QtCore>
15
16inline quint64 roundUpPowerOf2(quint64 v)
17{
18 v--;
19 v |= v >> 1;
20 v |= v >> 2;
21 v |= v >> 4;
22 v |= v >> 8;
23 v |= v >> 16;
24 v |= v >> 32;
25 v++;
26 return v;
27}
28
29inline bool isPowerOf2(quint64 v)
30{
31 return (v & (v - 1)) == 0;
32}
33
34inline quint32 avalanche(quint32 h)
35{
36 h ^= h >> 16;
37 h *= 0x85ebca6b;
38 h ^= h >> 13;
39 h *= 0xc2b2ae35;
40 h ^= h >> 16;
41 return h;
42}
43
44inline quint32 deavalanche(quint32 h)
45{
46 h ^= h >> 16;
47 h *= 0x7ed1b41d;
48 h ^= (h ^ (h >> 13)) >> 13;
49 h *= 0xa5cb9243;
50 h ^= h >> 16;
51 return h;
52}
53
54template <class T>
56 typedef T Key;
57 typedef quint32 Hash;
58 static const Key NullKey = Key(0);
59 static const Hash NullHash = Hash(0);
60
61 static Hash hash(T key)
62 {
63 return avalanche(Hash(key));
64 }
65
67 {
68 return (T) deavalanche(hash);
69 }
70};
71
72template <class T>
74 typedef T Value;
75 typedef std::intptr_t IntType;
76 static const IntType NullValue = 0;
77 static const IntType Redirect = 1;
78};
79
80#endif // MAPTRAITS_H
qreal v
quint32 avalanche(quint32 h)
Definition map_traits.h:34
bool isPowerOf2(quint64 v)
Definition map_traits.h:29
quint32 deavalanche(quint32 h)
Definition map_traits.h:44
quint64 roundUpPowerOf2(quint64 v)
Definition map_traits.h:16
static const Hash NullHash
Definition map_traits.h:59
static Hash hash(T key)
Definition map_traits.h:61
static const Key NullKey
Definition map_traits.h:58
static Key dehash(Hash hash)
Definition map_traits.h:66
static const IntType NullValue
Definition map_traits.h:76
std::intptr_t IntType
Definition map_traits.h:75
static const IntType Redirect
Definition map_traits.h:77