/* Copyright (c) 1998-2015, Enno Rehling Katja Zedel Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies. THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. **/ #ifndef STRINGS_H #define STRINGS_H #include #ifdef __cplusplus extern "C" { #endif char *set_string(char **s, const char *neu); unsigned int hashstring(const char *s); const char *escape_string(const char *str, char *buffer, size_t len); unsigned int jenkins_hash(unsigned int a); unsigned int wang_hash(unsigned int a); /* benchmark for units: * JENKINS_HASH: 5.25 misses/hit (with good cache behavior) * WANG_HASH: 5.33 misses/hit (with good cache behavior) * KNUTH_HASH: 1.93 misses/hit (with bad cache behavior) * CF_HASH: fucking awful! */ #define KNUTH_HASH1(a, m) ((a) % m) #define KNUTH_HASH2(a, m) (m - 2 - a % (m-2)) #define CF_HASH1(a, m) ((a) % m) #define CF_HASH2(a, m) (8 - ((a) & 7)) #define JENKINS_HASH1(a, m) (jenkins_hash(a) % m) #define JENKINS_HASH2(a, m) 1 #define WANG_HASH1(a, m) (wang_hash(a) % m) #define WANG_HASH2(a, m) 1 #define HASH1 JENKINS_HASH1 #define HASH2 JENKINS_HASH2 #ifdef __cplusplus } #endif #endif /* STRINGS_H */