1/* 2 * Copyright 2011, Oliver Tappe <zooey@hirschkaefer.de> 3 * Distributed under the terms of the MIT License. 4 */ 5#ifndef _PACKAGE__PRIVATE__HASHABLE_STRING_H_ 6#define _PACKAGE__PRIVATE__HASHABLE_STRING_H_ 7 8 9#include <String.h> 10 11#include <HashString.h> 12 13 14namespace BPackageKit { 15 16namespace BPrivate { 17 18 19class HashableString : public BString { 20public: 21 inline HashableString(); 22 23 inline HashableString(const BString& string); 24 25 inline uint32 GetHashCode() const; 26 27 inline bool operator!= (const HashableString& other) const; 28 29private: 30 uint32 fHashCode; 31}; 32 33 34inline 35HashableString::HashableString() 36 : 37 fHashCode(0) 38{ 39} 40 41 42inline 43HashableString::HashableString(const BString& string) 44 : 45 BString(string), 46 fHashCode(string_hash(String())) 47{ 48} 49 50 51inline uint32 52HashableString::GetHashCode() const 53{ 54 return fHashCode; 55} 56 57 58inline bool 59HashableString::operator!= (const HashableString& other) const 60{ 61 return Compare(other) != 0 || fHashCode != other.fHashCode; 62} 63 64 65} // namespace BPrivate 66 67} // namespace BPackageKit 68 69 70#endif // _PACKAGE__PRIVATE__HASHABLE_STRING_H_ 71