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.
15 // TODO: Move here from HashMap.h and adapt all clients.
17 template<typename Value
>
20 HashKey32(const Value
& value
) : value(value
) {}
22 uint32
GetHashCode() const
27 HashKey32
<Value
> operator=(const HashKey32
<Value
>& other
)
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
);
48 template<typename Value
>
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
)
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
);
80 struct 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()
89 const char* string
= value
.String();
91 for (; *string
; string
++) {
92 uint32 g
= hash
& 0xf0000000;
95 hash
= (hash
<< 4) + *string
;
101 HashKeyString
operator=(const HashKeyString
& other
)
107 bool operator==(const HashKeyString
& other
) const
109 return (value
== other
.value
);
112 bool operator!=(const HashKeyString
& other
) const
114 return (value
!= other
.value
);
120 } // namespace BPrivate
122 using BPrivate::HashKeyString
;
124 #endif // HASH_KEYS_H