Made static String::hash() capable of incremental hashing.
git-svn-id: http://yate.null.ro/svn/yate/trunk@5859 acf43c95-373e-0410-b603-e72c3f656dc1
This commit is contained in:
parent
7c7d9e2a16
commit
ce97d09aa4
|
@ -1350,12 +1350,11 @@ String String::uriUnescape(const char* str, int* errptr)
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned int String::hash(const char* value)
|
unsigned int String::hash(const char* value, unsigned int h)
|
||||||
{
|
{
|
||||||
if (!value)
|
if (!value)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
unsigned int h = 0;
|
|
||||||
// sdbm hash algorithm, hash(i) = hash(i-1) * 65599 + str[i]
|
// sdbm hash algorithm, hash(i) = hash(i-1) * 65599 + str[i]
|
||||||
while (unsigned char c = (unsigned char) *value++)
|
while (unsigned char c = (unsigned char) *value++)
|
||||||
h = (h << 6) + (h << 16) - h + c;
|
h = (h << 6) + (h << 16) - h + c;
|
||||||
|
|
|
@ -1994,9 +1994,10 @@ public:
|
||||||
/**
|
/**
|
||||||
* Get the hash of an arbitrary string.
|
* Get the hash of an arbitrary string.
|
||||||
* @param value C string to hash
|
* @param value C string to hash
|
||||||
|
* @param h Old hash value for incremental hashing
|
||||||
* @return The hash of the string.
|
* @return The hash of the string.
|
||||||
*/
|
*/
|
||||||
static unsigned int hash(const char* value);
|
static unsigned int hash(const char* value, unsigned int h = 0);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Clear the string and free the memory
|
* Clear the string and free the memory
|
||||||
|
|
Loading…
Reference in New Issue