\hypertarget{group__adt__ghash}{
\section{adt ghash: Generic hash tables.}
\label{group__adt__ghash}\index{adt ghash: Generic hash tables.@{adt ghash: Generic hash tables.}}
}
\subsection*{Data Structures}
\begin{CompactItemize}
\item 
struct \hyperlink{structghash}{ghash}
\item 
struct \hyperlink{structghashiter}{ghashiter}
\end{CompactItemize}
\subsection*{Defines}
\begin{CompactItemize}
\item 
\#define \hyperlink{group__adt__ghash_g06408a9495c3264536eb441f2cfe21f0}{ghash\_\-entry\_\-hash}(P)~($\ast$(\hyperlink{group__adt_gab1a0335d8d46afee323cf2b3d132145}{adt\_\-hash\_\-t}$\ast$)(P))
\item 
\#define \hyperlink{group__adt__ghash_g3f6b74b60133f8479a5351213ad097e9}{ghash\_\-entry\_\-keyptr}(P)~((P)+sizeof(\hyperlink{group__adt_gab1a0335d8d46afee323cf2b3d132145}{adt\_\-hash\_\-t}))
\item 
\#define \hyperlink{group__adt__ghash_gb20f65db478dd9d049cf30b5c0e46798}{ghash\_\-entry\_\-dataptr}(P, L)~((P)+sizeof(\hyperlink{group__adt_gab1a0335d8d46afee323cf2b3d132145}{adt\_\-hash\_\-t})+(L))
\item 
\#define \hyperlink{group__adt__ghash_g1cf13ef03b3c316a344d5a7f5af2ef9f}{ghash\_\-hashb}~adt\_\-hashb
\item 
\#define \hyperlink{group__adt__ghash_ga793802d1ccac89ba8f2450041b19510}{ghash\_\-hashs}~adt\_\-hashs
\item 
\#define \hyperlink{group__adt__ghash_g67d80747f0e39bdaaaa34c1a3efa45b9}{ghash\_\-hashsp}~adt\_\-hashsp
\item 
\#define \hyperlink{group__adt__ghash_gda65697b1f72b4e162981b6e5ac590e8}{GHASH\_\-STRUCT\_\-ENTRY}(PREFIX, KTYPE, DTYPE)
\item 
\#define \hyperlink{group__adt__ghash_g4275ace9d4a3af4cac0ffb37cfb0285a}{GHASH\_\-KEYOFFSET}(PREFIX)~((unsigned long)\&((struct PREFIX\#\#\_\-entry$\ast$)0) $\rightarrow$ key)
\item 
\#define \hyperlink{group__adt__ghash_gd9dcfdb435e30e32b276f8ba0cc04b0a}{GHASH\_\-DATAOFFSET}(PREFIX)~((unsigned long)\&((struct PREFIX\#\#\_\-entry$\ast$)0) $\rightarrow$ data)
\item 
\#define \hyperlink{group__adt__ghash_g3464d7a289b27e168f574b1d8f8a8be3}{GHASH\_\-KEYSIZE}(PREFIX)
\item 
\#define \hyperlink{group__adt__ghash_gc1e305054793738b716c40999cfea9bf}{GHASH\_\-DECL}(PREFIX, KTYPE, DTYPE)
\item 
\#define \hyperlink{group__adt__ghash_g46a99956ed09905f7f8c32c603347bd3}{GHASH\_\-INIT\_\-DEFN}(PREFIX, KTYPE, DTYPE, HASHFN, CMP, KCOPY, DCOPY, KFREE, DFREE)
\item 
\#define \hyperlink{group__adt__ghash_gf8c5a4c9b22f8c620ed8875de9545f3e}{GHASH\_\-FREE\_\-DEFN}(PREFIX)
\item 
\#define \hyperlink{group__adt__ghash_g928454c59f629fbab0bb20e0fec7033c}{GHASH\_\-ADD\_\-DEFN}(PREFIX, KTYPE, DTYPE)
\item 
\#define \hyperlink{group__adt__ghash_g5c819bab0cc126b53ffe8b7c6e38bb27}{GHASH\_\-SET\_\-DEFN}(PREFIX, KTYPE, DTYPE)
\item 
\#define \hyperlink{group__adt__ghash_gabe08d7de7829f19e51789b06b1a95da}{GHASH\_\-GET\_\-DEFN}(PREFIX, KTYPE)
\item 
\#define \hyperlink{group__adt__ghash_g5462bc3c7d1eea455b6733ce60bd39d5}{GHASH\_\-REBUILD\_\-DEFN}(PREFIX)
\item 
\#define \hyperlink{group__adt__ghash_g2293adaa2df56053b058ff937e7c7254}{GHASH\_\-REHASH\_\-DEFN}(PREFIX)
\item 
\#define \hyperlink{group__adt__ghash_g4de5f1ce7dc082245c22f16635a9f5c5}{GHASH\_\-REMOVE\_\-DEFN}(PREFIX, KTYPE)
\item 
\#define \hyperlink{group__adt__ghash_g28d6134ab05a63015feb36a32ebc6b0f}{GHASH\_\-FOREACH\_\-DEFN}(PREFIX)
\item 
\#define \hyperlink{group__adt__ghash_ge84cc453db9361a299216c9211abc968}{GHASH\_\-SEARCH\_\-DEFN}(PREFIX)
\item 
\#define \hyperlink{group__adt__ghash_g7d55343d7fd6bd32f4f1107be14f219a}{GHASH\_\-DEFN}(PREFIX, KTYPE, DTYPE, HASHFN, CMPFN, KCOPY, DCOPY, KFREE, DFREE)
\item 
\#define \hyperlink{group__adt__ghash_g7db779509845eb235a86abc751e44887}{ghashiter\_\-loop}(I, G)~for(ghashiter\_\-first(I,G);ghashiter\_\-valid(I);ghashiter\_\-next(I))
\end{CompactItemize}
\subsection*{Functions}
\begin{CompactItemize}
\item 
void \hyperlink{group__adt__ghash_ge774815d548201157ed715de43e3ea9d}{ghash\_\-insert} (struct \hyperlink{structghash}{ghash} $\ast$d, void $\ast$e)
\item 
void $\ast$ \hyperlink{group__adt__ghash_g6550c0dfe54e19112959dba7b164058a}{ghash\_\-add} (struct \hyperlink{structghash}{ghash} $\ast$d, const void $\ast$key, const void $\ast$data)
\item 
void $\ast$ \hyperlink{group__adt__ghash_g199afecbf45d644c8371b612141df54b}{ghash\_\-set} (struct \hyperlink{structghash}{ghash} $\ast$d, const void $\ast$key, const void $\ast$data)
\item 
void \hyperlink{group__adt__ghash_ge609d6df48e1e10a1391d1c94c1dc9ac}{ghash\_\-free} (struct \hyperlink{structghash}{ghash} $\ast$d)
\item 
void $\ast$$\ast$ \hyperlink{group__adt__ghash_g92c681d50d718324d18ea35118593e0b}{ghash\_\-find} (struct \hyperlink{structghash}{ghash} $\ast$d, const void $\ast$key)
\item 
void $\ast$ \hyperlink{group__adt__ghash_g4b02b70d7c67a779a9dca5aa23b7f0f4}{ghash\_\-get} (struct \hyperlink{structghash}{ghash} $\ast$d, const void $\ast$key)
\item 
void \hyperlink{group__adt__ghash_g5b2766288f28271bbcf0c45f17e82b89}{ghash\_\-init} (struct \hyperlink{structghash}{ghash} $\ast$d, unsigned long keysize, unsigned long entrysize, \hyperlink{group__adt_gd6ce53fbc11dbf67ca1c126cd17ee81a}{adt\_\-hash\_\-fn} $\ast$hashfn, \hyperlink{group__adt_g03ed35b7331128b069dc77ab33798782}{adt\_\-cmp\_\-fn} $\ast$keycmp, \hyperlink{group__adt_ga98f7f3499407a5dc1afdcbb20df2e15}{adt\_\-copy\_\-fn} $\ast$keycopy, \hyperlink{group__adt_ga98f7f3499407a5dc1afdcbb20df2e15}{adt\_\-copy\_\-fn} $\ast$datacopy, \hyperlink{group__adt_g87ba7ca9dce36c22fe75a730a1d768a9}{adt\_\-free\_\-fn} $\ast$keyfree, \hyperlink{group__adt_g87ba7ca9dce36c22fe75a730a1d768a9}{adt\_\-free\_\-fn} $\ast$datafree)
\item 
int \hyperlink{group__adt__ghash_g6a6bba38a9aaf20a6b10eeaabaa9b869}{ghash\_\-rebuild} (struct \hyperlink{structghash}{ghash} $\ast$d)
\item 
int \hyperlink{group__adt__ghash_g4beb7c3192aa1ee02a8bf0142758e1af}{ghash\_\-rehash} (struct \hyperlink{structghash}{ghash} $\ast$d)
\item 
int \hyperlink{group__adt__ghash_gad78f59b6f21c62f96285d1583e017fb}{ghash\_\-remove} (struct \hyperlink{structghash}{ghash} $\ast$d, const void $\ast$key)
\item 
void \hyperlink{group__adt__ghash_g4778a040ba311b5925ca15d7ca640bf9}{ghash\_\-foreach} (struct \hyperlink{structghash}{ghash} $\ast$d, void($\ast$fn)(void $\ast$entry))
\item 
void $\ast$ \hyperlink{group__adt__ghash_g0065ab7531db704c0e51250c519693cc}{ghash\_\-search} (struct \hyperlink{structghash}{ghash} $\ast$d, int($\ast$fn)(const void $\ast$entry))
\item 
void \hyperlink{group__adt__ghash_g3c21bcee8850adc76bee68ee8dd7df3e}{ghashiter\_\-first} (struct \hyperlink{structghashiter}{ghashiter} $\ast$, const struct \hyperlink{structghash}{ghash} $\ast$)
\item 
int \hyperlink{group__adt__ghash_g03c8f3d628d6ea8c54ecffe4e892178f}{ghashiter\_\-valid} (const struct \hyperlink{structghashiter}{ghashiter} $\ast$)
\item 
void \hyperlink{group__adt__ghash_g733a92b13ce772e7e3810ea65fcd6454}{ghashiter\_\-next} (struct \hyperlink{structghashiter}{ghashiter} $\ast$)
\end{CompactItemize}


\subsection{Detailed Description}
The actual hash table manipulation functions use a simple linear probing algorithm with a dynamic table size. Since many more slots are allocated than are in use at any given time, there are always plenty of empty slots available to make searches short. Since each shot is a single pointer, these extra slots don't consume a significant amount of memory.

The structure at the center of the {\tt \hyperlink{structghash}{ghash}} implementation contains pointers to the actual data (including all relevant metadata) plus function pointers to the functions needed to manipulate the data. 

\subsection{Define Documentation}
\hypertarget{group__adt__ghash_g928454c59f629fbab0bb20e0fec7033c}{
\index{adt\_\-ghash@{adt\_\-ghash}!GHASH\_\-ADD\_\-DEFN@{GHASH\_\-ADD\_\-DEFN}}
\index{GHASH\_\-ADD\_\-DEFN@{GHASH\_\-ADD\_\-DEFN}!adt_ghash@{adt\_\-ghash}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}\#define GHASH\_\-ADD\_\-DEFN(PREFIX, KTYPE, DTYPE)}}
\label{group__adt__ghash_g928454c59f629fbab0bb20e0fec7033c}


\textbf{Value:}

\begin{Code}\begin{verbatim}struct PREFIX##_entry* PREFIX##_add(struct ghash* d, \
                                    KTYPE const* key, DTYPE const* data) { \
  return ghash_add(d, key, data); \
}
\end{verbatim}
\end{Code}
Define a specialized {\tt \hyperlink{structghash}{ghash}} table add function. \hypertarget{group__adt__ghash_gd9dcfdb435e30e32b276f8ba0cc04b0a}{
\index{adt\_\-ghash@{adt\_\-ghash}!GHASH\_\-DATAOFFSET@{GHASH\_\-DATAOFFSET}}
\index{GHASH\_\-DATAOFFSET@{GHASH\_\-DATAOFFSET}!adt_ghash@{adt\_\-ghash}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}\#define GHASH\_\-DATAOFFSET(PREFIX)~((unsigned long)\&((struct PREFIX\#\#\_\-entry$\ast$)0) $\rightarrow$ data)}}
\label{group__adt__ghash_gd9dcfdb435e30e32b276f8ba0cc04b0a}


The offset of the data into a specialized {\tt \hyperlink{structghash}{ghash}} entry. \hypertarget{group__adt__ghash_gc1e305054793738b716c40999cfea9bf}{
\index{adt\_\-ghash@{adt\_\-ghash}!GHASH\_\-DECL@{GHASH\_\-DECL}}
\index{GHASH\_\-DECL@{GHASH\_\-DECL}!adt_ghash@{adt\_\-ghash}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}\#define GHASH\_\-DECL(PREFIX, KTYPE, DTYPE)}}
\label{group__adt__ghash_gc1e305054793738b716c40999cfea9bf}


\textbf{Value:}

\begin{Code}\begin{verbatim}GHASH_STRUCT_ENTRY(PREFIX,KTYPE,DTYPE); \
extern void PREFIX##_init(struct ghash* d); \
extern void PREFIX##_free(struct ghash* d); \
extern struct PREFIX##_entry* PREFIX##_add(struct ghash* d, \
                                           KTYPE const* key, \
                                           DTYPE const* data); \
extern struct PREFIX##_entry* PREFIX##_set(struct ghash* d, \
                                           KTYPE const* key, \
                                           DTYPE const* data); \
extern struct PREFIX##_entry* PREFIX##_get(struct ghash* d, \
                                           KTYPE const* key); \
extern int PREFIX##_rebuild(struct ghash* d); \
extern int PREFIX##_rehash(struct ghash* d); \
extern int PREFIX##_remove(struct ghash* d, KTYPE const* key); \
extern void PREFIX##_foreach(struct ghash* d, \
                             void (*fn)(struct PREFIX##_entry*)); \
extern struct PREFIX##_entry* PREFIX##_search(struct ghash* d, \
                                              int (*fn)(const struct PREFIX##_entry*));
\end{verbatim}
\end{Code}
Declare all the prototypes for a {\tt \hyperlink{structghash}{ghash}} table, specialized to particular key and data types. \begin{Desc}
\item[Examples: ]\par
\hyperlink{adt_2ghash__test_8c-example}{adt/ghash\_\-test.c}.\end{Desc}
\hypertarget{group__adt__ghash_g7d55343d7fd6bd32f4f1107be14f219a}{
\index{adt\_\-ghash@{adt\_\-ghash}!GHASH\_\-DEFN@{GHASH\_\-DEFN}}
\index{GHASH\_\-DEFN@{GHASH\_\-DEFN}!adt_ghash@{adt\_\-ghash}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}\#define GHASH\_\-DEFN(PREFIX, KTYPE, DTYPE, HASHFN, CMPFN, KCOPY, DCOPY, KFREE, DFREE)}}
\label{group__adt__ghash_g7d55343d7fd6bd32f4f1107be14f219a}


\textbf{Value:}

\begin{Code}\begin{verbatim}GHASH_INIT_DEFN(PREFIX,KTYPE,DTYPE,HASHFN,CMPFN,KCOPY,DCOPY,KFREE,DFREE) \
GHASH_FREE_DEFN(PREFIX) \
GHASH_ADD_DEFN(PREFIX,KTYPE,DTYPE) \
GHASH_SET_DEFN(PREFIX,KTYPE,DTYPE) \
GHASH_GET_DEFN(PREFIX,KTYPE) \
GHASH_REBUILD_DEFN(PREFIX) \
GHASH_REHASH_DEFN(PREFIX) \
GHASH_REMOVE_DEFN(PREFIX,KTYPE) \
GHASH_FOREACH_DEFN(PREFIX) \
GHASH_SEARCH_DEFN(PREFIX)
\end{verbatim}
\end{Code}
Define all necessary functions for a specialized {\tt \hyperlink{structghash}{ghash}} table. If either of the copy functions {\tt KCOPY} or {\tt DCOPY} are {\tt NULL}, a simple memcpy is used instead. If either of the free functions {\tt KFREE} or {\tt DFREE} are NULL, no data freeing is attempted. \begin{Desc}
\item[Examples: ]\par
\hyperlink{adt_2ghash__test_8c-example}{adt/ghash\_\-test.c}.\end{Desc}
\hypertarget{group__adt__ghash_gb20f65db478dd9d049cf30b5c0e46798}{
\index{adt\_\-ghash@{adt\_\-ghash}!ghash\_\-entry\_\-dataptr@{ghash\_\-entry\_\-dataptr}}
\index{ghash\_\-entry\_\-dataptr@{ghash\_\-entry\_\-dataptr}!adt_ghash@{adt\_\-ghash}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}\#define ghash\_\-entry\_\-dataptr(P, L)~((P)+sizeof({\bf adt\_\-hash\_\-t})+(L))}}
\label{group__adt__ghash_gb20f65db478dd9d049cf30b5c0e46798}


The data structure address within an entry {\tt P} . The offset parameter {\tt L} is the size of the key structure. \hypertarget{group__adt__ghash_g06408a9495c3264536eb441f2cfe21f0}{
\index{adt\_\-ghash@{adt\_\-ghash}!ghash\_\-entry\_\-hash@{ghash\_\-entry\_\-hash}}
\index{ghash\_\-entry\_\-hash@{ghash\_\-entry\_\-hash}!adt_ghash@{adt\_\-ghash}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}\#define ghash\_\-entry\_\-hash(P)~($\ast$({\bf adt\_\-hash\_\-t}$\ast$)(P))}}
\label{group__adt__ghash_g06408a9495c3264536eb441f2cfe21f0}


The hash value stored within an entry {\tt P} . \hypertarget{group__adt__ghash_g3f6b74b60133f8479a5351213ad097e9}{
\index{adt\_\-ghash@{adt\_\-ghash}!ghash\_\-entry\_\-keyptr@{ghash\_\-entry\_\-keyptr}}
\index{ghash\_\-entry\_\-keyptr@{ghash\_\-entry\_\-keyptr}!adt_ghash@{adt\_\-ghash}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}\#define ghash\_\-entry\_\-keyptr(P)~((P)+sizeof({\bf adt\_\-hash\_\-t}))}}
\label{group__adt__ghash_g3f6b74b60133f8479a5351213ad097e9}


The key structure address within an entry {\tt P} . \hypertarget{group__adt__ghash_g28d6134ab05a63015feb36a32ebc6b0f}{
\index{adt\_\-ghash@{adt\_\-ghash}!GHASH\_\-FOREACH\_\-DEFN@{GHASH\_\-FOREACH\_\-DEFN}}
\index{GHASH\_\-FOREACH\_\-DEFN@{GHASH\_\-FOREACH\_\-DEFN}!adt_ghash@{adt\_\-ghash}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}\#define GHASH\_\-FOREACH\_\-DEFN(PREFIX)}}
\label{group__adt__ghash_g28d6134ab05a63015feb36a32ebc6b0f}


\textbf{Value:}

\begin{Code}\begin{verbatim}void PREFIX##_foreach(struct ghash* d, void (*fn)(struct PREFIX##_entry*)) { \
  ghash_foreach(d, (void (*)(void*))fn); \
}
\end{verbatim}
\end{Code}
Define a specialized {\tt \hyperlink{structghash}{ghash}} table iterator function. \hypertarget{group__adt__ghash_gf8c5a4c9b22f8c620ed8875de9545f3e}{
\index{adt\_\-ghash@{adt\_\-ghash}!GHASH\_\-FREE\_\-DEFN@{GHASH\_\-FREE\_\-DEFN}}
\index{GHASH\_\-FREE\_\-DEFN@{GHASH\_\-FREE\_\-DEFN}!adt_ghash@{adt\_\-ghash}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}\#define GHASH\_\-FREE\_\-DEFN(PREFIX)}}
\label{group__adt__ghash_gf8c5a4c9b22f8c620ed8875de9545f3e}


\textbf{Value:}

\begin{Code}\begin{verbatim}void PREFIX##_free(struct ghash* d) { \
  ghash_free(d); \
}
\end{verbatim}
\end{Code}
Define a specialized {\tt \hyperlink{structghash}{ghash}} table free function. \hypertarget{group__adt__ghash_gabe08d7de7829f19e51789b06b1a95da}{
\index{adt\_\-ghash@{adt\_\-ghash}!GHASH\_\-GET\_\-DEFN@{GHASH\_\-GET\_\-DEFN}}
\index{GHASH\_\-GET\_\-DEFN@{GHASH\_\-GET\_\-DEFN}!adt_ghash@{adt\_\-ghash}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}\#define GHASH\_\-GET\_\-DEFN(PREFIX, KTYPE)}}
\label{group__adt__ghash_gabe08d7de7829f19e51789b06b1a95da}


\textbf{Value:}

\begin{Code}\begin{verbatim}struct PREFIX##_entry* PREFIX##_get(struct ghash* d, KTYPE const* key) { \
  return ghash_get(d, key); \
}
\end{verbatim}
\end{Code}
Define a specialized {\tt \hyperlink{structghash}{ghash}} table get function. \hypertarget{group__adt__ghash_g1cf13ef03b3c316a344d5a7f5af2ef9f}{
\index{adt\_\-ghash@{adt\_\-ghash}!ghash\_\-hashb@{ghash\_\-hashb}}
\index{ghash\_\-hashb@{ghash\_\-hashb}!adt_ghash@{adt\_\-ghash}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}\#define ghash\_\-hashb~adt\_\-hashb}}
\label{group__adt__ghash_g1cf13ef03b3c316a344d5a7f5af2ef9f}


The {\tt adt\_\-hashb} function also works for \hyperlink{structghash}{ghash} \hypertarget{group__adt__ghash_ga793802d1ccac89ba8f2450041b19510}{
\index{adt\_\-ghash@{adt\_\-ghash}!ghash\_\-hashs@{ghash\_\-hashs}}
\index{ghash\_\-hashs@{ghash\_\-hashs}!adt_ghash@{adt\_\-ghash}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}\#define ghash\_\-hashs~adt\_\-hashs}}
\label{group__adt__ghash_ga793802d1ccac89ba8f2450041b19510}


The {\tt adt\_\-hashs} function also works for \hyperlink{structghash}{ghash} \hypertarget{group__adt__ghash_g67d80747f0e39bdaaaa34c1a3efa45b9}{
\index{adt\_\-ghash@{adt\_\-ghash}!ghash\_\-hashsp@{ghash\_\-hashsp}}
\index{ghash\_\-hashsp@{ghash\_\-hashsp}!adt_ghash@{adt\_\-ghash}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}\#define ghash\_\-hashsp~adt\_\-hashsp}}
\label{group__adt__ghash_g67d80747f0e39bdaaaa34c1a3efa45b9}


The {\tt adt\_\-hashsp} function also works for \hyperlink{structghash}{ghash} \hypertarget{group__adt__ghash_g46a99956ed09905f7f8c32c603347bd3}{
\index{adt\_\-ghash@{adt\_\-ghash}!GHASH\_\-INIT\_\-DEFN@{GHASH\_\-INIT\_\-DEFN}}
\index{GHASH\_\-INIT\_\-DEFN@{GHASH\_\-INIT\_\-DEFN}!adt_ghash@{adt\_\-ghash}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}\#define GHASH\_\-INIT\_\-DEFN(PREFIX, KTYPE, DTYPE, HASHFN, CMP, KCOPY, DCOPY, KFREE, DFREE)}}
\label{group__adt__ghash_g46a99956ed09905f7f8c32c603347bd3}


\textbf{Value:}

\begin{Code}\begin{verbatim}void PREFIX##_init(struct ghash* d) { \
  ghash_init(d, \
             GHASH_KEYSIZE(PREFIX), \
             sizeof(struct PREFIX##_entry), \
             (adt_hash_fn*)HASHFN, \
             (adt_cmp_fn*)CMP, \
             (adt_copy_fn*)KCOPY, \
             (adt_copy_fn*)DCOPY, \
             (adt_free_fn*)KFREE, \
             (adt_free_fn*)DFREE); \
}
\end{verbatim}
\end{Code}
Define a specialized {\tt \hyperlink{structghash}{ghash}} table init function. \hypertarget{group__adt__ghash_g4275ace9d4a3af4cac0ffb37cfb0285a}{
\index{adt\_\-ghash@{adt\_\-ghash}!GHASH\_\-KEYOFFSET@{GHASH\_\-KEYOFFSET}}
\index{GHASH\_\-KEYOFFSET@{GHASH\_\-KEYOFFSET}!adt_ghash@{adt\_\-ghash}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}\#define GHASH\_\-KEYOFFSET(PREFIX)~((unsigned long)\&((struct PREFIX\#\#\_\-entry$\ast$)0) $\rightarrow$ key)}}
\label{group__adt__ghash_g4275ace9d4a3af4cac0ffb37cfb0285a}


The offset of the key into a specialized {\tt \hyperlink{structghash}{ghash}} entry. \hypertarget{group__adt__ghash_g3464d7a289b27e168f574b1d8f8a8be3}{
\index{adt\_\-ghash@{adt\_\-ghash}!GHASH\_\-KEYSIZE@{GHASH\_\-KEYSIZE}}
\index{GHASH\_\-KEYSIZE@{GHASH\_\-KEYSIZE}!adt_ghash@{adt\_\-ghash}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}\#define GHASH\_\-KEYSIZE(PREFIX)}}
\label{group__adt__ghash_g3464d7a289b27e168f574b1d8f8a8be3}


\textbf{Value:}

\begin{Code}\begin{verbatim}( \
  GHASH_DATAOFFSET(PREFIX)-GHASH_KEYOFFSET(PREFIX) \
)
\end{verbatim}
\end{Code}
The actual size of the key data in a specialized {\tt \hyperlink{structghash}{ghash}} entry. \hypertarget{group__adt__ghash_g5462bc3c7d1eea455b6733ce60bd39d5}{
\index{adt\_\-ghash@{adt\_\-ghash}!GHASH\_\-REBUILD\_\-DEFN@{GHASH\_\-REBUILD\_\-DEFN}}
\index{GHASH\_\-REBUILD\_\-DEFN@{GHASH\_\-REBUILD\_\-DEFN}!adt_ghash@{adt\_\-ghash}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}\#define GHASH\_\-REBUILD\_\-DEFN(PREFIX)}}
\label{group__adt__ghash_g5462bc3c7d1eea455b6733ce60bd39d5}


\textbf{Value:}

\begin{Code}\begin{verbatim}int PREFIX##_rebuild(struct ghash* d) { \
  return ghash_rebuild(d); \
}
\end{verbatim}
\end{Code}
Define a specialized {\tt \hyperlink{structghash}{ghash}} table rebuild function. \hypertarget{group__adt__ghash_g2293adaa2df56053b058ff937e7c7254}{
\index{adt\_\-ghash@{adt\_\-ghash}!GHASH\_\-REHASH\_\-DEFN@{GHASH\_\-REHASH\_\-DEFN}}
\index{GHASH\_\-REHASH\_\-DEFN@{GHASH\_\-REHASH\_\-DEFN}!adt_ghash@{adt\_\-ghash}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}\#define GHASH\_\-REHASH\_\-DEFN(PREFIX)}}
\label{group__adt__ghash_g2293adaa2df56053b058ff937e7c7254}


\textbf{Value:}

\begin{Code}\begin{verbatim}int PREFIX##_rehash(struct ghash* d) { \
  return ghash_rehash(d); \
}
\end{verbatim}
\end{Code}
Define a specialized {\tt \hyperlink{structghash}{ghash}} table rehash function. \hypertarget{group__adt__ghash_g4de5f1ce7dc082245c22f16635a9f5c5}{
\index{adt\_\-ghash@{adt\_\-ghash}!GHASH\_\-REMOVE\_\-DEFN@{GHASH\_\-REMOVE\_\-DEFN}}
\index{GHASH\_\-REMOVE\_\-DEFN@{GHASH\_\-REMOVE\_\-DEFN}!adt_ghash@{adt\_\-ghash}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}\#define GHASH\_\-REMOVE\_\-DEFN(PREFIX, KTYPE)}}
\label{group__adt__ghash_g4de5f1ce7dc082245c22f16635a9f5c5}


\textbf{Value:}

\begin{Code}\begin{verbatim}extern int PREFIX##_remove(struct ghash* d, KTYPE const* key) { \
  return ghash_remove(d, (void*)key); \
}
\end{verbatim}
\end{Code}
Define a specialized {\tt \hyperlink{structghash}{ghash}} table remove function. \hypertarget{group__adt__ghash_ge84cc453db9361a299216c9211abc968}{
\index{adt\_\-ghash@{adt\_\-ghash}!GHASH\_\-SEARCH\_\-DEFN@{GHASH\_\-SEARCH\_\-DEFN}}
\index{GHASH\_\-SEARCH\_\-DEFN@{GHASH\_\-SEARCH\_\-DEFN}!adt_ghash@{adt\_\-ghash}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}\#define GHASH\_\-SEARCH\_\-DEFN(PREFIX)}}
\label{group__adt__ghash_ge84cc453db9361a299216c9211abc968}


\textbf{Value:}

\begin{Code}\begin{verbatim}struct PREFIX##_entry* PREFIX##_search(struct ghash* d, int (*fn)(const struct PREFIX##_entry*)) { \
  return ghash_search(d, (int (*)(const void*))fn); \
}
\end{verbatim}
\end{Code}
Define a specialized {\tt \hyperlink{structghash}{ghash}} table search function. \hypertarget{group__adt__ghash_g5c819bab0cc126b53ffe8b7c6e38bb27}{
\index{adt\_\-ghash@{adt\_\-ghash}!GHASH\_\-SET\_\-DEFN@{GHASH\_\-SET\_\-DEFN}}
\index{GHASH\_\-SET\_\-DEFN@{GHASH\_\-SET\_\-DEFN}!adt_ghash@{adt\_\-ghash}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}\#define GHASH\_\-SET\_\-DEFN(PREFIX, KTYPE, DTYPE)}}
\label{group__adt__ghash_g5c819bab0cc126b53ffe8b7c6e38bb27}


\textbf{Value:}

\begin{Code}\begin{verbatim}struct PREFIX##_entry* PREFIX##_set(struct ghash* d, \
                                    KTYPE const* key, DTYPE const* data) { \
  return ghash_set(d, key, data); \
}
\end{verbatim}
\end{Code}
Define a specialized {\tt \hyperlink{structghash}{ghash}} table add function. \hypertarget{group__adt__ghash_gda65697b1f72b4e162981b6e5ac590e8}{
\index{adt\_\-ghash@{adt\_\-ghash}!GHASH\_\-STRUCT\_\-ENTRY@{GHASH\_\-STRUCT\_\-ENTRY}}
\index{GHASH\_\-STRUCT\_\-ENTRY@{GHASH\_\-STRUCT\_\-ENTRY}!adt_ghash@{adt\_\-ghash}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}\#define GHASH\_\-STRUCT\_\-ENTRY(PREFIX, KTYPE, DTYPE)}}
\label{group__adt__ghash_gda65697b1f72b4e162981b6e5ac590e8}


\textbf{Value:}

\begin{Code}\begin{verbatim}struct PREFIX##_entry { \
  adt_hash_t hash; \
  KTYPE key; \
  DTYPE data; \
}
\end{verbatim}
\end{Code}
Prototype for the {\tt \hyperlink{structghash}{ghash}} entry structure, containing a key of type {\tt KTYPE} and data of type {\tt DTYPE} . \hypertarget{group__adt__ghash_g7db779509845eb235a86abc751e44887}{
\index{adt\_\-ghash@{adt\_\-ghash}!ghashiter\_\-loop@{ghashiter\_\-loop}}
\index{ghashiter\_\-loop@{ghashiter\_\-loop}!adt_ghash@{adt\_\-ghash}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}\#define ghashiter\_\-loop(I, G)~for(ghashiter\_\-first(I,G);ghashiter\_\-valid(I);ghashiter\_\-next(I))}}
\label{group__adt__ghash_g7db779509845eb235a86abc751e44887}


A convenience macro which expands to a {\tt for} loop using the {\tt \hyperlink{structghashiter}{ghashiter}} I to iterate over the table {\tt G} . \begin{Desc}
\item[Examples: ]\par
\hyperlink{adt_2ghash__test_8c-example}{adt/ghash\_\-test.c}.\end{Desc}


\subsection{Function Documentation}
\hypertarget{group__adt__ghash_g6550c0dfe54e19112959dba7b164058a}{
\index{adt\_\-ghash@{adt\_\-ghash}!ghash\_\-add@{ghash\_\-add}}
\index{ghash\_\-add@{ghash\_\-add}!adt_ghash@{adt\_\-ghash}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}void$\ast$ ghash\_\-add (struct {\bf ghash} $\ast$ {\em d}, const void $\ast$ {\em key}, const void $\ast$ {\em data})}}
\label{group__adt__ghash_g6550c0dfe54e19112959dba7b164058a}


Add an entry into a generic hash table. This function adds a new entry into the given hash table. If the table is too small to provide sufficient slots for efficient access, the table is automatically expanded to the next larger size and all the existing entries are copied over. \hypertarget{group__adt__ghash_g92c681d50d718324d18ea35118593e0b}{
\index{adt\_\-ghash@{adt\_\-ghash}!ghash\_\-find@{ghash\_\-find}}
\index{ghash\_\-find@{ghash\_\-find}!adt_ghash@{adt\_\-ghash}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}void$\ast$$\ast$ ghash\_\-find (struct {\bf ghash} $\ast$ {\em d}, const void $\ast$ {\em key})}}
\label{group__adt__ghash_g92c681d50d718324d18ea35118593e0b}


Find an entry in a {\tt \hyperlink{structghash}{ghash}} table.

\begin{Desc}
\item[Returns:]A pointer to the entry structure, or {\tt NULL} if the {\tt key} was not found. \end{Desc}
\hypertarget{group__adt__ghash_g4778a040ba311b5925ca15d7ca640bf9}{
\index{adt\_\-ghash@{adt\_\-ghash}!ghash\_\-foreach@{ghash\_\-foreach}}
\index{ghash\_\-foreach@{ghash\_\-foreach}!adt_ghash@{adt\_\-ghash}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}void ghash\_\-foreach (struct {\bf ghash} $\ast$ {\em d}, void($\ast$)(void $\ast$entry) {\em fn})}}
\label{group__adt__ghash_g4778a040ba311b5925ca15d7ca640bf9}


Iterate over a {\tt \hyperlink{structghash}{ghash}} table, calling a function for each entry. \hypertarget{group__adt__ghash_ge609d6df48e1e10a1391d1c94c1dc9ac}{
\index{adt\_\-ghash@{adt\_\-ghash}!ghash\_\-free@{ghash\_\-free}}
\index{ghash\_\-free@{ghash\_\-free}!adt_ghash@{adt\_\-ghash}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}void ghash\_\-free (struct {\bf ghash} $\ast$ {\em d})}}
\label{group__adt__ghash_ge609d6df48e1e10a1391d1c94c1dc9ac}


Free all data (and entries) in a {\tt \hyperlink{structghash}{ghash}} table. \hypertarget{group__adt__ghash_g4b02b70d7c67a779a9dca5aa23b7f0f4}{
\index{adt\_\-ghash@{adt\_\-ghash}!ghash\_\-get@{ghash\_\-get}}
\index{ghash\_\-get@{ghash\_\-get}!adt_ghash@{adt\_\-ghash}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}void$\ast$ ghash\_\-get (struct {\bf ghash} $\ast$ {\em d}, const void $\ast$ {\em key})}}
\label{group__adt__ghash_g4b02b70d7c67a779a9dca5aa23b7f0f4}


Find an entry in a {\tt \hyperlink{structghash}{ghash}} table.

\begin{Desc}
\item[Returns:]A pointer to the data structure or {\tt NULL} if the {\tt key} was not found. \end{Desc}
\hypertarget{group__adt__ghash_g5b2766288f28271bbcf0c45f17e82b89}{
\index{adt\_\-ghash@{adt\_\-ghash}!ghash\_\-init@{ghash\_\-init}}
\index{ghash\_\-init@{ghash\_\-init}!adt_ghash@{adt\_\-ghash}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}void ghash\_\-init (struct {\bf ghash} $\ast$ {\em d}, unsigned long {\em keysize}, unsigned long {\em entrysize}, {\bf adt\_\-hash\_\-fn} $\ast$ {\em hashfn}, {\bf adt\_\-cmp\_\-fn} $\ast$ {\em keycmp}, {\bf adt\_\-copy\_\-fn} $\ast$ {\em keycopy}, {\bf adt\_\-copy\_\-fn} $\ast$ {\em datacopy}, {\bf adt\_\-free\_\-fn} $\ast$ {\em keyfree}, {\bf adt\_\-free\_\-fn} $\ast$ {\em datafree})}}
\label{group__adt__ghash_g5b2766288f28271bbcf0c45f17e82b89}


Initialize an empty {\tt \hyperlink{structghash}{ghash}} table. \hypertarget{group__adt__ghash_ge774815d548201157ed715de43e3ea9d}{
\index{adt\_\-ghash@{adt\_\-ghash}!ghash\_\-insert@{ghash\_\-insert}}
\index{ghash\_\-insert@{ghash\_\-insert}!adt_ghash@{adt\_\-ghash}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}void ghash\_\-insert (struct {\bf ghash} $\ast$ {\em d}, void $\ast$ {\em e})}}
\label{group__adt__ghash_ge774815d548201157ed715de43e3ea9d}


Insert an entry into a {\tt \hyperlink{structghash}{ghash}} table, without resizing it. \hypertarget{group__adt__ghash_g6a6bba38a9aaf20a6b10eeaabaa9b869}{
\index{adt\_\-ghash@{adt\_\-ghash}!ghash\_\-rebuild@{ghash\_\-rebuild}}
\index{ghash\_\-rebuild@{ghash\_\-rebuild}!adt_ghash@{adt\_\-ghash}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}int ghash\_\-rebuild (struct {\bf ghash} $\ast$ {\em d})}}
\label{group__adt__ghash_g6a6bba38a9aaf20a6b10eeaabaa9b869}


Rebuild the entry pointer table in a {\tt \hyperlink{structghash}{ghash}} table. This function is used internally after either rehashing the table or removing an entry. \hypertarget{group__adt__ghash_g4beb7c3192aa1ee02a8bf0142758e1af}{
\index{adt\_\-ghash@{adt\_\-ghash}!ghash\_\-rehash@{ghash\_\-rehash}}
\index{ghash\_\-rehash@{ghash\_\-rehash}!adt_ghash@{adt\_\-ghash}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}int ghash\_\-rehash (struct {\bf ghash} $\ast$ {\em d})}}
\label{group__adt__ghash_g4beb7c3192aa1ee02a8bf0142758e1af}


Regenerate all the hash values in a {\tt \hyperlink{structghash}{ghash}} table and then rebuild it. Use this function when any of the keys change value. \hypertarget{group__adt__ghash_gad78f59b6f21c62f96285d1583e017fb}{
\index{adt\_\-ghash@{adt\_\-ghash}!ghash\_\-remove@{ghash\_\-remove}}
\index{ghash\_\-remove@{ghash\_\-remove}!adt_ghash@{adt\_\-ghash}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}int ghash\_\-remove (struct {\bf ghash} $\ast$ {\em d}, const void $\ast$ {\em key})}}
\label{group__adt__ghash_gad78f59b6f21c62f96285d1583e017fb}


Remove an entry from a {\tt \hyperlink{structghash}{ghash}} table. This function attempts to do the minimum amount of rebuilding necessary to adjust the positions of entries that may fall in the same slot as the newly removed entry.

\begin{Desc}
\item[Returns:]True if the entry was found (and removed), false otherwise. \end{Desc}
\begin{Desc}
\item[Examples: ]\par
\hyperlink{adt_2ghash__test_8c-example}{adt/ghash\_\-test.c}.\end{Desc}
\hypertarget{group__adt__ghash_g0065ab7531db704c0e51250c519693cc}{
\index{adt\_\-ghash@{adt\_\-ghash}!ghash\_\-search@{ghash\_\-search}}
\index{ghash\_\-search@{ghash\_\-search}!adt_ghash@{adt\_\-ghash}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}void$\ast$ ghash\_\-search (struct {\bf ghash} $\ast$ {\em d}, int($\ast$)(const void $\ast$entry) {\em fn})}}
\label{group__adt__ghash_g0065ab7531db704c0e51250c519693cc}


Search for the first entry in the {\tt \hyperlink{structghash}{ghash}} table for which the given function returns true. \hypertarget{group__adt__ghash_g199afecbf45d644c8371b612141df54b}{
\index{adt\_\-ghash@{adt\_\-ghash}!ghash\_\-set@{ghash\_\-set}}
\index{ghash\_\-set@{ghash\_\-set}!adt_ghash@{adt\_\-ghash}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}void$\ast$ ghash\_\-set (struct {\bf ghash} $\ast$ {\em d}, const void $\ast$ {\em key}, const void $\ast$ {\em data})}}
\label{group__adt__ghash_g199afecbf45d644c8371b612141df54b}


Replace or add an entry into a generic hash table. \begin{Desc}
\item[Examples: ]\par
\hyperlink{adt_2ghash__test_8c-example}{adt/ghash\_\-test.c}.\end{Desc}
\hypertarget{group__adt__ghash_g3c21bcee8850adc76bee68ee8dd7df3e}{
\index{adt\_\-ghash@{adt\_\-ghash}!ghashiter\_\-first@{ghashiter\_\-first}}
\index{ghashiter\_\-first@{ghashiter\_\-first}!adt_ghash@{adt\_\-ghash}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}void ghashiter\_\-first (struct {\bf ghashiter} $\ast$ {\em iter}, const struct {\bf ghash} $\ast$ {\em h})}}
\label{group__adt__ghash_g3c21bcee8850adc76bee68ee8dd7df3e}


Set a {\tt \hyperlink{structghash}{ghash}} iterator to the first element in the table. \hypertarget{group__adt__ghash_g733a92b13ce772e7e3810ea65fcd6454}{
\index{adt\_\-ghash@{adt\_\-ghash}!ghashiter\_\-next@{ghashiter\_\-next}}
\index{ghashiter\_\-next@{ghashiter\_\-next}!adt_ghash@{adt\_\-ghash}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}void ghashiter\_\-next (struct {\bf ghashiter} $\ast$ {\em iter})}}
\label{group__adt__ghash_g733a92b13ce772e7e3810ea65fcd6454}


Advance the {\tt \hyperlink{structghash}{ghash}} iterator to the next element in the table. \hypertarget{group__adt__ghash_g03c8f3d628d6ea8c54ecffe4e892178f}{
\index{adt\_\-ghash@{adt\_\-ghash}!ghashiter\_\-valid@{ghashiter\_\-valid}}
\index{ghashiter\_\-valid@{ghashiter\_\-valid}!adt_ghash@{adt\_\-ghash}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}int ghashiter\_\-valid (const struct {\bf ghashiter} $\ast$ {\em iter})}}
\label{group__adt__ghash_g03c8f3d628d6ea8c54ecffe4e892178f}


Check if the {\tt \hyperlink{structghash}{ghash}} iterator is still valid. 