2 * Copyright (c) 2000, Red Hat, Inc.
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * A copy of the GNU General Public License can be found at
12 * Written by DJ Delorie <dj@cygnus.com>
16 /* Simple hash class for install.cc */
24 class hash_internals {
34 h = new hash_internals;
37 h->keys = (char **) malloc (h->maxkeys * sizeof (char *));
49 hash::add (char *string)
52 for (i=0; i<h->numkeys; i++)
53 if (strcmp (h->keys[i], string) == 0)
55 if (h->numkeys >= h->maxkeys)
58 h->keys = (char **) realloc (h->keys, h->maxkeys * sizeof (char *));
61 h->keys[h->numkeys] = _strdup (string);
67 hash::has (char *string)
70 for (i=0; i<h->numkeys; i++)
71 if (strcmp (h->keys[i], string) == 0)
77 hash::enumerate (char *prev)
82 if (h->prev_index >= h->numkeys)
84 return h->keys[h->prev_index];
88 rev_len (const void *va, const void *vb)
90 char *a = *(char **)va;
91 char *b = *(char **)vb;
98 qsort (h->keys, h->numkeys, sizeof (h->keys[0]), rev_len);