\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)\&((struct PREFIX\#\#\_\-entry$\ast$)0) $\rightarrow$ key)
\item 
\#define \hyperlink{group__adt__ghash_gd9dcfdb435e30e32b276f8ba0cc04b0a}{GHASH\_\-DATAOFFSET}(PREFIX)~((unsigned)\&((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_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 \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 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[GHASH\_\-ADD\_\-DEFN]{\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 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[GHASH\_\-DATAOFFSET]{\setlength{\rightskip}{0pt plus 5cm}\#define GHASH\_\-DATAOFFSET(PREFIX)~((unsigned)\&((struct PREFIX\#\#\_\-entry$\ast$)0) $\rightarrow$ data)}}
\label{group__adt__ghash_gd9dcfdb435e30e32b276f8ba0cc04b0a}


The offset of the data into a specialized {\tt 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[GHASH\_\-DECL]{\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##_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 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[GHASH\_\-DEFN]{\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_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 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[ghash\_\-entry\_\-dataptr]{\setlength{\rightskip}{0pt plus 5cm}\#define ghash\_\-entry\_\-dataptr(P, L)~((P)+sizeof(\hyperlink{group__adt_gab1a0335d8d46afee323cf2b3d132145}{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[ghash\_\-entry\_\-hash]{\setlength{\rightskip}{0pt plus 5cm}\#define ghash\_\-entry\_\-hash(P)~($\ast$(\hyperlink{group__adt_gab1a0335d8d46afee323cf2b3d132145}{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[ghash\_\-entry\_\-keyptr]{\setlength{\rightskip}{0pt plus 5cm}\#define ghash\_\-entry\_\-keyptr(P)~((P)+sizeof(\hyperlink{group__adt_gab1a0335d8d46afee323cf2b3d132145}{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[GHASH\_\-FOREACH\_\-DEFN]{\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 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[GHASH\_\-FREE\_\-DEFN]{\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 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[GHASH\_\-GET\_\-DEFN]{\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 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[ghash\_\-hashb]{\setlength{\rightskip}{0pt plus 5cm}\#define ghash\_\-hashb~adt\_\-hashb}}
\label{group__adt__ghash_g1cf13ef03b3c316a344d5a7f5af2ef9f}


The {\tt adt\_\-hashb} function also works for 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[ghash\_\-hashs]{\setlength{\rightskip}{0pt plus 5cm}\#define ghash\_\-hashs~adt\_\-hashs}}
\label{group__adt__ghash_ga793802d1ccac89ba8f2450041b19510}


The {\tt adt\_\-hashs} function also works for 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[ghash\_\-hashsp]{\setlength{\rightskip}{0pt plus 5cm}\#define ghash\_\-hashsp~adt\_\-hashsp}}
\label{group__adt__ghash_g67d80747f0e39bdaaaa34c1a3efa45b9}


The {\tt adt\_\-hashsp} function also works for 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[GHASH\_\-INIT\_\-DEFN]{\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 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[GHASH\_\-KEYOFFSET]{\setlength{\rightskip}{0pt plus 5cm}\#define GHASH\_\-KEYOFFSET(PREFIX)~((unsigned)\&((struct PREFIX\#\#\_\-entry$\ast$)0) $\rightarrow$ key)}}
\label{group__adt__ghash_g4275ace9d4a3af4cac0ffb37cfb0285a}


The offset of the key into a specialized {\tt 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[GHASH\_\-KEYSIZE]{\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 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[GHASH\_\-REBUILD\_\-DEFN]{\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 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[GHASH\_\-REHASH\_\-DEFN]{\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 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[GHASH\_\-REMOVE\_\-DEFN]{\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 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[GHASH\_\-SEARCH\_\-DEFN]{\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 ghash} table search 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[GHASH\_\-STRUCT\_\-ENTRY]{\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 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[ghashiter\_\-loop]{\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 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[ghash\_\-add]{\setlength{\rightskip}{0pt plus 5cm}void$\ast$ ghash\_\-add (struct \hyperlink{structghash}{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[ghash\_\-find]{\setlength{\rightskip}{0pt plus 5cm}void$\ast$$\ast$ ghash\_\-find (struct \hyperlink{structghash}{ghash} $\ast$ {\em d}, const void $\ast$ {\em key})}}
\label{group__adt__ghash_g92c681d50d718324d18ea35118593e0b}


Find an entry in a {\tt 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[ghash\_\-foreach]{\setlength{\rightskip}{0pt plus 5cm}void ghash\_\-foreach (struct \hyperlink{structghash}{ghash} $\ast$ {\em d}, void($\ast$)(void $\ast$entry) {\em fn})}}
\label{group__adt__ghash_g4778a040ba311b5925ca15d7ca640bf9}


Iterate over a {\tt 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[ghash\_\-free]{\setlength{\rightskip}{0pt plus 5cm}void ghash\_\-free (struct \hyperlink{structghash}{ghash} $\ast$ {\em d})}}
\label{group__adt__ghash_ge609d6df48e1e10a1391d1c94c1dc9ac}


Free all data (and entries) in a {\tt 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[ghash\_\-get]{\setlength{\rightskip}{0pt plus 5cm}void$\ast$ ghash\_\-get (struct \hyperlink{structghash}{ghash} $\ast$ {\em d}, const void $\ast$ {\em key})}}
\label{group__adt__ghash_g4b02b70d7c67a779a9dca5aa23b7f0f4}


Find an entry in a {\tt 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[ghash\_\-init]{\setlength{\rightskip}{0pt plus 5cm}void ghash\_\-init (struct \hyperlink{structghash}{ghash} $\ast$ {\em d}, unsigned long {\em keysize}, unsigned long {\em entrysize}, \hyperlink{group__adt_gd6ce53fbc11dbf67ca1c126cd17ee81a}{adt\_\-hash\_\-fn} $\ast$ {\em hashfn}, \hyperlink{group__adt_g03ed35b7331128b069dc77ab33798782}{adt\_\-cmp\_\-fn} $\ast$ {\em keycmp}, \hyperlink{group__adt_ga98f7f3499407a5dc1afdcbb20df2e15}{adt\_\-copy\_\-fn} $\ast$ {\em keycopy}, \hyperlink{group__adt_ga98f7f3499407a5dc1afdcbb20df2e15}{adt\_\-copy\_\-fn} $\ast$ {\em datacopy}, \hyperlink{group__adt_g87ba7ca9dce36c22fe75a730a1d768a9}{adt\_\-free\_\-fn} $\ast$ {\em keyfree}, \hyperlink{group__adt_g87ba7ca9dce36c22fe75a730a1d768a9}{adt\_\-free\_\-fn} $\ast$ {\em datafree})}}
\label{group__adt__ghash_g5b2766288f28271bbcf0c45f17e82b89}


Initialize an empty {\tt 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[ghash\_\-insert]{\setlength{\rightskip}{0pt plus 5cm}void ghash\_\-insert (struct \hyperlink{structghash}{ghash} $\ast$ {\em d}, void $\ast$ {\em e})}}
\label{group__adt__ghash_ge774815d548201157ed715de43e3ea9d}


Insert an entry into a {\tt 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[ghash\_\-rebuild]{\setlength{\rightskip}{0pt plus 5cm}int ghash\_\-rebuild (struct \hyperlink{structghash}{ghash} $\ast$ {\em d})}}
\label{group__adt__ghash_g6a6bba38a9aaf20a6b10eeaabaa9b869}


Rebuild the entry pointer table in a {\tt 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[ghash\_\-rehash]{\setlength{\rightskip}{0pt plus 5cm}int ghash\_\-rehash (struct \hyperlink{structghash}{ghash} $\ast$ {\em d})}}
\label{group__adt__ghash_g4beb7c3192aa1ee02a8bf0142758e1af}


Regenerate all the hash values in a {\tt 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[ghash\_\-remove]{\setlength{\rightskip}{0pt plus 5cm}int ghash\_\-remove (struct \hyperlink{structghash}{ghash} $\ast$ {\em d}, const void $\ast$ {\em key})}}
\label{group__adt__ghash_gad78f59b6f21c62f96285d1583e017fb}


Remove an entry from a {\tt 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[ghash\_\-search]{\setlength{\rightskip}{0pt plus 5cm}void$\ast$ ghash\_\-search (struct \hyperlink{structghash}{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 ghash} table for which the given function returns true. \hypertarget{group__adt__ghash_g3c21bcee8850adc76bee68ee8dd7df3e}{
\index{adt_ghash@{adt\_\-ghash}!ghashiter_first@{ghashiter\_\-first}}
\index{ghashiter_first@{ghashiter\_\-first}!adt_ghash@{adt\_\-ghash}}
\subsubsection[ghashiter\_\-first]{\setlength{\rightskip}{0pt plus 5cm}void ghashiter\_\-first (struct \hyperlink{structghashiter}{ghashiter} $\ast$ {\em iter}, const struct \hyperlink{structghash}{ghash} $\ast$ {\em h})}}
\label{group__adt__ghash_g3c21bcee8850adc76bee68ee8dd7df3e}


Set a {\tt 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[ghashiter\_\-next]{\setlength{\rightskip}{0pt plus 5cm}void ghashiter\_\-next (struct \hyperlink{structghashiter}{ghashiter} $\ast$ {\em iter})}}
\label{group__adt__ghash_g733a92b13ce772e7e3810ea65fcd6454}


Advance the {\tt 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[ghashiter\_\-valid]{\setlength{\rightskip}{0pt plus 5cm}int ghashiter\_\-valid (const struct \hyperlink{structghashiter}{ghashiter} $\ast$ {\em iter})}}
\label{group__adt__ghash_g03c8f3d628d6ea8c54ecffe4e892178f}


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