File: hmreshuffle.c

package info (click to toggle)
yodl 4.05.02-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 4,724 kB
  • sloc: ansic: 7,803; perl: 683; cpp: 570; sh: 411; xml: 190; makefile: 163
file content (25 lines) | stat: -rw-r--r-- 686 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#include "hashmap.ih"

void hm_reshuffle(register HashMap *symtab)
{
    size_t newsize = symtab->d_size;
    size_t n;

    register HashItem **old = symtab->d_map;
    HashItem **new = new_calloc(newsize, sizeof(HashItem *));

    for (n = 0; n < symtab->d_n; ++old)         /* visit all OLD elements   */
    {
                                                /* Got one                  */
        if (*old != (HashItem *)FREE && *old != (HashItem *)REMOVED)
        {
            size_t idx;
            if (hm_find(&idx, new, newsize, (*old)->d_key) == UFAILED)
                new[idx] = *old;
            ++n;
        }
    }

    free(symtab->d_map);
    symtab->d_map = new;
}