From ce97d09aa44ab7a6b867a2e037ef599948a2f829 Mon Sep 17 00:00:00 2001 From: paulc Date: Wed, 2 Jul 2014 07:30:37 +0000 Subject: [PATCH] Made static String::hash() capable of incremental hashing. git-svn-id: http://yate.null.ro/svn/yate/trunk@5859 acf43c95-373e-0410-b603-e72c3f656dc1 --- engine/String.cpp | 3 +-- yateclass.h | 3 ++- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/engine/String.cpp b/engine/String.cpp index e519f2d9..a81277e6 100644 --- a/engine/String.cpp +++ b/engine/String.cpp @@ -1350,12 +1350,11 @@ String String::uriUnescape(const char* str, int* errptr) return s; } -unsigned int String::hash(const char* value) +unsigned int String::hash(const char* value, unsigned int h) { if (!value) return 0; - unsigned int h = 0; // sdbm hash algorithm, hash(i) = hash(i-1) * 65599 + str[i] while (unsigned char c = (unsigned char) *value++) h = (h << 6) + (h << 16) - h + c; diff --git a/yateclass.h b/yateclass.h index 4f0e9112..bb8e9cdb 100644 --- a/yateclass.h +++ b/yateclass.h @@ -1994,9 +1994,10 @@ public: /** * Get the hash of an arbitrary string. * @param value C string to hash + * @param h Old hash value for incremental hashing * @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