/* hash.c -- hash table maintenance
- Copyright (C) 1995 Free Software Foundation, Inc.
+ Copyright 1995, 2001 Free Software Foundation, Inc.
Written by Greg McGary <gkm@gnu.ai.mit.edu>
This program is free software; you can redistribute it and/or modify
ht->ht_size = round_up_2 (size);
if (ht->ht_size > (128 * 1024)) /* prevent size from getting out of hand */
ht->ht_size /= 2;
- ht->ht_vec = (void**) CALLOC (struct token *, ht->ht_size);
+ ht->ht_vec = (void**) XCALLOC (struct token *, ht->ht_size);
if (ht->ht_vec == 0)
error (1, 0, _("can't allocate %ld bytes for hash table: memory exhausted"),
ht->ht_size * sizeof(struct token *));
return ((HASH_VACANT (*slot)) ? 0 : *slot);
}
-void *
+const void *
hash_insert (struct hash_table* ht, void *item)
{
void **slot = hash_find_slot (ht, item);
return hash_insert_at (ht, item, slot);
}
-void *
+const void *
hash_insert_at (struct hash_table* ht, void *item, void const *slot)
{
- void *old_item = *(void **) slot;
+ const void *old_item = *(const void **) slot;
if (HASH_VACANT (old_item))
{
ht->ht_fill++;
return old_item;
}
-void *
+const void *
hash_delete (struct hash_table* ht, void const *item)
{
void **slot = hash_find_slot (ht, item);
return hash_delete_at (ht, slot);
}
-void *
+const void *
hash_delete_at (struct hash_table* ht, void const *slot)
{
- void *item = *(void **) slot;
+ const void *item = *(const void **) slot;
if (!HASH_VACANT (item))
{
*(void const **) slot = hash_deleted_item;
ht->ht_size *= 2;
ht->ht_rehashes++;
ht->ht_capacity = ht->ht_size - (ht->ht_size >> 4);
- ht->ht_vec = (void **) CALLOC (struct token *, ht->ht_size);
+ ht->ht_vec = (void **) XCALLOC (struct token *, ht->ht_size);
for (ovp = old_vec; ovp < &old_vec[old_ht_size]; ovp++)
{
void **end = &ht->ht_vec[ht->ht_size];
if (vector_0 == 0)
- vector_0 = MALLOC (void *, ht->ht_fill + 1);
+ vector_0 = XMALLOC (void *, ht->ht_fill + 1);
vector = vector_0;
for (slot = ht->ht_vec; slot < end; slot++)