[sr-dev] git:master: core: use const char*/str* for hash functions

Andrei Pelinescu-Onciul andrei at iptel.org
Thu Aug 26 22:01:27 CEST 2010


Module: sip-router
Branch: master
Commit: e8ef6f9a86e14e50634a8bae6db0b0e164cda917
URL:    http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=e8ef6f9a86e14e50634a8bae6db0b0e164cda917

Author: Andrei Pelinescu-Onciul <andrei at iptel.org>
Committer: Andrei Pelinescu-Onciul <andrei at iptel.org>
Date:   Thu Aug 26 21:40:45 2010 +0200

core: use const char*/str* for hash functions

---

 hashes.h   |   25 +++++++++++++------------
 str_hash.h |    2 +-
 2 files changed, 14 insertions(+), 13 deletions(-)

diff --git a/hashes.h b/hashes.h
index 58debe4..e6b5f7f 100644
--- a/hashes.h
+++ b/hashes.h
@@ -83,7 +83,7 @@
 /* "raw" 2 strings hash
  * returns an unsigned int (which you can use modulo table_size as hash value)
  */
-inline static unsigned int get_hash2_raw(str* key1, str* key2)
+inline static unsigned int get_hash2_raw(const str* key1, const str* key2)
 {
 	char* p;
 	register unsigned v;
@@ -101,9 +101,9 @@ inline static unsigned int get_hash2_raw(str* key1, str* key2)
 /* "raw" 1 string hash
  * returns an unsigned int (which you can use modulo table_size as hash value)
  */
-inline static unsigned int get_hash1_raw(char* s, int len)
+inline static unsigned int get_hash1_raw(const char* s, int len)
 {
-	char* p;
+	const char* p;
 	register unsigned v;
 	register unsigned h;
 	
@@ -148,9 +148,9 @@ inline static unsigned int get_hash1_raw(char* s, int len)
 
 /* a little slower than get_hash1_raw() , but better distribution for 
  * numbers and about the same for strings */
-inline static unsigned int get_hash1_raw2(char* s, int len)
+inline static unsigned int get_hash1_raw2(const char* s, int len)
 {
-	char* p;
+	const char* p;
 	register unsigned v;
 	register unsigned h;
 	
@@ -165,7 +165,7 @@ inline static unsigned int get_hash1_raw2(char* s, int len)
 /* "raw" 2 strings hash optimized for numeric strings (see above)
  * returns an unsigned int (which you can use modulo table_size as hash value)
  */
-inline static unsigned int get_hash2_raw2(str* key1, str* key2)
+inline static unsigned int get_hash2_raw2(const str* key1, const str* key2)
 {
 	char* p;
 	register unsigned v;
@@ -184,7 +184,7 @@ inline static unsigned int get_hash2_raw2(str* key1, str* key2)
  * insensitive)
  * returns an unsigned int (which you can use modulo table_size as hash value)
  */
-inline static unsigned int get_hash2_case_raw(str* key1, str* key2)
+inline static unsigned int get_hash2_case_raw(const str* key1, const str* key2)
 {
 	char* p;
 	register unsigned v;
@@ -202,9 +202,9 @@ inline static unsigned int get_hash2_case_raw(str* key1, str* key2)
 /* "raw" 1 string case insensitive hash
  * returns an unsigned int (which you can use modulo table_size as hash value)
  */
-inline static unsigned int get_hash1_case_raw(char* s, int len)
+inline static unsigned int get_hash1_case_raw(const char* s, int len)
 {
-	char* p;
+	const char* p;
 	register unsigned v;
 	register unsigned h;
 	
@@ -218,9 +218,9 @@ inline static unsigned int get_hash1_case_raw(char* s, int len)
 /* same as get_hash1_raw2, but case insensitive and slower
  * returns an unsigned int (which you can use modulo table_size as hash value)
  */
-inline static unsigned int get_hash1_case_raw2(char* s, int len)
+inline static unsigned int get_hash1_case_raw2(const char* s, int len)
 {
-	char* p;
+	const char* p;
 	register unsigned v;
 	register unsigned h;
 	
@@ -236,7 +236,8 @@ inline static unsigned int get_hash1_case_raw2(char* s, int len)
  * same as get_hash2_raw2 but case insensitive and slower
  * returns an unsigned int (which you can use modulo table_size as hash value)
  */
-inline static unsigned int get_hash2_case_raw2(str* key1, str* key2)
+inline static unsigned int get_hash2_case_raw2(const str* key1,
+											   const str* key2)
 {
 	char* p;
 	register unsigned v;
diff --git a/str_hash.h b/str_hash.h
index 3c0e17c..1de9748 100644
--- a/str_hash.h
+++ b/str_hash.h
@@ -96,7 +96,7 @@ inline static void str_hash_add(struct str_hash_table* ht,
 
 
 inline static struct str_hash_entry* str_hash_get(struct str_hash_table* ht,
-									char* key, int len)
+									const char* key, int len)
 {
 	int h;
 	struct str_hash_entry* e;




More information about the sr-dev mailing list