aboutsummaryrefslogtreecommitdiffstats
path: root/include/asterisk/strings.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/asterisk/strings.h')
-rw-r--r--include/asterisk/strings.h19
1 files changed, 19 insertions, 0 deletions
diff --git a/include/asterisk/strings.h b/include/asterisk/strings.h
index 68ecb2048..2fff9c133 100644
--- a/include/asterisk/strings.h
+++ b/include/asterisk/strings.h
@@ -23,6 +23,7 @@
#ifndef _ASTERISK_STRINGS_H
#define _ASTERISK_STRINGS_H
+#include <stdlib.h>
#include <string.h>
#include <stdarg.h>
@@ -263,4 +264,22 @@ struct ast_realloca {
(ra)->ptr; \
})
+/*!
+ * \brief Compute a hash value on a string
+ *
+ * This famous hash algorithm was written by Dan Bernstein and is
+ * commonly used.
+ *
+ * http://www.cse.yorku.ca/~oz/hash.html
+ */
+static force_inline int ast_str_hash(const char *str)
+{
+ int hash = 5381;
+
+ while (*str)
+ hash = hash * 33 ^ *str++;
+
+ return abs(hash);
+}
+
#endif /* _ASTERISK_STRINGS_H */