btrfs: Attempt to fix GCC2 build.
[haiku.git] / src / apps / webpositive / support / HashKeys.h
blob3480b5649204982471f46b60190e68bff8e9be77
1 /*
2 * Copyright 2010, Stephan Aßmus <superstippi@gmx.de>. All rights reserved.
3 * Copyright 2004-2007, Ingo Weinhold <ingo_weinhold@gmx.de>. All rights reserved.
4 * Distributed under the terms of the MIT License.
5 */
6 #ifndef HASH_KEYS_H
7 #define HASH_KEYS_H
9 #include <String.h>
12 namespace BPrivate {
14 #if 0
15 // TODO: Move here from HashMap.h and adapt all clients.
16 // HashKey32
17 template<typename Value>
18 struct HashKey32 {
19 HashKey32() {}
20 HashKey32(const Value& value) : value(value) {}
22 uint32 GetHashCode() const
24 return (uint32)value;
27 HashKey32<Value> operator=(const HashKey32<Value>& other)
29 value = other.value;
30 return *this;
33 bool operator==(const HashKey32<Value>& other) const
35 return (value == other.value);
38 bool operator!=(const HashKey32<Value>& other) const
40 return (value != other.value);
43 Value value;
47 // HashKey64
48 template<typename Value>
49 struct HashKey64 {
50 HashKey64() {}
51 HashKey64(const Value& value) : value(value) {}
53 uint32 GetHashCode() const
55 uint64 v = (uint64)value;
56 return (uint32)(v >> 32) ^ (uint32)v;
59 HashKey64<Value> operator=(const HashKey64<Value>& other)
61 value = other.value;
62 return *this;
65 bool operator==(const HashKey64<Value>& other) const
67 return (value == other.value);
70 bool operator!=(const HashKey64<Value>& other) const
72 return (value != other.value);
75 Value value;
77 #endif
80 struct HashKeyString {
81 HashKeyString() {}
82 HashKeyString(const BString& value) : value(value) {}
83 HashKeyString(const char* string) : value(string) {}
85 uint32 GetHashCode() const
87 // from the Dragon Book: a slightly modified hashpjw()
88 uint32 hash = 0;
89 const char* string = value.String();
90 if (string != NULL) {
91 for (; *string; string++) {
92 uint32 g = hash & 0xf0000000;
93 if (g != 0)
94 hash ^= g >> 24;
95 hash = (hash << 4) + *string;
98 return hash;
101 HashKeyString operator=(const HashKeyString& other)
103 value = other.value;
104 return *this;
107 bool operator==(const HashKeyString& other) const
109 return (value == other.value);
112 bool operator!=(const HashKeyString& other) const
114 return (value != other.value);
117 BString value;
120 } // namespace BPrivate
122 using BPrivate::HashKeyString;
124 #endif // HASH_KEYS_H