/* * Copyright 2010, Stephan Aßmus . All rights reserved. * Copyright 2004-2007, Ingo Weinhold . All rights reserved. * Distributed under the terms of the MIT License. */ #ifndef HASH_KEYS_H #define HASH_KEYS_H #include namespace BPrivate { #if 0 // TODO: Move here from HashMap.h and adapt all clients. // HashKey32 template struct HashKey32 { HashKey32() {} HashKey32(const Value& value) : value(value) {} uint32 GetHashCode() const { return (uint32)value; } HashKey32 operator=(const HashKey32& other) { value = other.value; return *this; } bool operator==(const HashKey32& other) const { return (value == other.value); } bool operator!=(const HashKey32& other) const { return (value != other.value); } Value value; }; // HashKey64 template struct HashKey64 { HashKey64() {} HashKey64(const Value& value) : value(value) {} uint32 GetHashCode() const { uint64 v = (uint64)value; return (uint32)(v >> 32) ^ (uint32)v; } HashKey64 operator=(const HashKey64& other) { value = other.value; return *this; } bool operator==(const HashKey64& other) const { return (value == other.value); } bool operator!=(const HashKey64& other) const { return (value != other.value); } Value value; }; #endif struct HashKeyString { HashKeyString() {} HashKeyString(const BString& value) : value(value) {} HashKeyString(const char* string) : value(string) {} uint32 GetHashCode() const { // from the Dragon Book: a slightly modified hashpjw() uint32 hash = 0; const char* string = value.String(); if (string != NULL) { for (; *string; string++) { uint32 g = hash & 0xf0000000; if (g != 0) hash ^= g >> 24; hash = (hash << 4) + *string; } } return hash; } HashKeyString operator=(const HashKeyString& other) { value = other.value; return *this; } bool operator==(const HashKeyString& other) const { return (value == other.value); } bool operator!=(const HashKeyString& other) const { return (value != other.value); } BString value; }; } // namespace BPrivate using BPrivate::HashKeyString; #endif // HASH_KEYS_H