summaryrefslogtreecommitdiff
path: root/include/llvm/ADT/StringExtras.h
diff options
context:
space:
mode:
authorDaniel Dunbar <daniel@zuster.org>2009-10-17 18:21:06 +0000
committerDaniel Dunbar <daniel@zuster.org>2009-10-17 18:21:06 +0000
commit4dee7fd2c2cb3fabddf99a184abe41dbc0bd4085 (patch)
tree9cab4086d71a65bc16259b5a2653a2ba56bf9680 /include/llvm/ADT/StringExtras.h
parent4e34a3912ad5c1a4f82c18bffa98898d5a4ea4c4 (diff)
downloadllvm-4dee7fd2c2cb3fabddf99a184abe41dbc0bd4085.tar.gz
llvm-4dee7fd2c2cb3fabddf99a184abe41dbc0bd4085.tar.bz2
llvm-4dee7fd2c2cb3fabddf99a184abe41dbc0bd4085.tar.xz
Move StringMap's string has function into StringExtras.h
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@84344 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include/llvm/ADT/StringExtras.h')
-rw-r--r--include/llvm/ADT/StringExtras.h14
1 files changed, 14 insertions, 0 deletions
diff --git a/include/llvm/ADT/StringExtras.h b/include/llvm/ADT/StringExtras.h
index 3d1993c6b2..515cda4b29 100644
--- a/include/llvm/ADT/StringExtras.h
+++ b/include/llvm/ADT/StringExtras.h
@@ -16,6 +16,7 @@
#include "llvm/Support/DataTypes.h"
#include "llvm/ADT/APFloat.h"
+#include "llvm/ADT/StringRef.h"
#include <cctype>
#include <cstdio>
#include <string>
@@ -225,6 +226,19 @@ void UnescapeString(std::string &Str);
/// doesn't satisfy std::isprint into an escape sequence.
void EscapeString(std::string &Str);
+/// HashString - Hash funtion for strings.
+///
+/// This is the Bernstein hash function.
+//
+// FIXME: Investigate whether a modified bernstein hash function performs
+// better: http://eternallyconfuzzled.com/tuts/algorithms/jsw_tut_hashing.aspx
+// X*33+c -> X*33^c
+static inline unsigned HashString(StringRef Str, unsigned Result = 0) {
+ for (unsigned i = 0, e = Str.size(); i != e; ++i)
+ Result = Result * 33 + Str[i];
+ return Result;
+}
+
} // End llvm namespace
#endif