Changeset 4385 for pjproject/branches/1.x/pjlib/src/pj/hash.c
- Timestamp:
- Feb 27, 2013 10:11:59 AM (10 years ago)
- Location:
- pjproject/branches/1.x
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/branches/1.x
- Property svn:mergeinfo changed
/pjproject/trunk merged: 4208,4296
- Property svn:mergeinfo changed
-
pjproject/branches/1.x/pjlib/src/pj/hash.c
r3553 r4385 80 80 for (i=0; i<key->slen; ++i) { 81 81 pj_uint8_t c = key->ptr[i]; 82 char lower; 82 83 if (c & 64) 83 result[i]= (char)(c | 32);84 lower = (char)(c | 32); 84 85 else 85 result[i] = (char)c; 86 hval = hval * PJ_HASH_MULTIPLIER + result[i]; 86 lower = (char)c; 87 if (result) 88 result[i] = lower; 89 hval = hval * PJ_HASH_MULTIPLIER + lower; 87 90 } 88 91 #else 89 92 for (i=0; i<key->slen; ++i) { 90 result[i] = (char)pj_tolower(key->ptr[i]); 91 hval = hval * PJ_HASH_MULTIPLIER + result[i]; 93 char lower = (char)pj_tolower(key->ptr[i]); 94 if (result) 95 result[i] = lower; 96 hval = hval * PJ_HASH_MULTIPLIER + lower; 92 97 } 93 98 #endif … … 129 134 const void *key, unsigned keylen, 130 135 void *val, pj_uint32_t *hval, 131 void *entry_buf )136 void *entry_buf, pj_bool_t lower) 132 137 { 133 138 pj_uint32_t hash; … … 147 152 const pj_uint8_t *p = (const pj_uint8_t*)key; 148 153 for ( ; *p; ++p ) { 149 hash = hash * PJ_HASH_MULTIPLIER + *p; 154 if (lower) 155 hash = hash * PJ_HASH_MULTIPLIER + pj_tolower(*p); 156 else 157 hash = hash * PJ_HASH_MULTIPLIER + *p; 150 158 } 151 159 keylen = p - (const unsigned char*)key; … … 154 162 *end = p + keylen; 155 163 for ( ; p!=end; ++p) { 156 hash = hash * PJ_HASH_MULTIPLIER + *p; 164 if (lower) 165 hash = hash * PJ_HASH_MULTIPLIER + pj_tolower(*p); 166 else 167 hash = hash * PJ_HASH_MULTIPLIER + *p; 157 168 } 158 169 } … … 169 180 { 170 181 if (entry->hash==hash && entry->keylen==keylen && 171 pj_memcmp(entry->key, key, keylen)==0) 182 ((lower && pj_ansi_strnicmp((const char*)entry->key, 183 (const char*)key, keylen)==0) || 184 (!lower && pj_memcmp(entry->key, key, keylen)==0))) 172 185 { 173 break; 186 break; 174 187 } 175 188 } … … 215 228 { 216 229 pj_hash_entry *entry; 217 entry = *find_entry( NULL, ht, key, keylen, NULL, hval, NULL );230 entry = *find_entry( NULL, ht, key, keylen, NULL, hval, NULL, PJ_FALSE); 218 231 return entry ? entry->value : NULL; 219 232 } 220 233 221 PJ_DEF(void) pj_hash_set( pj_pool_t *pool, pj_hash_table_t *ht, 222 const void *key, unsigned keylen, pj_uint32_t hval, 223 void *value ) 234 PJ_DEF(void *) pj_hash_get_lower( pj_hash_table_t *ht, 235 const void *key, unsigned keylen, 236 pj_uint32_t *hval) 237 { 238 pj_hash_entry *entry; 239 entry = *find_entry( NULL, ht, key, keylen, NULL, hval, NULL, PJ_TRUE); 240 return entry ? entry->value : NULL; 241 } 242 243 static void hash_set( pj_pool_t *pool, pj_hash_table_t *ht, 244 const void *key, unsigned keylen, pj_uint32_t hval, 245 void *value, void *entry_buf, pj_bool_t lower ) 224 246 { 225 247 pj_hash_entry **p_entry; 226 248 227 p_entry = find_entry( pool, ht, key, keylen, value, &hval, NULL); 249 p_entry = find_entry( pool, ht, key, keylen, value, &hval, entry_buf, 250 lower); 228 251 if (*p_entry) { 229 252 if (value == NULL) { … … 242 265 } 243 266 267 PJ_DEF(void) pj_hash_set( pj_pool_t *pool, pj_hash_table_t *ht, 268 const void *key, unsigned keylen, pj_uint32_t hval, 269 void *value ) 270 { 271 hash_set(pool, ht, key, keylen, hval, value, NULL, PJ_FALSE); 272 } 273 274 PJ_DEF(void) pj_hash_set_lower( pj_pool_t *pool, pj_hash_table_t *ht, 275 const void *key, unsigned keylen, 276 pj_uint32_t hval, void *value ) 277 { 278 hash_set(pool, ht, key, keylen, hval, value, NULL, PJ_TRUE); 279 } 280 244 281 PJ_DEF(void) pj_hash_set_np( pj_hash_table_t *ht, 245 282 const void *key, unsigned keylen, … … 247 284 void *value) 248 285 { 249 pj_hash_entry **p_entry; 250 251 p_entry = find_entry( NULL, ht, key, keylen, value, &hval, 252 (void*)entry_buf ); 253 if (*p_entry) { 254 if (value == NULL) { 255 /* delete entry */ 256 PJ_LOG(6, ("hashtbl", "%p: p_entry %p deleted", ht, *p_entry)); 257 *p_entry = (*p_entry)->next; 258 --ht->count; 259 260 } else { 261 /* overwrite */ 262 (*p_entry)->value = value; 263 PJ_LOG(6, ("hashtbl", "%p: p_entry %p value set to %p", ht, 264 *p_entry, value)); 265 } 266 } 286 hash_set(NULL, ht, key, keylen, hval, value, (void *)entry_buf, PJ_FALSE); 287 } 288 289 PJ_DEF(void) pj_hash_set_np_lower( pj_hash_table_t *ht, 290 const void *key, unsigned keylen, 291 pj_uint32_t hval, 292 pj_hash_entry_buf entry_buf, 293 void *value) 294 { 295 hash_set(NULL, ht, key, keylen, hval, value, (void *)entry_buf, PJ_TRUE); 267 296 } 268 297
Note: See TracChangeset
for help on using the changeset viewer.