MCPcopy Create free account
hub / github.com/Kitware/VTK / xmlHashGrow

Function xmlHashGrow

ThirdParty/libxml2/vtklibxml2/hash.c:353–409  ·  view source on GitHub ↗

* xmlHashGrow: * @hash: hash table * @size: new size of the hash table * * Resize the hash table. * * Returns 0 in case of success, -1 if a memory allocation failed. */

Source from the content-addressed store, hash-verified

351 * Returns 0 in case of success, -1 if a memory allocation failed.
352 */
353static int
354xmlHashGrow(xmlHashTablePtr hash, unsigned size) {
355 const xmlHashEntry *oldentry, *oldend, *end;
356 xmlHashEntry *table;
357 unsigned oldsize, i;
358
359 /* Add 0 to avoid spurious -Wtype-limits warning on 64-bit GCC */
360 if ((size_t) size + 0 > SIZE_MAX / sizeof(table[0]))
361 return(-1);
362 table = xmlMalloc(size * sizeof(table[0]));
363 if (table == NULL)
364 return(-1);
365 memset(table, 0, size * sizeof(table[0]));
366
367 oldsize = hash->size;
368 if (oldsize == 0)
369 goto done;
370
371 oldend = &hash->table[oldsize];
372 end = &table[size];
373
374 /*
375 * Robin Hood sorting order is maintained if we
376 *
377 * - compute hash indices with modulo
378 * - resize by an integer factor
379 * - start to copy from the beginning of a probe sequence
380 */
381 oldentry = hash->table;
382 while (oldentry->hashValue != 0) {
383 if (++oldentry >= oldend)
384 oldentry = hash->table;
385 }
386
387 for (i = 0; i < oldsize; i++) {
388 if (oldentry->hashValue != 0) {
389 xmlHashEntry *entry = &table[oldentry->hashValue & (size - 1)];
390
391 while (entry->hashValue != 0) {
392 if (++entry >= end)
393 entry = table;
394 }
395 *entry = *oldentry;
396 }
397
398 if (++oldentry >= oldend)
399 oldentry = hash->table;
400 }
401
402 xmlFree(hash->table);
403
404done:
405 hash->table = table;
406 hash->size = size;
407
408 return(0);
409}
410

Callers 2

xmlHashCreateFunction · 0.85
xmlHashUpdateInternalFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected