1998-09-21 03:22:07 +02:00
|
|
|
/* Hash tables for Objective C internal structures
|
2011-01-03 21:52:22 +01:00
|
|
|
Copyright (C) 1993, 1996, 1997, 2004, 2009, 2010
|
|
|
|
Free Software Foundation, Inc.
|
1998-09-21 03:22:07 +02:00
|
|
|
|
hash.c, [...]: Replace "GNU CC" with "GCC".
* hash.c, init.c, libobjc.def, libobjc_entry.c, linking.m,
makefile.dos, misc.c, nil_method.c, objects.c, sarray.c,
selector.c, sendmsg.c, thr-dce.c, thr-decosf1.c, thr-irix.c,
thr-mach.c, thr-objc.c, thr-os2.c, thr-posix.c, thr-pthreads.c,
thr-rtems.c, thr-single.c, thr-solaris.c, thr-vxworks.c,
thr-win32.c, thr.c: Replace "GNU CC" with "GCC".
From-SVN: r67134
2003-05-23 22:25:39 +02:00
|
|
|
This file is part of GCC.
|
1998-09-21 03:22:07 +02:00
|
|
|
|
hash.c, [...]: Replace "GNU CC" with "GCC".
* hash.c, init.c, libobjc.def, libobjc_entry.c, linking.m,
makefile.dos, misc.c, nil_method.c, objects.c, sarray.c,
selector.c, sendmsg.c, thr-dce.c, thr-decosf1.c, thr-irix.c,
thr-mach.c, thr-objc.c, thr-os2.c, thr-posix.c, thr-pthreads.c,
thr-rtems.c, thr-single.c, thr-solaris.c, thr-vxworks.c,
thr-win32.c, thr.c: Replace "GNU CC" with "GCC".
From-SVN: r67134
2003-05-23 22:25:39 +02:00
|
|
|
GCC is free software; you can redistribute it and/or modify
|
1998-09-21 03:22:07 +02:00
|
|
|
it under the terms of the GNU General Public License as published by
|
2009-04-09 17:00:19 +02:00
|
|
|
the Free Software Foundation; either version 3, or (at your option)
|
1998-09-21 03:22:07 +02:00
|
|
|
any later version.
|
|
|
|
|
hash.c, [...]: Replace "GNU CC" with "GCC".
* hash.c, init.c, libobjc.def, libobjc_entry.c, linking.m,
makefile.dos, misc.c, nil_method.c, objects.c, sarray.c,
selector.c, sendmsg.c, thr-dce.c, thr-decosf1.c, thr-irix.c,
thr-mach.c, thr-objc.c, thr-os2.c, thr-posix.c, thr-pthreads.c,
thr-rtems.c, thr-single.c, thr-solaris.c, thr-vxworks.c,
thr-win32.c, thr.c: Replace "GNU CC" with "GCC".
From-SVN: r67134
2003-05-23 22:25:39 +02:00
|
|
|
GCC is distributed in the hope that it will be useful,
|
1998-09-21 03:22:07 +02:00
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
2009-04-09 17:00:19 +02:00
|
|
|
Under Section 7 of GPL version 3, you are granted additional
|
|
|
|
permissions described in the GCC Runtime Library Exception, version
|
|
|
|
3.1, as published by the Free Software Foundation.
|
1998-09-21 03:22:07 +02:00
|
|
|
|
2009-04-09 17:00:19 +02:00
|
|
|
You should have received a copy of the GNU General Public License and
|
|
|
|
a copy of the GCC Runtime Library Exception along with this program;
|
|
|
|
see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
|
|
|
|
<http://www.gnu.org/licenses/>. */
|
1998-09-21 03:22:07 +02:00
|
|
|
|
2010-09-12 00:47:14 +02:00
|
|
|
#include "objc-private/common.h"
|
2010-12-21 12:24:27 +01:00
|
|
|
#include <assert.h> /* For assert. */
|
1998-09-21 03:22:07 +02:00
|
|
|
|
2010-12-21 12:24:27 +01:00
|
|
|
#include "objc/runtime.h" /* For objc_calloc. */
|
2010-09-18 11:34:58 +02:00
|
|
|
#include "objc-private/hash.h"
|
1998-09-21 03:22:07 +02:00
|
|
|
|
|
|
|
/* These two macros determine when a hash table is full and
|
|
|
|
by how much it should be expanded respectively.
|
|
|
|
|
|
|
|
These equations are percentages. */
|
|
|
|
#define FULLNESS(cache) \
|
|
|
|
((((cache)->size * 75) / 100) <= (cache)->used)
|
|
|
|
#define EXPANSION(cache) \
|
|
|
|
((cache)->size * 2)
|
|
|
|
|
|
|
|
cache_ptr
|
re PR libobjc/19024 (name collisions libobjc/libmysqlclient)
2005-03-02 David Ayers <d.ayers@inode.at>
PR libobjc/19024
* Makefile.in (OBJS): Add hash_compat.lo.
(OBJS_GC): Add hash_compat_gc.lo.
(hash_compat_gc.lo): New target and rule.
* objc/hash.h (hash_new, hash_delete, hash_add, hash_remove)
(hash_next, hash_value_for_key, hash_is_key_in_hash)
(hash_ptr, hash_string, compare_ptrs, compare_strings): Prefix
with objc_. Add deprecated non prefixed inlined versions.
(OBJC_IGNORE_DEPRECATED_API): New macro to hide deprecated
declarations.
* hash.c (hash_new, hash_delete, hash_add, hash_remove, hash_next)
(hash_value_for_key, hash_is_key_in_hash): Prefix with objc_ and
update callers.
* hash_compat.c: New file.
* archive.c: Update callers.
* init.c: Likewise.
* selector.c: Likewise.
* libobjc.def: Add objc_ versions of hash functions.
From-SVN: r95793
2005-03-02 20:37:03 +01:00
|
|
|
objc_hash_new (unsigned int size, hash_func_type hash_func,
|
|
|
|
compare_func_type compare_func)
|
1998-09-21 03:22:07 +02:00
|
|
|
{
|
|
|
|
cache_ptr cache;
|
|
|
|
|
|
|
|
/* Pass me a value greater than 0 and a power of 2. */
|
|
|
|
assert (size);
|
2002-07-02 21:43:03 +02:00
|
|
|
assert (! (size & (size - 1)));
|
1998-09-21 03:22:07 +02:00
|
|
|
|
2010-12-21 12:24:27 +01:00
|
|
|
/* Allocate the cache structure. calloc insures its initialization
|
|
|
|
for default values. */
|
1998-09-21 03:22:07 +02:00
|
|
|
cache = (cache_ptr) objc_calloc (1, sizeof (struct cache));
|
|
|
|
assert (cache);
|
|
|
|
|
2010-12-21 12:24:27 +01:00
|
|
|
/* Allocate the array of buckets for the cache. calloc initializes
|
|
|
|
all of the pointers to NULL. */
|
1998-09-21 03:22:07 +02:00
|
|
|
cache->node_table
|
|
|
|
= (node_ptr *) objc_calloc (size, sizeof (node_ptr));
|
|
|
|
assert (cache->node_table);
|
|
|
|
|
|
|
|
cache->size = size;
|
|
|
|
|
2010-12-21 12:24:27 +01:00
|
|
|
/* This should work for all processor architectures (?). */
|
1998-09-21 03:22:07 +02:00
|
|
|
cache->mask = (size - 1);
|
|
|
|
|
|
|
|
/* Store the hashing function so that codes can be computed. */
|
|
|
|
cache->hash_func = hash_func;
|
|
|
|
|
2010-12-21 12:24:27 +01:00
|
|
|
/* Store the function that compares hash keys to determine if they
|
|
|
|
are equal. */
|
1998-09-21 03:22:07 +02:00
|
|
|
cache->compare_func = compare_func;
|
|
|
|
|
|
|
|
return cache;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
re PR libobjc/19024 (name collisions libobjc/libmysqlclient)
2005-03-02 David Ayers <d.ayers@inode.at>
PR libobjc/19024
* Makefile.in (OBJS): Add hash_compat.lo.
(OBJS_GC): Add hash_compat_gc.lo.
(hash_compat_gc.lo): New target and rule.
* objc/hash.h (hash_new, hash_delete, hash_add, hash_remove)
(hash_next, hash_value_for_key, hash_is_key_in_hash)
(hash_ptr, hash_string, compare_ptrs, compare_strings): Prefix
with objc_. Add deprecated non prefixed inlined versions.
(OBJC_IGNORE_DEPRECATED_API): New macro to hide deprecated
declarations.
* hash.c (hash_new, hash_delete, hash_add, hash_remove, hash_next)
(hash_value_for_key, hash_is_key_in_hash): Prefix with objc_ and
update callers.
* hash_compat.c: New file.
* archive.c: Update callers.
* init.c: Likewise.
* selector.c: Likewise.
* libobjc.def: Add objc_ versions of hash functions.
From-SVN: r95793
2005-03-02 20:37:03 +01:00
|
|
|
objc_hash_delete (cache_ptr cache)
|
1998-09-21 03:22:07 +02:00
|
|
|
{
|
|
|
|
node_ptr node;
|
|
|
|
node_ptr next_node;
|
|
|
|
unsigned int i;
|
|
|
|
|
|
|
|
/* Purge all key/value pairs from the table. */
|
|
|
|
/* Step through the nodes one by one and remove every node WITHOUT
|
2010-12-21 12:24:27 +01:00
|
|
|
using objc_hash_next. this makes objc_hash_delete much more
|
|
|
|
efficient. */
|
|
|
|
for (i = 0; i < cache->size; i++)
|
|
|
|
{
|
|
|
|
if ((node = cache->node_table[i]))
|
|
|
|
{
|
|
|
|
/* An entry in the hash table has been found. Now step
|
|
|
|
through the nodes next in the list and free them. */
|
|
|
|
while ((next_node = node->next))
|
|
|
|
{
|
|
|
|
objc_hash_remove (cache,node->key);
|
|
|
|
node = next_node;
|
|
|
|
}
|
|
|
|
objc_hash_remove (cache,node->key);
|
|
|
|
}
|
1998-09-21 03:22:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Release the array of nodes and the cache itself. */
|
|
|
|
objc_free(cache->node_table);
|
|
|
|
objc_free(cache);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
re PR libobjc/19024 (name collisions libobjc/libmysqlclient)
2005-03-02 David Ayers <d.ayers@inode.at>
PR libobjc/19024
* Makefile.in (OBJS): Add hash_compat.lo.
(OBJS_GC): Add hash_compat_gc.lo.
(hash_compat_gc.lo): New target and rule.
* objc/hash.h (hash_new, hash_delete, hash_add, hash_remove)
(hash_next, hash_value_for_key, hash_is_key_in_hash)
(hash_ptr, hash_string, compare_ptrs, compare_strings): Prefix
with objc_. Add deprecated non prefixed inlined versions.
(OBJC_IGNORE_DEPRECATED_API): New macro to hide deprecated
declarations.
* hash.c (hash_new, hash_delete, hash_add, hash_remove, hash_next)
(hash_value_for_key, hash_is_key_in_hash): Prefix with objc_ and
update callers.
* hash_compat.c: New file.
* archive.c: Update callers.
* init.c: Likewise.
* selector.c: Likewise.
* libobjc.def: Add objc_ versions of hash functions.
From-SVN: r95793
2005-03-02 20:37:03 +01:00
|
|
|
objc_hash_add (cache_ptr *cachep, const void *key, void *value)
|
1998-09-21 03:22:07 +02:00
|
|
|
{
|
2010-12-21 12:24:27 +01:00
|
|
|
size_t indx = (*(*cachep)->hash_func) (*cachep, key);
|
1998-09-21 03:22:07 +02:00
|
|
|
node_ptr node = (node_ptr) objc_calloc (1, sizeof (struct cache_node));
|
|
|
|
|
|
|
|
assert (node);
|
|
|
|
|
|
|
|
/* Initialize the new node. */
|
|
|
|
node->key = key;
|
|
|
|
node->value = value;
|
|
|
|
node->next = (*cachep)->node_table[indx];
|
|
|
|
|
2010-12-21 12:24:27 +01:00
|
|
|
/* Debugging. Check the list for another key. */
|
1998-09-21 03:22:07 +02:00
|
|
|
#ifdef DEBUG
|
2010-12-21 12:24:27 +01:00
|
|
|
{
|
|
|
|
node_ptr node1 = (*cachep)->node_table[indx];
|
|
|
|
while (node1)
|
|
|
|
{
|
|
|
|
assert (node1->key != key);
|
|
|
|
node1 = node1->next;
|
|
|
|
}
|
1998-09-21 03:22:07 +02:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Install the node as the first element on the list. */
|
|
|
|
(*cachep)->node_table[indx] = node;
|
|
|
|
|
|
|
|
/* Bump the number of entries in the cache. */
|
|
|
|
++(*cachep)->used;
|
2010-12-21 12:24:27 +01:00
|
|
|
|
|
|
|
/* Check the hash table's fullness. We're going to expand if it is
|
|
|
|
above the fullness level. */
|
|
|
|
if (FULLNESS (*cachep))
|
|
|
|
{
|
|
|
|
/* The hash table has reached its fullness level. Time to
|
|
|
|
expand it.
|
|
|
|
|
|
|
|
I'm using a slow method here but is built on other primitive
|
|
|
|
functions thereby increasing its correctness. */
|
|
|
|
node_ptr node1 = NULL;
|
|
|
|
cache_ptr new = objc_hash_new (EXPANSION (*cachep),
|
|
|
|
(*cachep)->hash_func,
|
|
|
|
(*cachep)->compare_func);
|
|
|
|
|
|
|
|
DEBUG_PRINTF ("Expanding cache %#x from %d to %d\n",
|
|
|
|
(int) *cachep, (*cachep)->size, new->size);
|
|
|
|
|
|
|
|
/* Copy the nodes from the first hash table to the new one. */
|
|
|
|
while ((node1 = objc_hash_next (*cachep, node1)))
|
|
|
|
objc_hash_add (&new, node1->key, node1->value);
|
|
|
|
|
|
|
|
/* Trash the old cache. */
|
|
|
|
objc_hash_delete (*cachep);
|
|
|
|
|
|
|
|
/* Return a pointer to the new hash table. */
|
|
|
|
*cachep = new;
|
|
|
|
}
|
1998-09-21 03:22:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
re PR libobjc/19024 (name collisions libobjc/libmysqlclient)
2005-03-02 David Ayers <d.ayers@inode.at>
PR libobjc/19024
* Makefile.in (OBJS): Add hash_compat.lo.
(OBJS_GC): Add hash_compat_gc.lo.
(hash_compat_gc.lo): New target and rule.
* objc/hash.h (hash_new, hash_delete, hash_add, hash_remove)
(hash_next, hash_value_for_key, hash_is_key_in_hash)
(hash_ptr, hash_string, compare_ptrs, compare_strings): Prefix
with objc_. Add deprecated non prefixed inlined versions.
(OBJC_IGNORE_DEPRECATED_API): New macro to hide deprecated
declarations.
* hash.c (hash_new, hash_delete, hash_add, hash_remove, hash_next)
(hash_value_for_key, hash_is_key_in_hash): Prefix with objc_ and
update callers.
* hash_compat.c: New file.
* archive.c: Update callers.
* init.c: Likewise.
* selector.c: Likewise.
* libobjc.def: Add objc_ versions of hash functions.
From-SVN: r95793
2005-03-02 20:37:03 +01:00
|
|
|
objc_hash_remove (cache_ptr cache, const void *key)
|
1998-09-21 03:22:07 +02:00
|
|
|
{
|
2010-12-21 12:24:27 +01:00
|
|
|
size_t indx = (*cache->hash_func) (cache, key);
|
1998-09-21 03:22:07 +02:00
|
|
|
node_ptr node = cache->node_table[indx];
|
|
|
|
|
2010-12-21 12:24:27 +01:00
|
|
|
/* We assume there is an entry in the table. Error if it is
|
|
|
|
not. */
|
1998-09-21 03:22:07 +02:00
|
|
|
assert (node);
|
|
|
|
|
2010-12-21 12:24:27 +01:00
|
|
|
/* Special case. First element is the key/value pair to be
|
|
|
|
removed. */
|
|
|
|
if ((*cache->compare_func) (node->key, key))
|
|
|
|
{
|
|
|
|
cache->node_table[indx] = node->next;
|
|
|
|
objc_free(node);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Otherwise, find the hash entry. */
|
|
|
|
node_ptr prev = node;
|
|
|
|
BOOL removed = NO;
|
|
|
|
do
|
|
|
|
{
|
|
|
|
if ((*cache->compare_func) (node->key, key))
|
|
|
|
{
|
|
|
|
prev->next = node->next, removed = YES;
|
|
|
|
objc_free(node);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
prev = node, node = node->next;
|
|
|
|
}
|
|
|
|
while (!removed && node);
|
|
|
|
assert (removed);
|
|
|
|
}
|
|
|
|
|
1998-09-21 03:22:07 +02:00
|
|
|
/* Decrement the number of entries in the hash table. */
|
|
|
|
--cache->used;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
node_ptr
|
re PR libobjc/19024 (name collisions libobjc/libmysqlclient)
2005-03-02 David Ayers <d.ayers@inode.at>
PR libobjc/19024
* Makefile.in (OBJS): Add hash_compat.lo.
(OBJS_GC): Add hash_compat_gc.lo.
(hash_compat_gc.lo): New target and rule.
* objc/hash.h (hash_new, hash_delete, hash_add, hash_remove)
(hash_next, hash_value_for_key, hash_is_key_in_hash)
(hash_ptr, hash_string, compare_ptrs, compare_strings): Prefix
with objc_. Add deprecated non prefixed inlined versions.
(OBJC_IGNORE_DEPRECATED_API): New macro to hide deprecated
declarations.
* hash.c (hash_new, hash_delete, hash_add, hash_remove, hash_next)
(hash_value_for_key, hash_is_key_in_hash): Prefix with objc_ and
update callers.
* hash_compat.c: New file.
* archive.c: Update callers.
* init.c: Likewise.
* selector.c: Likewise.
* libobjc.def: Add objc_ versions of hash functions.
From-SVN: r95793
2005-03-02 20:37:03 +01:00
|
|
|
objc_hash_next (cache_ptr cache, node_ptr node)
|
1998-09-21 03:22:07 +02:00
|
|
|
{
|
2010-12-21 12:24:27 +01:00
|
|
|
/* If the scan is being started then reset the last node visitied
|
|
|
|
pointer and bucket index. */
|
|
|
|
if (!node)
|
1998-09-21 03:22:07 +02:00
|
|
|
cache->last_bucket = 0;
|
2010-12-21 12:24:27 +01:00
|
|
|
|
|
|
|
/* If there is a node visited last then check for another entry in
|
|
|
|
the same bucket. Otherwise step to the next bucket. */
|
|
|
|
if (node)
|
|
|
|
{
|
|
|
|
if (node->next)
|
|
|
|
{
|
|
|
|
/* There is a node which follows the last node returned.
|
|
|
|
Step to that node and retun it. */
|
|
|
|
return node->next;
|
|
|
|
}
|
1998-09-21 03:22:07 +02:00
|
|
|
else
|
2010-12-21 12:24:27 +01:00
|
|
|
++cache->last_bucket;
|
|
|
|
}
|
1998-09-21 03:22:07 +02:00
|
|
|
|
2010-12-21 12:24:27 +01:00
|
|
|
/* If the list isn't exhausted then search the buckets for other
|
|
|
|
nodes. */
|
|
|
|
if (cache->last_bucket < cache->size)
|
|
|
|
{
|
|
|
|
/* Scan the remainder of the buckets looking for an entry at
|
|
|
|
the head of the list. Return the first item found. */
|
|
|
|
while (cache->last_bucket < cache->size)
|
|
|
|
if (cache->node_table[cache->last_bucket])
|
|
|
|
return cache->node_table[cache->last_bucket];
|
|
|
|
else
|
|
|
|
++cache->last_bucket;
|
|
|
|
|
|
|
|
/* No further nodes were found in the hash table. */
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
else
|
1998-09-21 03:22:07 +02:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-12-21 12:24:27 +01:00
|
|
|
/* Given KEY, return corresponding value for it in CACHE. Return NULL
|
|
|
|
if the KEY is not recorded. */
|
1998-09-21 03:22:07 +02:00
|
|
|
void *
|
re PR libobjc/19024 (name collisions libobjc/libmysqlclient)
2005-03-02 David Ayers <d.ayers@inode.at>
PR libobjc/19024
* Makefile.in (OBJS): Add hash_compat.lo.
(OBJS_GC): Add hash_compat_gc.lo.
(hash_compat_gc.lo): New target and rule.
* objc/hash.h (hash_new, hash_delete, hash_add, hash_remove)
(hash_next, hash_value_for_key, hash_is_key_in_hash)
(hash_ptr, hash_string, compare_ptrs, compare_strings): Prefix
with objc_. Add deprecated non prefixed inlined versions.
(OBJC_IGNORE_DEPRECATED_API): New macro to hide deprecated
declarations.
* hash.c (hash_new, hash_delete, hash_add, hash_remove, hash_next)
(hash_value_for_key, hash_is_key_in_hash): Prefix with objc_ and
update callers.
* hash_compat.c: New file.
* archive.c: Update callers.
* init.c: Likewise.
* selector.c: Likewise.
* libobjc.def: Add objc_ versions of hash functions.
From-SVN: r95793
2005-03-02 20:37:03 +01:00
|
|
|
objc_hash_value_for_key (cache_ptr cache, const void *key)
|
1998-09-21 03:22:07 +02:00
|
|
|
{
|
2010-12-21 12:24:27 +01:00
|
|
|
node_ptr node = cache->node_table[(*cache->hash_func) (cache, key)];
|
1998-09-21 03:22:07 +02:00
|
|
|
void *retval = NULL;
|
|
|
|
|
|
|
|
if (node)
|
2010-12-21 12:24:27 +01:00
|
|
|
do
|
|
|
|
{
|
|
|
|
if ((*cache->compare_func) (node->key, key))
|
|
|
|
{
|
|
|
|
retval = node->value;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
node = node->next;
|
|
|
|
}
|
|
|
|
while (! retval && node);
|
|
|
|
|
1998-09-21 03:22:07 +02:00
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
2010-12-21 12:24:27 +01:00
|
|
|
/* Given KEY, return YES if it exists in the CACHE. Return NO if it
|
|
|
|
does not */
|
1998-09-21 03:22:07 +02:00
|
|
|
BOOL
|
re PR libobjc/19024 (name collisions libobjc/libmysqlclient)
2005-03-02 David Ayers <d.ayers@inode.at>
PR libobjc/19024
* Makefile.in (OBJS): Add hash_compat.lo.
(OBJS_GC): Add hash_compat_gc.lo.
(hash_compat_gc.lo): New target and rule.
* objc/hash.h (hash_new, hash_delete, hash_add, hash_remove)
(hash_next, hash_value_for_key, hash_is_key_in_hash)
(hash_ptr, hash_string, compare_ptrs, compare_strings): Prefix
with objc_. Add deprecated non prefixed inlined versions.
(OBJC_IGNORE_DEPRECATED_API): New macro to hide deprecated
declarations.
* hash.c (hash_new, hash_delete, hash_add, hash_remove, hash_next)
(hash_value_for_key, hash_is_key_in_hash): Prefix with objc_ and
update callers.
* hash_compat.c: New file.
* archive.c: Update callers.
* init.c: Likewise.
* selector.c: Likewise.
* libobjc.def: Add objc_ versions of hash functions.
From-SVN: r95793
2005-03-02 20:37:03 +01:00
|
|
|
objc_hash_is_key_in_hash (cache_ptr cache, const void *key)
|
1998-09-21 03:22:07 +02:00
|
|
|
{
|
2010-12-21 12:24:27 +01:00
|
|
|
node_ptr node = cache->node_table[(*cache->hash_func) (cache, key)];
|
|
|
|
|
1998-09-21 03:22:07 +02:00
|
|
|
if (node)
|
2010-12-21 12:24:27 +01:00
|
|
|
do
|
|
|
|
{
|
|
|
|
if ((*cache->compare_func)(node->key, key))
|
1998-09-21 03:22:07 +02:00
|
|
|
return YES;
|
2010-12-21 12:24:27 +01:00
|
|
|
else
|
|
|
|
node = node->next;
|
|
|
|
}
|
|
|
|
while (node);
|
1998-09-21 03:22:07 +02:00
|
|
|
|
|
|
|
return NO;
|
|
|
|
}
|