File: ghash_rebuild.c

package info (click to toggle)
bglibs 2.04%2Bdfsg-8
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 3,468 kB
  • sloc: ansic: 15,821; perl: 674; sh: 63; makefile: 29
file content (27 lines) | stat: -rw-r--r-- 669 bytes parent folder | download | duplicates (8)
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
26
27
#include <stdlib.h>
#include <string.h>

#include "ghash.h"

/** Rebuild the entry pointer table in a \c ghash table. This function
 * is used internally after either rehashing the table or removing an
 * entry. */
int ghash_rebuild(struct ghash* d)
{
  unsigned i;
  void** newtable;
  void** oldtable;
  void** oldptr;
  if (d->table) {
    if ((newtable = malloc(d->size * sizeof *newtable)) == 0) return 0;
    memset(newtable, 0, d->size * sizeof *newtable);
    oldptr = oldtable = d->table;
    d->table = newtable;
    d->count = 0;
    for (i = 0; i < d->size; ++i, ++oldptr)
      if (*oldptr)
	ghash_insert(d, *oldptr);
    free(oldtable);
  }
  return 1;
}