• Main Page
  • Related Pages
  • Namespaces
  • Data Structures
  • Files
  • File List
  • Globals

ink_hash_table.h

Go to the documentation of this file.
00001 /** @file
00002 
00003   A brief file description
00004 
00005   @section license License
00006 
00007   Licensed to the Apache Software Foundation (ASF) under one
00008   or more contributor license agreements.  See the NOTICE file
00009   distributed with this work for additional information
00010   regarding copyright ownership.  The ASF licenses this file
00011   to you under the Apache License, Version 2.0 (the
00012   "License"); you may not use this file except in compliance
00013   with the License.  You may obtain a copy of the License at
00014 
00015       http://www.apache.org/licenses/LICENSE-2.0
00016 
00017   Unless required by applicable law or agreed to in writing, software
00018   distributed under the License is distributed on an "AS IS" BASIS,
00019   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00020   See the License for the specific language governing permissions and
00021   limitations under the License.
00022  */
00023 
00024 /****************************************************************************
00025 
00026   ink_hash_table.h
00027 
00028   This file implements hash tables.  This allows us to provide alternative
00029   implementations of hash tables.
00030 
00031  ****************************************************************************/
00032 
00033 #ifndef _ink_hash_table_h_
00034 #define _ink_hash_table_h_
00035 
00036 #ifdef __cplusplus
00037 extern "C"
00038 {
00039 #endif                          /* __cplusplus */
00040 #include "ink_apidefs.h"
00041 
00042 /*===========================================================================*
00043 
00044   This is the Tcl implementation of InkHashTable
00045 
00046  *===========================================================================*/
00047 
00048 #include <tcl.h>
00049 
00050   typedef Tcl_HashTable InkHashTable;
00051   typedef Tcl_HashEntry InkHashTableEntry;
00052   typedef char *InkHashTableKey;
00053   typedef ClientData InkHashTableValue;
00054   typedef Tcl_HashSearch InkHashTableIteratorState;
00055 
00056   typedef int (*InkHashTableEntryFunction) (InkHashTable * ht, InkHashTableEntry * entry);
00057 
00058   /* Types of InkHashTable Keys */
00059 
00060   typedef enum
00061   { InkHashTableKeyType_String, InkHashTableKeyType_Word }
00062   InkHashTableKeyType;
00063 
00064 /*===========================================================================*
00065 
00066                             Function Prototypes
00067 
00068  *===========================================================================*/
00069 
00070   InkHashTable *ink_hash_table_create(InkHashTableKeyType key_type);
00071   InkHashTable *ink_hash_table_destroy(InkHashTable * ht_ptr);
00072   InkHashTable *ink_hash_table_destroy_and_free_values(InkHashTable * ht_ptr);
00073   InkHashTable *ink_hash_table_destroy_and_xfree_values(InkHashTable * ht_ptr);
00074   inkcoreapi int ink_hash_table_isbound(InkHashTable * ht_ptr, const char *key);
00075   inkcoreapi int ink_hash_table_lookup(InkHashTable * ht_ptr, const char *key, InkHashTableValue * value_ptr);
00076   inkcoreapi int ink_hash_table_delete(InkHashTable * ht_ptr, const char *key);
00077   InkHashTableEntry *ink_hash_table_lookup_entry(InkHashTable * ht_ptr, const char *key);
00078   InkHashTableEntry *ink_hash_table_get_entry(InkHashTable * ht_ptr, const char *key, int *new_value);
00079   void ink_hash_table_set_entry(InkHashTable * ht_ptr, InkHashTableEntry * he_ptr, InkHashTableValue value);
00080   inkcoreapi void ink_hash_table_insert(InkHashTable * ht_ptr, const char *key, InkHashTableValue value);
00081   void ink_hash_table_map(InkHashTable * ht_ptr, InkHashTableEntryFunction map);
00082   InkHashTableKey ink_hash_table_entry_key(InkHashTable * ht_ptr, InkHashTableEntry * entry_ptr);
00083   inkcoreapi InkHashTableValue ink_hash_table_entry_value(InkHashTable * ht_ptr, InkHashTableEntry * entry_ptr);
00084   void ink_hash_table_dump_strings(InkHashTable * ht_ptr);
00085   void ink_hash_table_replace_string(InkHashTable * ht_ptr, InkHashTableKey key, char *str);
00086 
00087 /* inline functions declarations */
00088 
00089 /*---------------------------------------------------------------------------*
00090 
00091   InkHashTableEntry *ink_hash_table_iterator_first
00092         (InkHashTable *ht_ptr, InkHashTableIteratorState *state_ptr)
00093 
00094   This routine takes a hash table <ht_ptr>, creates some iterator state
00095   stored through <state_ptr>, and returns a pointer to the first hash table
00096   entry.  The iterator state is used by InkHashTableIteratorNext() to proceed
00097   through the rest of the entries.
00098 
00099  *---------------------------------------------------------------------------*/
00100 
00101   static inline InkHashTableEntry *ink_hash_table_iterator_first
00102     (InkHashTable * ht_ptr, InkHashTableIteratorState * state_ptr)
00103   {
00104     Tcl_HashTable *tcl_ht_ptr;
00105     Tcl_HashSearch *tcl_search_state_ptr;
00106     Tcl_HashEntry *tcl_he_ptr;
00107     InkHashTableEntry *he_ptr;
00108 
00109       tcl_ht_ptr = (Tcl_HashTable *) ht_ptr;
00110       tcl_search_state_ptr = (Tcl_HashSearch *) state_ptr;
00111 
00112       tcl_he_ptr = Tcl_FirstHashEntry(tcl_ht_ptr, tcl_search_state_ptr);
00113       he_ptr = (InkHashTableEntry *) tcl_he_ptr;
00114 
00115       return (he_ptr);
00116   }                             /* End ink_hash_table_iterator_first */
00117 
00118 
00119 /*---------------------------------------------------------------------------*
00120 
00121   InkHashTableEntry *ink_hash_table_iterator_next(InkHashTable *ht_ptr,
00122                                                   InkHashTableIteratorState *state_ptr)
00123 
00124   This routine takes a hash table <ht_ptr> and a pointer to iterator state
00125   initialized by a previous call to InkHashTableIteratorFirst(), and returns
00126   a pointer to the next InkHashTableEntry, or NULL if no entries remain.
00127 
00128  *---------------------------------------------------------------------------*/
00129 
00130   static inline InkHashTableEntry *ink_hash_table_iterator_next(InkHashTable * ht_ptr,
00131                                                                 InkHashTableIteratorState * state_ptr)
00132   {
00133     (void) ht_ptr;
00134     Tcl_HashSearch *tcl_search_state_ptr;
00135     Tcl_HashEntry *tcl_he_ptr;
00136     InkHashTableEntry *he_ptr;
00137 
00138     tcl_search_state_ptr = (Tcl_HashSearch *) state_ptr;
00139 
00140     tcl_he_ptr = Tcl_NextHashEntry(tcl_search_state_ptr);
00141     he_ptr = (InkHashTableEntry *) tcl_he_ptr;
00142 
00143     return (he_ptr);
00144   }                             /* End ink_hash_table_iterator_next */
00145 
00146 #ifdef __cplusplus
00147 }
00148 #endif /* __cplusplus */
00149 #endif /* #ifndef _ink_hash_table_h_ */

Generated by  doxygen 1.7.1