Main Page   Alphabetical List   Data Structures   File List   Data Fields   Globals   Examples  

chtbl.h

Go to the documentation of this file.
00001 /*! \file chtbl.h
00002     Header file for chtbl.c
00003  */
00004 
00005 
00006 #ifdef __cplusplus
00007 extern "C" {
00008 #endif
00009 
00010 
00011 #ifndef CHTBL_H
00012 #define CHTBL_H
00013 
00014 #include <stdlib.h>
00015 #include "list.h"
00016 
00017 
00018 /* ---------------------------------------------------------------- */
00019 /* Structure used to walk through a hash                            */
00020 /* ---------------------------------------------------------------- */
00021 
00022 /*! \brief This value is used by the function chtbl_next(). It tells the function to set the hash pointer to the
00023            first element of the hash.
00024  */
00025 
00026 #define REWIND_HASH    0
00027 
00028 /*! \brief This value is used by the function chtbl_next(). It tells the function to set the hash pointer to the
00029            current element of the hash.
00030  */
00031 
00032 #define CURRENT_HASH   1
00033 
00034 /*! \brief Data structure that defines one element within a hash table. This structure is used by the function
00035            chtbl_next().
00036  */
00037 
00038 typedef struct CHTbl_handle_
00039 {
00040   /*! \brief Index of the current linked list. */
00041   int        current_list;
00042 
00043   /*! \brief Pointer to the current element within the current linked list. */
00044   ListElmt   *current_element;
00045 
00046 } CHTbl_handle;
00047 
00048 /* ---------------------------------------------------------------- */
00049 /* Data structures for the hash tables                              */
00050 /* ---------------------------------------------------------------- */
00051 
00052 /*! \brief Data structure that defines a linked hash table.
00053  */
00054 
00055 typedef struct CHTbl_
00056 {
00057   /*! \brief Number of linked list hold by the hash table. */
00058   int  conteneurs;
00059 
00060   /*! \brief Pointer to the function used to hash the input key. */
00061   int  (*h)(const void *cle);
00062 
00063   /*! \brief Pointer to the function used to compare the data pointed by two elements of the hash table. */
00064   int  (*corresp)(const void *cle1, const void *cle2);
00065 
00066   /*! \brief Pointer to the function used to free the memory allocated for the data pointed by one element of the hash table. */
00067   void (*detruire)(void *donnee);
00068 
00069   /*! \brief Number of element in the hash table. */
00070   int  taille;
00071 
00072   /*! \brief Pointer to a linked list. */
00073   List *table;
00074 
00075   /*! \brief This parameter represents the position of one element within the linked list. It is used bu the
00076              function chtbl_next(). */
00077   CHTbl_handle pointer;
00078 
00079 } CHTbl;
00080 
00081 /* ---------------------------------------------------------------- */
00082 /* Hash table's API                                                 */
00083 /* ---------------------------------------------------------------- */
00084 
00085 
00086 int chtbl_init(CHTbl *htab, int conteneurs, 
00087               int (*h)(const void *cle), 
00088               int (*corresp)(const void *cle1, const void *cle2), 
00089               void (*detruire)(void *donnee));
00090 
00091 void chtbl_destroy(CHTbl *htab);
00092 
00093 int chtbl_insert(CHTbl *htab, const void *donnee);
00094 
00095 int chtbl_remove(CHTbl *htab, void **donnee);
00096 
00097 int chtbl_lookup(const CHTbl *htab, void **donnee);
00098 
00099 int chtbl_find (const CHTbl *htab, void **donnee);
00100 
00101 void* chtbl_next (CHTbl *htab, int rewind);
00102 
00103 #define chtbl_size(htab) ((htab)->taille)
00104 
00105 #endif
00106 
00107 #ifdef __cplusplus
00108 }
00109 #endif
00110 

Generated on Thu Apr 3 16:23:42 2003 for Common_C_libraries by doxygen1.3-rc1