/* Hash tables for Objective C internal structures
- Copyright (C) 1993, 1996, 1997 Free Software Foundation, Inc.
+ Copyright (C) 1993, 1996, 1997, 2004, 2009 Free Software Foundation, Inc.
This file is part of GCC.
GCC is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
-the Free Software Foundation; either version 2, or (at your option)
+the Free Software Foundation; either version 3, or (at your option)
any later version.
GCC is distributed in the hope that it will be useful,
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
-You should have received a copy of the GNU General Public License
-along with GCC; see the file COPYING. If not, write to
-the Free Software Foundation, 59 Temple Place - Suite 330,
-Boston, MA 02111-1307, USA. */
+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.
-/* As a special exception, if you link this library with files
- compiled with GCC to produce an executable, this does not cause
- the resulting executable to be covered by the GNU General Public License.
- This exception does not however invalidate any other reasons why
- the executable file might be covered by the GNU General Public License. */
+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/>. */
-#include "assert.h"
+#include "objc-private/common.h"
+#include <assert.h> /* For assert */
-#include "hash.h"
-
-#include "runtime.h" /* for DEBUG_PRINTF */
+#include "objc/runtime.h" /* For objc_calloc */
+#include "objc/thr.h" /* Required by objc-private/runtime.h. */
+#include "objc-private/hash.h"
+#include "objc-private/runtime.h" /* for DEBUG_PRINTF */
/* These two macros determine when a hash table is full and
by how much it should be expanded respectively.
((cache)->size * 2)
cache_ptr
-hash_new (unsigned int size, hash_func_type hash_func,
- compare_func_type compare_func)
+objc_hash_new (unsigned int size, hash_func_type hash_func,
+ compare_func_type compare_func)
{
cache_ptr cache;
void
-hash_delete (cache_ptr cache)
+objc_hash_delete (cache_ptr cache)
{
node_ptr node;
node_ptr next_node;
/* Purge all key/value pairs from the table. */
/* Step through the nodes one by one and remove every node WITHOUT
- using hash_next. this makes hash_delete much more efficient. */
+ 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)) {
- hash_remove (cache,node->key);
+ objc_hash_remove (cache,node->key);
node = next_node;
}
- hash_remove (cache,node->key);
+ objc_hash_remove (cache,node->key);
}
}
void
-hash_add (cache_ptr *cachep, const void *key, void *value)
+objc_hash_add (cache_ptr *cachep, const void *key, void *value)
{
size_t indx = (*(*cachep)->hash_func)(*cachep, key);
node_ptr node = (node_ptr) objc_calloc (1, sizeof (struct cache_node));
primitive functions thereby increasing its
correctness. */
node_ptr node1 = NULL;
- cache_ptr new = hash_new (EXPANSION (*cachep),
- (*cachep)->hash_func,
- (*cachep)->compare_func);
+ cache_ptr new = objc_hash_new (EXPANSION (*cachep),
+ (*cachep)->hash_func,
+ (*cachep)->compare_func);
DEBUG_PRINTF ("Expanding cache %#x from %d to %d\n",
- *cachep, (*cachep)->size, new->size);
+ (int) *cachep, (*cachep)->size, new->size);
/* Copy the nodes from the first hash table to the new one. */
- while ((node1 = hash_next (*cachep, node1)))
- hash_add (&new, node1->key, node1->value);
+ while ((node1 = objc_hash_next (*cachep, node1)))
+ objc_hash_add (&new, node1->key, node1->value);
/* Trash the old cache. */
- hash_delete (*cachep);
+ objc_hash_delete (*cachep);
/* Return a pointer to the new hash table. */
*cachep = new;
void
-hash_remove (cache_ptr cache, const void *key)
+objc_hash_remove (cache_ptr cache, const void *key)
{
size_t indx = (*cache->hash_func)(cache, key);
node_ptr node = cache->node_table[indx];
node_ptr
-hash_next (cache_ptr cache, node_ptr node)
+objc_hash_next (cache_ptr cache, node_ptr node)
{
/* If the scan is being started then reset the last node
visitied pointer and bucket index. */
Return NULL if the KEY is not recorded. */
void *
-hash_value_for_key (cache_ptr cache, const void *key)
+objc_hash_value_for_key (cache_ptr cache, const void *key)
{
node_ptr node = cache->node_table[(*cache->hash_func)(cache, key)];
void *retval = NULL;
Return NO if it does not */
BOOL
-hash_is_key_in_hash (cache_ptr cache, const void *key)
+objc_hash_is_key_in_hash (cache_ptr cache, const void *key)
{
node_ptr node = cache->node_table[(*cache->hash_func)(cache, key)];