Add HashValue() methods to BString
This commit is contained in:
@@ -30,6 +30,9 @@ public:
|
|||||||
int32 charCount) const;
|
int32 charCount) const;
|
||||||
bool IsEmpty() const;
|
bool IsEmpty() const;
|
||||||
|
|
||||||
|
uint32 HashValue() const;
|
||||||
|
static uint32 HashValue(const char* string);
|
||||||
|
|
||||||
// Assignment
|
// Assignment
|
||||||
BString& operator=(const BString& string);
|
BString& operator=(const BString& string);
|
||||||
BString& operator=(const char* string);
|
BString& operator=(const char* string);
|
||||||
@@ -416,6 +419,13 @@ BString::String() const
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
inline uint32
|
||||||
|
BString::HashValue() const
|
||||||
|
{
|
||||||
|
return HashValue(String());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
inline BString &
|
inline BString &
|
||||||
BString::SetTo(const char* string)
|
BString::SetTo(const char* string)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -282,6 +282,23 @@ BString::CountBytes(int32 fromCharOffset, int32 charCount) const
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*static*/ uint32
|
||||||
|
BString::HashValue(const char* string)
|
||||||
|
{
|
||||||
|
// from the Dragon Book: a slightly modified hashpjw()
|
||||||
|
uint32 h = 0;
|
||||||
|
if (string != NULL) {
|
||||||
|
for (; *string; string++) {
|
||||||
|
uint32 g = h & 0xf0000000;
|
||||||
|
if (g)
|
||||||
|
h ^= g >> 24;
|
||||||
|
h = (h << 4) + *string;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return h;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// #pragma mark - Assignment
|
// #pragma mark - Assignment
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user