00001
00002
00003
00004
00005
00006
00007
00008
00009 #include <string.h>
00010
00011 #include "setGetHashTable.h"
00012 #include "MALLOC.h"
00013
00014
00015
00016
00017
00018 static unsigned int setGetHashTableHash( void * key )
00019 {
00020 unsigned long hash = 5381;
00021 int c ;
00022 char * str = key ;
00023
00024 while ( (c = *str++) )
00025 {
00026 hash = ((hash << 5) + hash) + c ;
00027 }
00028
00029 return hash;
00030
00031 }
00032
00033 static int setGetHashTableEqualKeys( void * k1, void * k2 )
00034 {
00035 if ( strcmp( (char *)k1, (char *)k2 ) == 0 )
00036 {
00037 return 1 ;
00038 }
00039 return 0 ;
00040 }
00041
00042 GetPropertyHashTable * createGetHashTable( void )
00043 {
00044 return create_hashtable(16, setGetHashTableHash, setGetHashTableEqualKeys ) ;
00045 }
00046
00047 void destroyGetHashTable( GetPropertyHashTable * hashTable )
00048 {
00049
00050 hashtable_destroy( hashTable, 0 ) ;
00051 }
00052
00053 getPropertyFunc searchGetHashtable( GetPropertyHashTable * hashTable, char * key )
00054 {
00055 return (getPropertyFunc) hashtable_search( hashTable, key ) ;
00056 }
00057
00058 int insertGetHashtable( GetPropertyHashTable * hashTable, char * key, getPropertyFunc value )
00059 {
00060
00061
00062 char * copyKey = NULL ;
00063 int keyLength = strlen( key ) + 1 ;
00064
00065 copyKey = MALLOC( keyLength * sizeof(char) ) ;
00066 if ( copyKey == NULL ) { return 0 ; }
00067 strcpy( copyKey, key ) ;
00068
00069 return hashtable_insert( hashTable, copyKey, value ) ;
00070 }
00071
00072 SetPropertyHashTable * createSetHashTable( void )
00073 {
00074 return create_hashtable(16, setGetHashTableHash, setGetHashTableEqualKeys ) ;
00075 }
00076
00077 void destroySetHashTable( SetPropertyHashTable * hashTable )
00078 {
00079
00080 hashtable_destroy( hashTable, 0 ) ;
00081 }
00082
00083 setPropertyFunc searchSetHashtable( SetPropertyHashTable * hashTable, char * key )
00084 {
00085 return (setPropertyFunc) hashtable_search( hashTable, key ) ;
00086 }
00087
00088 int insertSetHashtable( SetPropertyHashTable * hashTable, char * key, setPropertyFunc value )
00089 {
00090
00091
00092 char * copyKey = NULL ;
00093 int keyLength = strlen( key ) + 1 ;
00094
00095 copyKey = MALLOC( keyLength * sizeof(char) ) ;
00096 strcpy( copyKey, key ) ;
00097
00098 return hashtable_insert( hashTable, copyKey, value ) ;
00099 }
00100