* xmlHashFindEntry: * @hash: hash table, non-NULL, size > 0 * @key: first string key, non-NULL * @key2: second string key * @key3: third string key * @hashValue: valid hash value of keys * @pfound: result of search * * Try to find a matching hash table entry. If an entry was found, set * @found to 1 and return the entry. Otherwise, set @found to 0 and return * the location where a new en
| 288 | * the location where a new entry should be inserted. |
| 289 | */ |
| 290 | ATTRIBUTE_NO_SANITIZE_INTEGER |
| 291 | static xmlHashEntry * |
| 292 | xmlHashFindEntry(const xmlHashTable *hash, const xmlChar *key, |
| 293 | const xmlChar *key2, const xmlChar *key3, |
| 294 | unsigned hashValue, int *pfound) { |
| 295 | xmlHashEntry *entry; |
| 296 | unsigned mask, pos, displ; |
| 297 | int found = 0; |
| 298 | |
| 299 | mask = hash->size - 1; |
| 300 | pos = hashValue & mask; |
| 301 | entry = &hash->table[pos]; |
| 302 | |
| 303 | if (entry->hashValue != 0) { |
| 304 | /* |
| 305 | * Robin hood hashing: abort if the displacement of the entry |
| 306 | * is smaller than the displacement of the key we look for. |
| 307 | * This also stops at the correct position when inserting. |
| 308 | */ |
| 309 | displ = 0; |
| 310 | hashValue |= MAX_HASH_SIZE; |
| 311 | |
| 312 | do { |
| 313 | if (entry->hashValue == hashValue) { |
| 314 | if (hash->dict) { |
| 315 | if ((entry->key == key) && |
| 316 | (entry->key2 == key2) && |
| 317 | (entry->key3 == key3)) { |
| 318 | found = 1; |
| 319 | break; |
| 320 | } |
| 321 | } |
| 322 | if ((strcmp((const char *) entry->key, |
| 323 | (const char *) key) == 0) && |
| 324 | (xmlFastStrEqual(entry->key2, key2)) && |
| 325 | (xmlFastStrEqual(entry->key3, key3))) { |
| 326 | found = 1; |
| 327 | break; |
| 328 | } |
| 329 | } |
| 330 | |
| 331 | displ++; |
| 332 | pos++; |
| 333 | entry++; |
| 334 | if ((pos & mask) == 0) |
| 335 | entry = hash->table; |
| 336 | } while ((entry->hashValue != 0) && |
| 337 | (((pos - entry->hashValue) & mask) >= displ)); |
| 338 | } |
| 339 | |
| 340 | *pfound = found; |
| 341 | return(entry); |
| 342 | } |
| 343 | |
| 344 | /** |
| 345 | * xmlHashGrow: |
no test coverage detected