\doxysection{hash\+\_\+table.\+c}
\label{hash__table_8c_source}\index{src/libsphinxbase/util/hash\_table.c@{src/libsphinxbase/util/hash\_table.c}}

\begin{DoxyCode}{0}
\DoxyCodeLine{00001\ \textcolor{comment}{/*\ -\/*-\/\ c-\/basic-\/offset:\ 4;\ indent-\/tabs-\/mode:\ nil\ -\/*-\/\ */}}
\DoxyCodeLine{00002\ \textcolor{comment}{/*\ ====================================================================}}
\DoxyCodeLine{00003\ \textcolor{comment}{\ *\ Copyright\ (c)\ 1999-\/2004\ Carnegie\ Mellon\ University.\ \ All\ rights}}
\DoxyCodeLine{00004\ \textcolor{comment}{\ *\ reserved.}}
\DoxyCodeLine{00005\ \textcolor{comment}{\ *}}
\DoxyCodeLine{00006\ \textcolor{comment}{\ *\ Redistribution\ and\ use\ in\ source\ and\ binary\ forms,\ with\ or\ without}}
\DoxyCodeLine{00007\ \textcolor{comment}{\ *\ modification,\ are\ permitted\ provided\ that\ the\ following\ conditions}}
\DoxyCodeLine{00008\ \textcolor{comment}{\ *\ are\ met:}}
\DoxyCodeLine{00009\ \textcolor{comment}{\ *}}
\DoxyCodeLine{00010\ \textcolor{comment}{\ *\ 1.\ Redistributions\ of\ source\ code\ must\ retain\ the\ above\ copyright}}
\DoxyCodeLine{00011\ \textcolor{comment}{\ *\ \ \ \ notice,\ this\ list\ of\ conditions\ and\ the\ following\ disclaimer.\ }}
\DoxyCodeLine{00012\ \textcolor{comment}{\ *}}
\DoxyCodeLine{00013\ \textcolor{comment}{\ *\ 2.\ Redistributions\ in\ binary\ form\ must\ reproduce\ the\ above\ copyright}}
\DoxyCodeLine{00014\ \textcolor{comment}{\ *\ \ \ \ notice,\ this\ list\ of\ conditions\ and\ the\ following\ disclaimer\ in}}
\DoxyCodeLine{00015\ \textcolor{comment}{\ *\ \ \ \ the\ documentation\ and/or\ other\ materials\ provided\ with\ the}}
\DoxyCodeLine{00016\ \textcolor{comment}{\ *\ \ \ \ distribution.}}
\DoxyCodeLine{00017\ \textcolor{comment}{\ *}}
\DoxyCodeLine{00018\ \textcolor{comment}{\ *\ This\ work\ was\ supported\ in\ part\ by\ funding\ from\ the\ Defense\ Advanced\ }}
\DoxyCodeLine{00019\ \textcolor{comment}{\ *\ Research\ Projects\ Agency\ and\ the\ National\ Science\ Foundation\ of\ the\ }}
\DoxyCodeLine{00020\ \textcolor{comment}{\ *\ United\ States\ of\ America,\ and\ the\ CMU\ Sphinx\ Speech\ Consortium.}}
\DoxyCodeLine{00021\ \textcolor{comment}{\ *}}
\DoxyCodeLine{00022\ \textcolor{comment}{\ *\ THIS\ SOFTWARE\ IS\ PROVIDED\ BY\ CARNEGIE\ MELLON\ UNIVERSITY\ \`{}\`{}AS\ IS''\ AND\ }}
\DoxyCodeLine{00023\ \textcolor{comment}{\ *\ ANY\ EXPRESSED\ OR\ IMPLIED\ WARRANTIES,\ INCLUDING,\ BUT\ NOT\ LIMITED\ TO,\ }}
\DoxyCodeLine{00024\ \textcolor{comment}{\ *\ THE\ IMPLIED\ WARRANTIES\ OF\ MERCHANTABILITY\ AND\ FITNESS\ FOR\ A\ PARTICULAR}}
\DoxyCodeLine{00025\ \textcolor{comment}{\ *\ PURPOSE\ ARE\ DISCLAIMED.\ \ IN\ NO\ EVENT\ SHALL\ CARNEGIE\ MELLON\ UNIVERSITY}}
\DoxyCodeLine{00026\ \textcolor{comment}{\ *\ NOR\ ITS\ EMPLOYEES\ BE\ LIABLE\ FOR\ ANY\ DIRECT,\ INDIRECT,\ INCIDENTAL,}}
\DoxyCodeLine{00027\ \textcolor{comment}{\ *\ SPECIAL,\ EXEMPLARY,\ OR\ CONSEQUENTIAL\ DAMAGES\ (INCLUDING,\ BUT\ NOT\ }}
\DoxyCodeLine{00028\ \textcolor{comment}{\ *\ LIMITED\ TO,\ PROCUREMENT\ OF\ SUBSTITUTE\ GOODS\ OR\ SERVICES;\ LOSS\ OF\ USE,\ }}
\DoxyCodeLine{00029\ \textcolor{comment}{\ *\ DATA,\ OR\ PROFITS;\ OR\ BUSINESS\ INTERRUPTION)\ HOWEVER\ CAUSED\ AND\ ON\ ANY\ }}
\DoxyCodeLine{00030\ \textcolor{comment}{\ *\ THEORY\ OF\ LIABILITY,\ WHETHER\ IN\ CONTRACT,\ STRICT\ LIABILITY,\ OR\ TORT\ }}
\DoxyCodeLine{00031\ \textcolor{comment}{\ *\ (INCLUDING\ NEGLIGENCE\ OR\ OTHERWISE)\ ARISING\ IN\ ANY\ WAY\ OUT\ OF\ THE\ USE\ }}
\DoxyCodeLine{00032\ \textcolor{comment}{\ *\ OF\ THIS\ SOFTWARE,\ EVEN\ IF\ ADVISED\ OF\ THE\ POSSIBILITY\ OF\ SUCH\ DAMAGE.}}
\DoxyCodeLine{00033\ \textcolor{comment}{\ *}}
\DoxyCodeLine{00034\ \textcolor{comment}{\ *\ ====================================================================}}
\DoxyCodeLine{00035\ \textcolor{comment}{\ *}}
\DoxyCodeLine{00036\ \textcolor{comment}{\ */}}
\DoxyCodeLine{00037\ \textcolor{comment}{/*}}
\DoxyCodeLine{00038\ \textcolor{comment}{\ *\ hash.c\ -\/-\/\ Hash\ table\ module.}}
\DoxyCodeLine{00039\ \textcolor{comment}{\ *}}
\DoxyCodeLine{00040\ \textcolor{comment}{\ *\ **********************************************}}
\DoxyCodeLine{00041\ \textcolor{comment}{\ *\ CMU\ ARPA\ Speech\ Project}}
\DoxyCodeLine{00042\ \textcolor{comment}{\ *}}
\DoxyCodeLine{00043\ \textcolor{comment}{\ *\ Copyright\ (c)\ 1999\ Carnegie\ Mellon\ University.}}
\DoxyCodeLine{00044\ \textcolor{comment}{\ *\ ALL\ RIGHTS\ RESERVED.}}
\DoxyCodeLine{00045\ \textcolor{comment}{\ *\ **********************************************}}
\DoxyCodeLine{00046\ \textcolor{comment}{\ *\ }}
\DoxyCodeLine{00047\ \textcolor{comment}{\ *\ HISTORY}}
\DoxyCodeLine{00048\ \textcolor{comment}{\ *\ \$Log:\ hash.c,v\ \$}}
\DoxyCodeLine{00049\ \textcolor{comment}{\ *\ Revision\ 1.5\ \ 2005/06/22\ 03:04:01\ \ arthchan2003}}
\DoxyCodeLine{00050\ \textcolor{comment}{\ *\ 1,\ Implemented\ hash\_delete\ and\ hash\_display,\ 2,\ Fixed\ doxygen\ documentation,\ 3,\ Added\ \ keyword.}}
\DoxyCodeLine{00051\ \textcolor{comment}{\ *}}
\DoxyCodeLine{00052\ \textcolor{comment}{\ *\ Revision\ 1.9\ \ 2005/05/25\ 06:17:53\ \ archan}}
\DoxyCodeLine{00053\ \textcolor{comment}{\ *\ Delete\ the\ test\ code\ in\ cmd\_ln.c\ and\ fixed\ platform\ specific\ code\ of\ hash.c}}
\DoxyCodeLine{00054\ \textcolor{comment}{\ *}}
\DoxyCodeLine{00055\ \textcolor{comment}{\ *\ Revision\ 1.8\ \ 2005/05/24\ 01:10:54\ \ archan}}
\DoxyCodeLine{00056\ \textcolor{comment}{\ *\ Fix\ a\ bug\ when\ the\ value\ only\ appear\ in\ the\ hash\ but\ there\ is\ no\ chain.\ \ \ Also\ make\ sure\ that\ prev\ was\ initialized\ to\ NULL.\ All\ success\ cases\ were\ tested,\ but\ not\ tested\ with\ the\ deletion\ is\ tested.}}
\DoxyCodeLine{00057\ \textcolor{comment}{\ *}}
\DoxyCodeLine{00058\ \textcolor{comment}{\ *\ Revision\ 1.6\ \ 2005/05/24\ 00:00:45\ \ archan}}
\DoxyCodeLine{00059\ \textcolor{comment}{\ *\ Added\ basic\ functionalities\ to\ hash\_t:\ 1,\ display\ and\ 2,\ delete\ a\ key\ from\ a\ hash.\ \(\backslash\)n}}
\DoxyCodeLine{00060\ \textcolor{comment}{\ *}}
\DoxyCodeLine{00061\ \textcolor{comment}{\ *\ Revision\ 1.5\ \ 2005/05/11\ 07:01:38\ \ archan}}
\DoxyCodeLine{00062\ \textcolor{comment}{\ *\ Added\ comments\ on\ the\ usage\ of\ the\ current\ implementation\ of\ hash\ tables.}}
\DoxyCodeLine{00063\ \textcolor{comment}{\ *}}
\DoxyCodeLine{00064\ \textcolor{comment}{\ *\ Revision\ 1.4\ \ 2005/05/03\ 04:09:11\ \ archan}}
\DoxyCodeLine{00065\ \textcolor{comment}{\ *\ Implemented\ the\ heart\ of\ word\ copy\ search.\ For\ every\ ci-\/phone,\ every\ word\ end,\ a\ tree\ will\ be\ allocated\ to\ preserve\ its\ pathscore.\ \ This\ is\ different\ from\ 3.5\ or\ below,\ only\ the\ best\ score\ for\ a\ particular\ ci-\/phone,\ regardless\ of\ the\ word-\/ends\ will\ be\ preserved\ at\ every\ frame.\ \ The\ graph\ propagation\ will\ not\ collect\ unused\ word\ tree\ at\ this\ point.\ srch\_WST\_propagate\_wd\_lv2\ is\ also\ as\ the\ most\ stupid\ in\ the\ century.\ \ But\ well,\ after\ all,\ everything\ needs\ a\ start.\ \ I\ will\ then\ really\ get\ the\ results\ from\ the\ search\ and\ see\ how\ it\ looks.}}
\DoxyCodeLine{00066\ \textcolor{comment}{\ *}}
\DoxyCodeLine{00067\ \textcolor{comment}{\ *\ Revision\ 1.3\ \ 2005/03/30\ 01:22:48\ \ archan}}
\DoxyCodeLine{00068\ \textcolor{comment}{\ *\ Fixed\ mistakes\ in\ last\ updates.\ Add}}
\DoxyCodeLine{00069\ \textcolor{comment}{\ *}}
\DoxyCodeLine{00070\ \textcolor{comment}{\ *\ }}
\DoxyCodeLine{00071\ \textcolor{comment}{\ *\ 05-\/May-\/1999\ \ M\ K\ Ravishankar\ (rkm@cs.cmu.edu)\ at\ Carnegie\ Mellon}}
\DoxyCodeLine{00072\ \textcolor{comment}{\ *\ \ \ \ \ \ \ \ \ \ \ \ \ \ Removed\ hash\_key2hash().\ \ Added\ hash\_enter\_bkey()\ and\ hash\_lookup\_bkey(),}}
\DoxyCodeLine{00073\ \textcolor{comment}{\ *\ \ \ \ \ \ \ \ \ \ \ \ \ \ and\ len\ attribute\ to\ hash\_entry\_t.}}
\DoxyCodeLine{00074\ \textcolor{comment}{\ *\ }}
\DoxyCodeLine{00075\ \textcolor{comment}{\ *\ 30-\/Apr-\/1999\ \ M\ K\ Ravishankar\ (rkm@cs.cmu.edu)\ at\ Carnegie\ Mellon}}
\DoxyCodeLine{00076\ \textcolor{comment}{\ *\ \ \ \ \ \ \ \ \ \ \ \ \ \ Added\ hash\_key2hash().}}
\DoxyCodeLine{00077\ \textcolor{comment}{\ *\ }}
\DoxyCodeLine{00078\ \textcolor{comment}{\ *\ 18-\/Jun-\/97\ \ \ \ M\ K\ Ravishankar\ (rkm@cs.cmu.edu)\ at\ Carnegie\ Mellon}}
\DoxyCodeLine{00079\ \textcolor{comment}{\ *\ \ \ \ \ \ \ \ \ \ \ \ \ \ Included\ case\ sensitive/insensitive\ option.\ \ Removed\ local,\ static}}
\DoxyCodeLine{00080\ \textcolor{comment}{\ *\ \ \ \ \ \ \ \ \ \ \ \ \ \ maintenance\ of\ all\ hash\ tables.}}
\DoxyCodeLine{00081\ \textcolor{comment}{\ *\ }}
\DoxyCodeLine{00082\ \textcolor{comment}{\ *\ 31-\/Jul-\/95\ \ \ \ M\ K\ Ravishankar\ (rkm@cs.cmu.edu)\ at\ Carnegie\ Mellon}}
\DoxyCodeLine{00083\ \textcolor{comment}{\ *\ \ \ \ \ \ \ \ \ \ \ \ \ \ Created.}}
\DoxyCodeLine{00084\ \textcolor{comment}{\ */}}
\DoxyCodeLine{00085\ }
\DoxyCodeLine{00086\ }
\DoxyCodeLine{00087\ \textcolor{preprocessor}{\#include\ <stdio.h>}}
\DoxyCodeLine{00088\ \textcolor{preprocessor}{\#include\ <stdlib.h>}}
\DoxyCodeLine{00089\ \textcolor{preprocessor}{\#include\ <string.h>}}
\DoxyCodeLine{00090\ \textcolor{preprocessor}{\#include\ <assert.h>}}
\DoxyCodeLine{00091\ }
\DoxyCodeLine{00092\ \textcolor{preprocessor}{\#ifdef\ \_MSC\_VER}}
\DoxyCodeLine{00093\ \textcolor{preprocessor}{\#pragma\ warning\ (disable:\ 4018)}}
\DoxyCodeLine{00094\ \textcolor{preprocessor}{\#endif}}
\DoxyCodeLine{00095\ }
\DoxyCodeLine{00096\ \textcolor{preprocessor}{\#include\ "{}sphinxbase/hash\_table.h"{}}}
\DoxyCodeLine{00097\ \textcolor{preprocessor}{\#include\ "{}sphinxbase/err.h"{}}}
\DoxyCodeLine{00098\ \textcolor{preprocessor}{\#include\ "{}sphinxbase/ckd\_alloc.h"{}}}
\DoxyCodeLine{00099\ \textcolor{preprocessor}{\#include\ "{}sphinxbase/case.h"{}}}
\DoxyCodeLine{00100\ }
\DoxyCodeLine{00101\ }
\DoxyCodeLine{00102\ \textcolor{preprocessor}{\#if\ 0}}
\DoxyCodeLine{00103\ \textcolor{keyword}{static}\ \textcolor{keywordtype}{void}}
\DoxyCodeLine{00104\ prime\_sieve(int32\ max)}
\DoxyCodeLine{00105\ \{}
\DoxyCodeLine{00106\ \ \ \ \ \textcolor{keywordtype}{char}\ *notprime;}
\DoxyCodeLine{00107\ \ \ \ \ int32\ p,\ pp;}
\DoxyCodeLine{00108\ }
\DoxyCodeLine{00109\ \ \ \ \ notprime\ =\ (\textcolor{keywordtype}{char}\ *)\ ckd\_calloc(max\ +\ 1,\ 1);}
\DoxyCodeLine{00110\ \ \ \ \ p\ =\ 2;}
\DoxyCodeLine{00111\ \ \ \ \ \textcolor{keywordflow}{for}\ (;;)\ \{}
\DoxyCodeLine{00112\ \ \ \ \ \ \ \ \ printf(\textcolor{stringliteral}{"{}\%d\(\backslash\)n"{}},\ p);}
\DoxyCodeLine{00113\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{for}\ (pp\ =\ p\ +\ p;\ pp\ <=\ max;\ pp\ +=\ p)}
\DoxyCodeLine{00114\ \ \ \ \ \ \ \ \ \ \ \ \ notprime[pp]\ =\ 1;}
\DoxyCodeLine{00115\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{for}\ (++p;\ (p\ <=\ max)\ \&\&\ notprime[p];\ p++);}
\DoxyCodeLine{00116\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (p\ >\ max)}
\DoxyCodeLine{00117\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{break};}
\DoxyCodeLine{00118\ \ \ \ \ \}}
\DoxyCodeLine{00119\ \}}
\DoxyCodeLine{00120\ \textcolor{preprocessor}{\#endif}}
\DoxyCodeLine{00121\ }
\DoxyCodeLine{00122\ }
\DoxyCodeLine{00123\ \textcolor{comment}{/*}}
\DoxyCodeLine{00124\ \textcolor{comment}{\ *\ HACK!!\ \ Initial\ hash\ table\ size\ is\ restricted\ by\ this\ set\ of\ primes.\ \ (Of\ course,}}
\DoxyCodeLine{00125\ \textcolor{comment}{\ *\ collision\ resolution\ by\ chaining\ will\ accommodate\ more\ entries\ indefinitely,\ but}}
\DoxyCodeLine{00126\ \textcolor{comment}{\ *\ efficiency\ will\ drop.)}}
\DoxyCodeLine{00127\ \textcolor{comment}{\ */}}
\DoxyCodeLine{00128\ \textcolor{keyword}{const}\ int32\ prime[]\ =\ \{}
\DoxyCodeLine{00129\ \ \ \ \ 101,\ 211,\ 307,\ 401,\ 503,\ 601,\ 701,\ 809,\ 907,}
\DoxyCodeLine{00130\ \ \ \ \ 1009,\ 1201,\ 1601,\ 2003,\ 2411,\ 3001,\ 4001,\ 5003,\ 6007,\ 7001,\ 8009,}
\DoxyCodeLine{00131\ \ \ \ \ 9001,}
\DoxyCodeLine{00132\ \ \ \ \ 10007,\ 12007,\ 16001,\ 20011,\ 24001,\ 30011,\ 40009,\ 50021,\ 60013,}
\DoxyCodeLine{00133\ \ \ \ \ 70001,\ 80021,\ 90001,}
\DoxyCodeLine{00134\ \ \ \ \ 100003,\ 120011,\ 160001,\ 200003,\ 240007,\ 300007,\ 400009,\ 500009,}
\DoxyCodeLine{00135\ \ \ \ \ 600011,\ 700001,\ 800011,\ 900001,}
\DoxyCodeLine{00136\ \ \ \ \ -\/1}
\DoxyCodeLine{00137\ \};}
\DoxyCodeLine{00138\ }
\DoxyCodeLine{00139\ }
\DoxyCodeLine{00143\ \textcolor{keyword}{static}\ int32}
\DoxyCodeLine{00144\ prime\_size(int32\ size)}
\DoxyCodeLine{00145\ \{}
\DoxyCodeLine{00146\ \ \ \ \ int32\ i;}
\DoxyCodeLine{00147\ }
\DoxyCodeLine{00148\ \ \ \ \ \textcolor{keywordflow}{for}\ (i\ =\ 0;\ (prime[i]\ >\ 0)\ \&\&\ (prime[i]\ <\ size);\ i++);}
\DoxyCodeLine{00149\ \ \ \ \ \textcolor{keywordflow}{if}\ (prime[i]\ <=\ 0)\ \{}
\DoxyCodeLine{00150\ \ \ \ \ \ \ \ \ E\_WARN(\textcolor{stringliteral}{"{}Very\ large\ hash\ table\ requested\ (\%d\ entries)\(\backslash\)n"{}},\ size);}
\DoxyCodeLine{00151\ \ \ \ \ \ \ \ \ -\/-\/i;}
\DoxyCodeLine{00152\ \ \ \ \ \}}
\DoxyCodeLine{00153\ \ \ \ \ \textcolor{keywordflow}{return}\ (prime[i]);}
\DoxyCodeLine{00154\ \}}
\DoxyCodeLine{00155\ }
\DoxyCodeLine{00156\ }
\DoxyCodeLine{00157\ hash\_table\_t\ *}
\DoxyCodeLine{00158\ hash\_table\_new(int32\ size,\ int32\ casearg)}
\DoxyCodeLine{00159\ \{}
\DoxyCodeLine{00160\ \ \ \ \ hash\_table\_t\ *h;}
\DoxyCodeLine{00161\ }
\DoxyCodeLine{00162\ \ \ \ \ h\ =\ (hash\_table\_t\ *)\ ckd\_calloc(1,\ \textcolor{keyword}{sizeof}(hash\_table\_t));}
\DoxyCodeLine{00163\ \ \ \ \ h-\/>size\ =\ prime\_size(size\ +\ (size\ >>\ 1));}
\DoxyCodeLine{00164\ \ \ \ \ h-\/>nocase\ =\ (casearg\ ==\ HASH\_CASE\_NO);}
\DoxyCodeLine{00165\ \ \ \ \ h-\/>table\ =\ (hash\_entry\_t\ *)\ ckd\_calloc(h-\/>size,\ \textcolor{keyword}{sizeof}(hash\_entry\_t));}
\DoxyCodeLine{00166\ \ \ \ \ \textcolor{comment}{/*\ The\ above\ calloc\ clears\ h-\/>table[*].key\ and\ .next\ to\ NULL,\ i.e.\ an\ empty\ table\ */}}
\DoxyCodeLine{00167\ }
\DoxyCodeLine{00168\ \ \ \ \ \textcolor{keywordflow}{return}\ h;}
\DoxyCodeLine{00169\ \}}
\DoxyCodeLine{00170\ }
\DoxyCodeLine{00171\ }
\DoxyCodeLine{00172\ \textcolor{comment}{/*}}
\DoxyCodeLine{00173\ \textcolor{comment}{\ *\ Compute\ hash\ value\ for\ given\ key\ string.}}
\DoxyCodeLine{00174\ \textcolor{comment}{\ *\ Somewhat\ tuned\ for\ English\ text\ word\ strings.}}
\DoxyCodeLine{00175\ \textcolor{comment}{\ */}}
\DoxyCodeLine{00176\ \textcolor{keyword}{static}\ uint32}
\DoxyCodeLine{00177\ key2hash(hash\_table\_t\ *\ h,\ \textcolor{keyword}{const}\ \textcolor{keywordtype}{char}\ *key)}
\DoxyCodeLine{00178\ \{}
\DoxyCodeLine{00179\ }
\DoxyCodeLine{00180\ \ \ \ \ \textcolor{keyword}{register}\ \textcolor{keyword}{const}\ \textcolor{keywordtype}{char}\ *cp;}
\DoxyCodeLine{00181\ }
\DoxyCodeLine{00191\ \ \ \ \ \textcolor{comment}{/*register\ char\ c;\ */}}
\DoxyCodeLine{00192\ \ \ \ \ \textcolor{keyword}{register}\ \textcolor{keywordtype}{unsigned}\ \textcolor{keywordtype}{char}\ c;}
\DoxyCodeLine{00193\ \ \ \ \ \textcolor{keyword}{register}\ int32\ s;}
\DoxyCodeLine{00194\ \ \ \ \ \textcolor{keyword}{register}\ uint32\ hash;}
\DoxyCodeLine{00195\ }
\DoxyCodeLine{00196\ \ \ \ \ hash\ =\ 0;}
\DoxyCodeLine{00197\ \ \ \ \ s\ =\ 0;}
\DoxyCodeLine{00198\ }
\DoxyCodeLine{00199\ \ \ \ \ \textcolor{keywordflow}{if}\ (h-\/>nocase)\ \{}
\DoxyCodeLine{00200\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{for}\ (cp\ =\ key;\ *cp;\ cp++)\ \{}
\DoxyCodeLine{00201\ \ \ \ \ \ \ \ \ \ \ \ \ c\ =\ *cp;}
\DoxyCodeLine{00202\ \ \ \ \ \ \ \ \ \ \ \ \ c\ =\ UPPER\_CASE(c);}
\DoxyCodeLine{00203\ \ \ \ \ \ \ \ \ \ \ \ \ hash\ +=\ c\ <<\ s;}
\DoxyCodeLine{00204\ \ \ \ \ \ \ \ \ \ \ \ \ s\ +=\ 5;}
\DoxyCodeLine{00205\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (s\ >=\ 25)}
\DoxyCodeLine{00206\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ s\ -\/=\ 24;}
\DoxyCodeLine{00207\ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00208\ \ \ \ \ \}}
\DoxyCodeLine{00209\ \ \ \ \ \textcolor{keywordflow}{else}\ \{}
\DoxyCodeLine{00210\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{for}\ (cp\ =\ key;\ *cp;\ cp++)\ \{}
\DoxyCodeLine{00211\ \ \ \ \ \ \ \ \ \ \ \ \ hash\ +=\ (*cp)\ <<\ s;}
\DoxyCodeLine{00212\ \ \ \ \ \ \ \ \ \ \ \ \ s\ +=\ 5;}
\DoxyCodeLine{00213\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (s\ >=\ 25)}
\DoxyCodeLine{00214\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ s\ -\/=\ 24;}
\DoxyCodeLine{00215\ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00216\ \ \ \ \ \}}
\DoxyCodeLine{00217\ }
\DoxyCodeLine{00218\ \ \ \ \ \textcolor{keywordflow}{return}\ (hash\ \%\ h-\/>size);}
\DoxyCodeLine{00219\ \}}
\DoxyCodeLine{00220\ }
\DoxyCodeLine{00221\ }
\DoxyCodeLine{00222\ \textcolor{keyword}{static}\ \textcolor{keywordtype}{char}\ *}
\DoxyCodeLine{00223\ makekey(uint8\ *\ data,\ int32\ len,\ \textcolor{keywordtype}{char}\ *key)}
\DoxyCodeLine{00224\ \{}
\DoxyCodeLine{00225\ \ \ \ \ int32\ i,\ j;}
\DoxyCodeLine{00226\ }
\DoxyCodeLine{00227\ \ \ \ \ \textcolor{keywordflow}{if}\ (!key)}
\DoxyCodeLine{00228\ \ \ \ \ \ \ \ \ key\ =\ (\textcolor{keywordtype}{char}\ *)\ ckd\_calloc(len\ *\ 2\ +\ 1,\ \textcolor{keyword}{sizeof}(\textcolor{keywordtype}{char}));}
\DoxyCodeLine{00229\ }
\DoxyCodeLine{00230\ \ \ \ \ \textcolor{keywordflow}{for}\ (i\ =\ 0,\ j\ =\ 0;\ i\ <\ len;\ i++,\ j\ +=\ 2)\ \{}
\DoxyCodeLine{00231\ \ \ \ \ \ \ \ \ key[j]\ =\ \textcolor{charliteral}{'A'}\ +\ (data[i]\ \&\ 0x000f);}
\DoxyCodeLine{00232\ \ \ \ \ \ \ \ \ key[j\ +\ 1]\ =\ \textcolor{charliteral}{'J'}\ +\ ((data[i]\ >>\ 4)\ \&\ 0x000f);}
\DoxyCodeLine{00233\ \ \ \ \ \}}
\DoxyCodeLine{00234\ \ \ \ \ key[j]\ =\ \textcolor{charliteral}{'\(\backslash\)0'};}
\DoxyCodeLine{00235\ }
\DoxyCodeLine{00236\ \ \ \ \ \textcolor{keywordflow}{return}\ key;}
\DoxyCodeLine{00237\ \}}
\DoxyCodeLine{00238\ }
\DoxyCodeLine{00239\ }
\DoxyCodeLine{00240\ \textcolor{keyword}{static}\ int32}
\DoxyCodeLine{00241\ keycmp\_nocase(hash\_entry\_t\ *\ entry,\ \textcolor{keyword}{const}\ \textcolor{keywordtype}{char}\ *key)}
\DoxyCodeLine{00242\ \{}
\DoxyCodeLine{00243\ \ \ \ \ \textcolor{keywordtype}{char}\ c1,\ c2;}
\DoxyCodeLine{00244\ \ \ \ \ int32\ i;}
\DoxyCodeLine{00245\ \ \ \ \ \textcolor{keyword}{const}\ \textcolor{keywordtype}{char}\ *str;}
\DoxyCodeLine{00246\ }
\DoxyCodeLine{00247\ \ \ \ \ str\ =\ entry-\/>key;}
\DoxyCodeLine{00248\ \ \ \ \ \textcolor{keywordflow}{for}\ (i\ =\ 0;\ i\ <\ entry-\/>len;\ i++)\ \{}
\DoxyCodeLine{00249\ \ \ \ \ \ \ \ \ c1\ =\ *(str++);}
\DoxyCodeLine{00250\ \ \ \ \ \ \ \ \ c1\ =\ UPPER\_CASE(c1);}
\DoxyCodeLine{00251\ \ \ \ \ \ \ \ \ c2\ =\ *(key++);}
\DoxyCodeLine{00252\ \ \ \ \ \ \ \ \ c2\ =\ UPPER\_CASE(c2);}
\DoxyCodeLine{00253\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (c1\ !=\ c2)}
\DoxyCodeLine{00254\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ (c1\ -\/\ c2);}
\DoxyCodeLine{00255\ \ \ \ \ \}}
\DoxyCodeLine{00256\ }
\DoxyCodeLine{00257\ \ \ \ \ \textcolor{keywordflow}{return}\ 0;}
\DoxyCodeLine{00258\ \}}
\DoxyCodeLine{00259\ }
\DoxyCodeLine{00260\ }
\DoxyCodeLine{00261\ \textcolor{keyword}{static}\ int32}
\DoxyCodeLine{00262\ keycmp\_case(hash\_entry\_t\ *\ entry,\ \textcolor{keyword}{const}\ \textcolor{keywordtype}{char}\ *key)}
\DoxyCodeLine{00263\ \{}
\DoxyCodeLine{00264\ \ \ \ \ \textcolor{keywordtype}{char}\ c1,\ c2;}
\DoxyCodeLine{00265\ \ \ \ \ int32\ i;}
\DoxyCodeLine{00266\ \ \ \ \ \textcolor{keyword}{const}\ \textcolor{keywordtype}{char}\ *str;}
\DoxyCodeLine{00267\ }
\DoxyCodeLine{00268\ \ \ \ \ str\ =\ entry-\/>key;}
\DoxyCodeLine{00269\ \ \ \ \ \textcolor{keywordflow}{for}\ (i\ =\ 0;\ i\ <\ entry-\/>len;\ i++)\ \{}
\DoxyCodeLine{00270\ \ \ \ \ \ \ \ \ c1\ =\ *(str++);}
\DoxyCodeLine{00271\ \ \ \ \ \ \ \ \ c2\ =\ *(key++);}
\DoxyCodeLine{00272\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (c1\ !=\ c2)}
\DoxyCodeLine{00273\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ (c1\ -\/\ c2);}
\DoxyCodeLine{00274\ \ \ \ \ \}}
\DoxyCodeLine{00275\ }
\DoxyCodeLine{00276\ \ \ \ \ \textcolor{keywordflow}{return}\ 0;}
\DoxyCodeLine{00277\ \}}
\DoxyCodeLine{00278\ }
\DoxyCodeLine{00279\ }
\DoxyCodeLine{00280\ \textcolor{comment}{/*}}
\DoxyCodeLine{00281\ \textcolor{comment}{\ *\ Lookup\ entry\ with\ hash-\/value\ hash\ in\ table\ h\ for\ given\ key}}
\DoxyCodeLine{00282\ \textcolor{comment}{\ *\ Return\ value:\ hash\_entry\_t\ for\ key}}
\DoxyCodeLine{00283\ \textcolor{comment}{\ */}}
\DoxyCodeLine{00284\ \textcolor{keyword}{static}\ hash\_entry\_t\ *}
\DoxyCodeLine{00285\ lookup(hash\_table\_t\ *\ h,\ uint32\ hash,\ \textcolor{keyword}{const}\ \textcolor{keywordtype}{char}\ *key,\ \textcolor{keywordtype}{size\_t}\ len)}
\DoxyCodeLine{00286\ \{}
\DoxyCodeLine{00287\ \ \ \ \ hash\_entry\_t\ *entry;}
\DoxyCodeLine{00288\ }
\DoxyCodeLine{00289\ \ \ \ \ entry\ =\ \&(h-\/>table[hash]);}
\DoxyCodeLine{00290\ \ \ \ \ \textcolor{keywordflow}{if}\ (entry-\/>key\ ==\ NULL)}
\DoxyCodeLine{00291\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ NULL;}
\DoxyCodeLine{00292\ }
\DoxyCodeLine{00293\ \ \ \ \ \textcolor{keywordflow}{if}\ (h-\/>nocase)\ \{}
\DoxyCodeLine{00294\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{while}\ (entry\ \&\&\ ((entry-\/>len\ !=\ len)}
\DoxyCodeLine{00295\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ ||\ (keycmp\_nocase(entry,\ key)\ !=\ 0)))}
\DoxyCodeLine{00296\ \ \ \ \ \ \ \ \ \ \ \ \ entry\ =\ entry-\/>next;}
\DoxyCodeLine{00297\ \ \ \ \ \}}
\DoxyCodeLine{00298\ \ \ \ \ \textcolor{keywordflow}{else}\ \{}
\DoxyCodeLine{00299\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{while}\ (entry\ \&\&\ ((entry-\/>len\ !=\ len)}
\DoxyCodeLine{00300\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ ||\ (keycmp\_case(entry,\ key)\ !=\ 0)))}
\DoxyCodeLine{00301\ \ \ \ \ \ \ \ \ \ \ \ \ entry\ =\ entry-\/>next;}
\DoxyCodeLine{00302\ \ \ \ \ \}}
\DoxyCodeLine{00303\ }
\DoxyCodeLine{00304\ \ \ \ \ \textcolor{keywordflow}{return}\ entry;}
\DoxyCodeLine{00305\ \}}
\DoxyCodeLine{00306\ }
\DoxyCodeLine{00307\ }
\DoxyCodeLine{00308\ int32}
\DoxyCodeLine{00309\ hash\_table\_lookup(hash\_table\_t\ *\ h,\ \textcolor{keyword}{const}\ \textcolor{keywordtype}{char}\ *key,\ \textcolor{keywordtype}{void}\ **\ val)}
\DoxyCodeLine{00310\ \{}
\DoxyCodeLine{00311\ \ \ \ \ hash\_entry\_t\ *entry;}
\DoxyCodeLine{00312\ \ \ \ \ uint32\ hash;}
\DoxyCodeLine{00313\ \ \ \ \ int32\ len;}
\DoxyCodeLine{00314\ }
\DoxyCodeLine{00315\ \ \ \ \ hash\ =\ key2hash(h,\ key);}
\DoxyCodeLine{00316\ \ \ \ \ len\ =\ strlen(key);}
\DoxyCodeLine{00317\ }
\DoxyCodeLine{00318\ \ \ \ \ entry\ =\ lookup(h,\ hash,\ key,\ len);}
\DoxyCodeLine{00319\ \ \ \ \ \textcolor{keywordflow}{if}\ (entry)\ \{}
\DoxyCodeLine{00320\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (val)}
\DoxyCodeLine{00321\ \ \ \ \ \ \ \ \ \ \ \ \ *val\ =\ entry-\/>val;}
\DoxyCodeLine{00322\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ 0;}
\DoxyCodeLine{00323\ \ \ \ \ \}}
\DoxyCodeLine{00324\ \ \ \ \ \textcolor{keywordflow}{else}}
\DoxyCodeLine{00325\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ -\/1;}
\DoxyCodeLine{00326\ \}}
\DoxyCodeLine{00327\ }
\DoxyCodeLine{00328\ int32}
\DoxyCodeLine{00329\ hash\_table\_lookup\_int32(hash\_table\_t\ *\ h,\ \textcolor{keyword}{const}\ \textcolor{keywordtype}{char}\ *key,\ int32\ *val)}
\DoxyCodeLine{00330\ \{}
\DoxyCodeLine{00331\ \ \ \ \ \textcolor{keywordtype}{void}\ *vval;}
\DoxyCodeLine{00332\ \ \ \ \ int32\ rv;}
\DoxyCodeLine{00333\ }
\DoxyCodeLine{00334\ \ \ \ \ rv\ =\ hash\_table\_lookup(h,\ key,\ \&vval);}
\DoxyCodeLine{00335\ \ \ \ \ \textcolor{keywordflow}{if}\ (rv\ !=\ 0)}
\DoxyCodeLine{00336\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ rv;}
\DoxyCodeLine{00337\ \ \ \ \ \textcolor{keywordflow}{if}\ (val)}
\DoxyCodeLine{00338\ \ \ \ \ \ \ \ \ *val\ =\ (int32)(\textcolor{keywordtype}{long})vval;}
\DoxyCodeLine{00339\ \ \ \ \ \textcolor{keywordflow}{return}\ 0;}
\DoxyCodeLine{00340\ \}}
\DoxyCodeLine{00341\ }
\DoxyCodeLine{00342\ }
\DoxyCodeLine{00343\ int32}
\DoxyCodeLine{00344\ hash\_table\_lookup\_bkey(hash\_table\_t\ *\ h,\ \textcolor{keyword}{const}\ \textcolor{keywordtype}{char}\ *key,\ \textcolor{keywordtype}{size\_t}\ len,\ \textcolor{keywordtype}{void}\ **\ val)}
\DoxyCodeLine{00345\ \{}
\DoxyCodeLine{00346\ \ \ \ \ hash\_entry\_t\ *entry;}
\DoxyCodeLine{00347\ \ \ \ \ uint32\ hash;}
\DoxyCodeLine{00348\ \ \ \ \ \textcolor{keywordtype}{char}\ *str;}
\DoxyCodeLine{00349\ }
\DoxyCodeLine{00350\ \ \ \ \ str\ =\ makekey((uint8\ *)\ key,\ len,\ NULL);}
\DoxyCodeLine{00351\ \ \ \ \ hash\ =\ key2hash(h,\ str);}
\DoxyCodeLine{00352\ \ \ \ \ ckd\_free(str);}
\DoxyCodeLine{00353\ }
\DoxyCodeLine{00354\ \ \ \ \ entry\ =\ lookup(h,\ hash,\ key,\ len);}
\DoxyCodeLine{00355\ \ \ \ \ \textcolor{keywordflow}{if}\ (entry)\ \{}
\DoxyCodeLine{00356\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (val)}
\DoxyCodeLine{00357\ \ \ \ \ \ \ \ \ \ \ \ \ *val\ =\ entry-\/>val;}
\DoxyCodeLine{00358\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ 0;}
\DoxyCodeLine{00359\ \ \ \ \ \}}
\DoxyCodeLine{00360\ \ \ \ \ \textcolor{keywordflow}{else}}
\DoxyCodeLine{00361\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ -\/1;}
\DoxyCodeLine{00362\ \}}
\DoxyCodeLine{00363\ }
\DoxyCodeLine{00364\ int32}
\DoxyCodeLine{00365\ hash\_table\_lookup\_bkey\_int32(hash\_table\_t\ *\ h,\ \textcolor{keyword}{const}\ \textcolor{keywordtype}{char}\ *key,\ \textcolor{keywordtype}{size\_t}\ len,\ int32\ *val)}
\DoxyCodeLine{00366\ \{}
\DoxyCodeLine{00367\ \ \ \ \ \textcolor{keywordtype}{void}\ *vval;}
\DoxyCodeLine{00368\ \ \ \ \ int32\ rv;}
\DoxyCodeLine{00369\ }
\DoxyCodeLine{00370\ \ \ \ \ rv\ =\ hash\_table\_lookup\_bkey(h,\ key,\ len,\ \&vval);}
\DoxyCodeLine{00371\ \ \ \ \ \textcolor{keywordflow}{if}\ (rv\ !=\ 0)}
\DoxyCodeLine{00372\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ rv;}
\DoxyCodeLine{00373\ \ \ \ \ \textcolor{keywordflow}{if}\ (val)}
\DoxyCodeLine{00374\ \ \ \ \ \ \ \ \ *val\ =\ (int32)(\textcolor{keywordtype}{long})vval;}
\DoxyCodeLine{00375\ \ \ \ \ \textcolor{keywordflow}{return}\ 0;}
\DoxyCodeLine{00376\ \}}
\DoxyCodeLine{00377\ }
\DoxyCodeLine{00378\ }
\DoxyCodeLine{00379\ \textcolor{keyword}{static}\ \textcolor{keywordtype}{void}\ *}
\DoxyCodeLine{00380\ enter(hash\_table\_t\ *\ h,\ uint32\ hash,\ \textcolor{keyword}{const}\ \textcolor{keywordtype}{char}\ *key,\ \textcolor{keywordtype}{size\_t}\ len,\ \textcolor{keywordtype}{void}\ *val,\ int32\ replace)}
\DoxyCodeLine{00381\ \{}
\DoxyCodeLine{00382\ \ \ \ \ hash\_entry\_t\ *cur,\ *\textcolor{keyword}{new};}
\DoxyCodeLine{00383\ }
\DoxyCodeLine{00384\ \ \ \ \ \textcolor{keywordflow}{if}\ ((cur\ =\ lookup(h,\ hash,\ key,\ len))\ !=\ NULL)\ \{}
\DoxyCodeLine{00385\ \ \ \ \ \ \ \ \ \textcolor{keywordtype}{void}\ *oldval;}
\DoxyCodeLine{00386\ \ \ \ \ \ \ \ \ \textcolor{comment}{/*\ Key\ already\ exists.\ */}}
\DoxyCodeLine{00387\ \ \ \ \ \ \ \ \ oldval\ =\ cur-\/>val;}
\DoxyCodeLine{00388\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (replace)\ \{}
\DoxyCodeLine{00389\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{comment}{/*\ Replace\ the\ pointer\ if\ replacement\ is\ requested,}}
\DoxyCodeLine{00390\ \textcolor{comment}{\ \ \ \ \ \ \ \ \ \ \ \ \ *\ because\ this\ might\ be\ a\ different\ instance\ of\ the\ same}}
\DoxyCodeLine{00391\ \textcolor{comment}{\ \ \ \ \ \ \ \ \ \ \ \ \ *\ string\ (this\ verges\ on\ magic,\ sorry)\ */}}
\DoxyCodeLine{00392\ \ \ \ \ \ \ \ \ \ \ \ \ cur-\/>key\ =\ key;}
\DoxyCodeLine{00393\ \ \ \ \ \ \ \ \ \ \ \ \ cur-\/>val\ =\ val;}
\DoxyCodeLine{00394\ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00395\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ oldval;}
\DoxyCodeLine{00396\ \ \ \ \ \}}
\DoxyCodeLine{00397\ }
\DoxyCodeLine{00398\ \ \ \ \ cur\ =\ \&(h-\/>table[hash]);}
\DoxyCodeLine{00399\ \ \ \ \ \textcolor{keywordflow}{if}\ (cur-\/>key\ ==\ NULL)\ \{}
\DoxyCodeLine{00400\ \ \ \ \ \ \ \ \ \textcolor{comment}{/*\ Empty\ slot\ at\ hashed\ location;\ add\ this\ entry\ */}}
\DoxyCodeLine{00401\ \ \ \ \ \ \ \ \ cur-\/>key\ =\ key;}
\DoxyCodeLine{00402\ \ \ \ \ \ \ \ \ cur-\/>len\ =\ len;}
\DoxyCodeLine{00403\ \ \ \ \ \ \ \ \ cur-\/>val\ =\ val;}
\DoxyCodeLine{00404\ }
\DoxyCodeLine{00405\ \ \ \ \ \ \ \ \ \textcolor{comment}{/*\ Added\ by\ ARCHAN\ at\ 20050515.\ This\ allows\ deletion\ could\ work.\ */}}
\DoxyCodeLine{00406\ \ \ \ \ \ \ \ \ cur-\/>next\ =\ NULL;}
\DoxyCodeLine{00407\ }
\DoxyCodeLine{00408\ \ \ \ \ \}}
\DoxyCodeLine{00409\ \ \ \ \ \textcolor{keywordflow}{else}\ \{}
\DoxyCodeLine{00410\ \ \ \ \ \ \ \ \ \textcolor{comment}{/*\ Key\ collision;\ create\ new\ entry\ and\ link\ to\ hashed\ location\ */}}
\DoxyCodeLine{00411\ \ \ \ \ \ \ \ \ \textcolor{keyword}{new}\ =\ (hash\_entry\_t\ *)\ ckd\_calloc(1,\ \textcolor{keyword}{sizeof}(hash\_entry\_t));}
\DoxyCodeLine{00412\ \ \ \ \ \ \ \ \ \textcolor{keyword}{new}-\/>key\ =\ key;}
\DoxyCodeLine{00413\ \ \ \ \ \ \ \ \ \textcolor{keyword}{new}-\/>len\ =\ len;}
\DoxyCodeLine{00414\ \ \ \ \ \ \ \ \ \textcolor{keyword}{new}-\/>val\ =\ val;}
\DoxyCodeLine{00415\ \ \ \ \ \ \ \ \ \textcolor{keyword}{new}-\/>next\ =\ cur-\/>next;}
\DoxyCodeLine{00416\ \ \ \ \ \ \ \ \ cur-\/>next\ =\ \textcolor{keyword}{new};}
\DoxyCodeLine{00417\ \ \ \ \ \}}
\DoxyCodeLine{00418\ \ \ \ \ ++h-\/>inuse;}
\DoxyCodeLine{00419\ }
\DoxyCodeLine{00420\ \ \ \ \ \textcolor{keywordflow}{return}\ val;}
\DoxyCodeLine{00421\ \}}
\DoxyCodeLine{00422\ }
\DoxyCodeLine{00423\ \textcolor{comment}{/*\ 20050523\ Added\ by\ ARCHAN\ \ to\ delete\ a\ key\ from\ a\ hash\ table\ */}}
\DoxyCodeLine{00424\ \textcolor{keyword}{static}\ \textcolor{keywordtype}{void}\ *}
\DoxyCodeLine{00425\ \textcolor{keyword}{delete}(hash\_table\_t\ *\ h,\ uint32\ hash,\ \textcolor{keyword}{const}\ \textcolor{keywordtype}{char}\ *key,\ \textcolor{keywordtype}{size\_t}\ len)}
\DoxyCodeLine{00426\ \{}
\DoxyCodeLine{00427\ \ \ \ \ hash\_entry\_t\ *entry,\ *prev;}
\DoxyCodeLine{00428\ \ \ \ \ \textcolor{keywordtype}{void}\ *val;}
\DoxyCodeLine{00429\ }
\DoxyCodeLine{00430\ \ \ \ \ prev\ =\ NULL;}
\DoxyCodeLine{00431\ \ \ \ \ entry\ =\ \&(h-\/>table[hash]);}
\DoxyCodeLine{00432\ \ \ \ \ \textcolor{keywordflow}{if}\ (entry-\/>key\ ==\ NULL)}
\DoxyCodeLine{00433\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ NULL;}
\DoxyCodeLine{00434\ }
\DoxyCodeLine{00435\ \ \ \ \ \textcolor{keywordflow}{if}\ (h-\/>nocase)\ \{}
\DoxyCodeLine{00436\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{while}\ (entry\ \&\&\ ((entry-\/>len\ !=\ len)}
\DoxyCodeLine{00437\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ ||\ (keycmp\_nocase(entry,\ key)\ !=\ 0)))\ \{}
\DoxyCodeLine{00438\ \ \ \ \ \ \ \ \ \ \ \ \ prev\ =\ entry;}
\DoxyCodeLine{00439\ \ \ \ \ \ \ \ \ \ \ \ \ entry\ =\ entry-\/>next;}
\DoxyCodeLine{00440\ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00441\ \ \ \ \ \}}
\DoxyCodeLine{00442\ \ \ \ \ \textcolor{keywordflow}{else}\ \{}
\DoxyCodeLine{00443\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{while}\ (entry\ \&\&\ ((entry-\/>len\ !=\ len)}
\DoxyCodeLine{00444\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ ||\ (keycmp\_case(entry,\ key)\ !=\ 0)))\ \{}
\DoxyCodeLine{00445\ \ \ \ \ \ \ \ \ \ \ \ \ prev\ =\ entry;}
\DoxyCodeLine{00446\ \ \ \ \ \ \ \ \ \ \ \ \ entry\ =\ entry-\/>next;}
\DoxyCodeLine{00447\ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00448\ \ \ \ \ \}}
\DoxyCodeLine{00449\ }
\DoxyCodeLine{00450\ \ \ \ \ \textcolor{keywordflow}{if}\ (entry\ ==\ NULL)}
\DoxyCodeLine{00451\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ NULL;}
\DoxyCodeLine{00452\ }
\DoxyCodeLine{00453\ \ \ \ \ \textcolor{comment}{/*\ At\ this\ point,\ entry\ will\ be\ the\ one\ required\ to\ be\ deleted,\ prev}}
\DoxyCodeLine{00454\ \textcolor{comment}{\ \ \ \ \ \ \ will\ contain\ the\ previous\ entry}}
\DoxyCodeLine{00455\ \textcolor{comment}{\ \ \ \ \ */}}
\DoxyCodeLine{00456\ \ \ \ \ val\ =\ entry-\/>val;}
\DoxyCodeLine{00457\ }
\DoxyCodeLine{00458\ \ \ \ \ \textcolor{keywordflow}{if}\ (prev\ ==\ NULL)\ \{}
\DoxyCodeLine{00459\ \ \ \ \ \ \ \ \ \textcolor{comment}{/*\ That\ is\ to\ say\ the\ entry\ in\ the\ hash\ table\ (not\ the\ chain)\ matched\ the\ key.\ */}}
\DoxyCodeLine{00460\ \ \ \ \ \ \ \ \ \textcolor{comment}{/*\ We\ will\ then\ copy\ the\ things\ from\ the\ next\ entry\ to\ the\ hash\ table\ */}}
\DoxyCodeLine{00461\ \ \ \ \ \ \ \ \ prev\ =\ entry;}
\DoxyCodeLine{00462\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (entry-\/>next)\ \{\ \ \ \ \ \ \textcolor{comment}{/*\ There\ is\ a\ next\ entry,\ great,\ copy\ it.\ */}}
\DoxyCodeLine{00463\ \ \ \ \ \ \ \ \ \ \ \ \ entry\ =\ entry-\/>next;}
\DoxyCodeLine{00464\ \ \ \ \ \ \ \ \ \ \ \ \ prev-\/>key\ =\ entry-\/>key;}
\DoxyCodeLine{00465\ \ \ \ \ \ \ \ \ \ \ \ \ prev-\/>len\ =\ entry-\/>len;}
\DoxyCodeLine{00466\ \ \ \ \ \ \ \ \ \ \ \ \ prev-\/>val\ =\ entry-\/>val;}
\DoxyCodeLine{00467\ \ \ \ \ \ \ \ \ \ \ \ \ prev-\/>next\ =\ entry-\/>next;}
\DoxyCodeLine{00468\ \ \ \ \ \ \ \ \ \ \ \ \ ckd\_free(entry);}
\DoxyCodeLine{00469\ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00470\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{else}\ \{\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{comment}{/*\ There\ is\ not\ a\ next\ entry,\ just\ set\ the\ key\ to\ null\ */}}
\DoxyCodeLine{00471\ \ \ \ \ \ \ \ \ \ \ \ \ prev-\/>key\ =\ NULL;}
\DoxyCodeLine{00472\ \ \ \ \ \ \ \ \ \ \ \ \ prev-\/>len\ =\ 0;}
\DoxyCodeLine{00473\ \ \ \ \ \ \ \ \ \ \ \ \ prev-\/>next\ =\ NULL;}
\DoxyCodeLine{00474\ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00475\ }
\DoxyCodeLine{00476\ \ \ \ \ \}}
\DoxyCodeLine{00477\ \ \ \ \ \textcolor{keywordflow}{else}\ \{\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{comment}{/*\ This\ case\ is\ simple\ */}}
\DoxyCodeLine{00478\ \ \ \ \ \ \ \ \ prev-\/>next\ =\ entry-\/>next;}
\DoxyCodeLine{00479\ \ \ \ \ \ \ \ \ ckd\_free(entry);}
\DoxyCodeLine{00480\ \ \ \ \ \}}
\DoxyCodeLine{00481\ }
\DoxyCodeLine{00482\ \ \ \ \ \textcolor{comment}{/*\ Do\ wiring\ and\ free\ the\ entry\ */}}
\DoxyCodeLine{00483\ }
\DoxyCodeLine{00484\ \ \ \ \ -\/-\/h-\/>inuse;}
\DoxyCodeLine{00485\ }
\DoxyCodeLine{00486\ \ \ \ \ \textcolor{keywordflow}{return}\ val;}
\DoxyCodeLine{00487\ \}}
\DoxyCodeLine{00488\ }
\DoxyCodeLine{00489\ \textcolor{keywordtype}{void}}
\DoxyCodeLine{00490\ hash\_table\_empty(hash\_table\_t\ *h)}
\DoxyCodeLine{00491\ \{}
\DoxyCodeLine{00492\ \ \ \ \ hash\_entry\_t\ *e,\ *e2;}
\DoxyCodeLine{00493\ \ \ \ \ int32\ i;}
\DoxyCodeLine{00494\ }
\DoxyCodeLine{00495\ \ \ \ \ \textcolor{keywordflow}{for}\ (i\ =\ 0;\ i\ <\ h-\/>size;\ i++)\ \{}
\DoxyCodeLine{00496\ \ \ \ \ \ \ \ \ \textcolor{comment}{/*\ Free\ collision\ lists.\ */}}
\DoxyCodeLine{00497\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{for}\ (e\ =\ h-\/>table[i].next;\ e;\ e\ =\ e2)\ \{}
\DoxyCodeLine{00498\ \ \ \ \ \ \ \ \ \ \ \ \ e2\ =\ e-\/>next;}
\DoxyCodeLine{00499\ \ \ \ \ \ \ \ \ \ \ \ \ ckd\_free((\textcolor{keywordtype}{void}\ *)\ e);}
\DoxyCodeLine{00500\ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00501\ \ \ \ \ \ \ \ \ memset(\&h-\/>table[i],\ 0,\ \textcolor{keyword}{sizeof}(h-\/>table[i]));}
\DoxyCodeLine{00502\ \ \ \ \ \}}
\DoxyCodeLine{00503\ \ \ \ \ h-\/>inuse\ =\ 0;}
\DoxyCodeLine{00504\ \}}
\DoxyCodeLine{00505\ }
\DoxyCodeLine{00506\ }
\DoxyCodeLine{00507\ \textcolor{keywordtype}{void}\ *}
\DoxyCodeLine{00508\ hash\_table\_enter(hash\_table\_t\ *\ h,\ \textcolor{keyword}{const}\ \textcolor{keywordtype}{char}\ *key,\ \textcolor{keywordtype}{void}\ *val)}
\DoxyCodeLine{00509\ \{}
\DoxyCodeLine{00510\ \ \ \ \ uint32\ hash;}
\DoxyCodeLine{00511\ \ \ \ \ \textcolor{keywordtype}{size\_t}\ len;}
\DoxyCodeLine{00512\ }
\DoxyCodeLine{00513\ \ \ \ \ hash\ =\ key2hash(h,\ key);}
\DoxyCodeLine{00514\ \ \ \ \ len\ =\ strlen(key);}
\DoxyCodeLine{00515\ \ \ \ \ \textcolor{keywordflow}{return}\ (enter(h,\ hash,\ key,\ len,\ val,\ 0));}
\DoxyCodeLine{00516\ \}}
\DoxyCodeLine{00517\ }
\DoxyCodeLine{00518\ \textcolor{keywordtype}{void}\ *}
\DoxyCodeLine{00519\ hash\_table\_replace(hash\_table\_t\ *\ h,\ \textcolor{keyword}{const}\ \textcolor{keywordtype}{char}\ *key,\ \textcolor{keywordtype}{void}\ *val)}
\DoxyCodeLine{00520\ \{}
\DoxyCodeLine{00521\ \ \ \ \ uint32\ hash;}
\DoxyCodeLine{00522\ \ \ \ \ \textcolor{keywordtype}{size\_t}\ len;}
\DoxyCodeLine{00523\ }
\DoxyCodeLine{00524\ \ \ \ \ hash\ =\ key2hash(h,\ key);}
\DoxyCodeLine{00525\ \ \ \ \ len\ =\ strlen(key);}
\DoxyCodeLine{00526\ \ \ \ \ \textcolor{keywordflow}{return}\ (enter(h,\ hash,\ key,\ len,\ val,\ 1));}
\DoxyCodeLine{00527\ \}}
\DoxyCodeLine{00528\ }
\DoxyCodeLine{00529\ \textcolor{keywordtype}{void}\ *}
\DoxyCodeLine{00530\ hash\_table\_delete(hash\_table\_t\ *\ h,\ \textcolor{keyword}{const}\ \textcolor{keywordtype}{char}\ *key)}
\DoxyCodeLine{00531\ \{}
\DoxyCodeLine{00532\ \ \ \ \ uint32\ hash;}
\DoxyCodeLine{00533\ \ \ \ \ \textcolor{keywordtype}{size\_t}\ len;}
\DoxyCodeLine{00534\ }
\DoxyCodeLine{00535\ \ \ \ \ hash\ =\ key2hash(h,\ key);}
\DoxyCodeLine{00536\ \ \ \ \ len\ =\ strlen(key);}
\DoxyCodeLine{00537\ }
\DoxyCodeLine{00538\ \ \ \ \ \textcolor{keywordflow}{return}\ (\textcolor{keyword}{delete}(h,\ hash,\ key,\ len));}
\DoxyCodeLine{00539\ \}}
\DoxyCodeLine{00540\ }
\DoxyCodeLine{00541\ \textcolor{keywordtype}{void}\ *}
\DoxyCodeLine{00542\ hash\_table\_enter\_bkey(hash\_table\_t\ *\ h,\ \textcolor{keyword}{const}\ \textcolor{keywordtype}{char}\ *key,\ \textcolor{keywordtype}{size\_t}\ len,\ \textcolor{keywordtype}{void}\ *val)}
\DoxyCodeLine{00543\ \{}
\DoxyCodeLine{00544\ \ \ \ \ uint32\ hash;}
\DoxyCodeLine{00545\ \ \ \ \ \textcolor{keywordtype}{char}\ *str;}
\DoxyCodeLine{00546\ }
\DoxyCodeLine{00547\ \ \ \ \ str\ =\ makekey((uint8\ *)\ key,\ len,\ NULL);}
\DoxyCodeLine{00548\ \ \ \ \ hash\ =\ key2hash(h,\ str);}
\DoxyCodeLine{00549\ \ \ \ \ ckd\_free(str);}
\DoxyCodeLine{00550\ }
\DoxyCodeLine{00551\ \ \ \ \ \textcolor{keywordflow}{return}\ (enter(h,\ hash,\ key,\ len,\ val,\ 0));}
\DoxyCodeLine{00552\ \}}
\DoxyCodeLine{00553\ }
\DoxyCodeLine{00554\ \textcolor{keywordtype}{void}\ *}
\DoxyCodeLine{00555\ hash\_table\_replace\_bkey(hash\_table\_t\ *\ h,\ \textcolor{keyword}{const}\ \textcolor{keywordtype}{char}\ *key,\ \textcolor{keywordtype}{size\_t}\ len,\ \textcolor{keywordtype}{void}\ *val)}
\DoxyCodeLine{00556\ \{}
\DoxyCodeLine{00557\ \ \ \ \ uint32\ hash;}
\DoxyCodeLine{00558\ \ \ \ \ \textcolor{keywordtype}{char}\ *str;}
\DoxyCodeLine{00559\ }
\DoxyCodeLine{00560\ \ \ \ \ str\ =\ makekey((uint8\ *)\ key,\ len,\ NULL);}
\DoxyCodeLine{00561\ \ \ \ \ hash\ =\ key2hash(h,\ str);}
\DoxyCodeLine{00562\ \ \ \ \ ckd\_free(str);}
\DoxyCodeLine{00563\ }
\DoxyCodeLine{00564\ \ \ \ \ \textcolor{keywordflow}{return}\ (enter(h,\ hash,\ key,\ len,\ val,\ 1));}
\DoxyCodeLine{00565\ \}}
\DoxyCodeLine{00566\ }
\DoxyCodeLine{00567\ \textcolor{keywordtype}{void}\ *}
\DoxyCodeLine{00568\ hash\_table\_delete\_bkey(hash\_table\_t\ *\ h,\ \textcolor{keyword}{const}\ \textcolor{keywordtype}{char}\ *key,\ \textcolor{keywordtype}{size\_t}\ len)}
\DoxyCodeLine{00569\ \{}
\DoxyCodeLine{00570\ \ \ \ \ uint32\ hash;}
\DoxyCodeLine{00571\ \ \ \ \ \textcolor{keywordtype}{char}\ *str;}
\DoxyCodeLine{00572\ }
\DoxyCodeLine{00573\ \ \ \ \ str\ =\ makekey((uint8\ *)\ key,\ len,\ NULL);}
\DoxyCodeLine{00574\ \ \ \ \ hash\ =\ key2hash(h,\ str);}
\DoxyCodeLine{00575\ \ \ \ \ ckd\_free(str);}
\DoxyCodeLine{00576\ }
\DoxyCodeLine{00577\ \ \ \ \ \textcolor{keywordflow}{return}\ (\textcolor{keyword}{delete}(h,\ hash,\ key,\ len));}
\DoxyCodeLine{00578\ \}}
\DoxyCodeLine{00579\ }
\DoxyCodeLine{00580\ \textcolor{keywordtype}{void}}
\DoxyCodeLine{00581\ hash\_table\_display(hash\_table\_t\ *\ h,\ int32\ showdisplay)}
\DoxyCodeLine{00582\ \{}
\DoxyCodeLine{00583\ \ \ \ \ hash\_entry\_t\ *e;}
\DoxyCodeLine{00584\ \ \ \ \ \textcolor{keywordtype}{int}\ i,\ j;}
\DoxyCodeLine{00585\ \ \ \ \ j\ =\ 0;}
\DoxyCodeLine{00586\ }
\DoxyCodeLine{00587\ \ \ \ \ E\_INFOCONT(\textcolor{stringliteral}{"{}Hash\ with\ chaining\ representation\ of\ the\ hash\ table\(\backslash\)n"{}});}
\DoxyCodeLine{00588\ }
\DoxyCodeLine{00589\ \ \ \ \ \textcolor{keywordflow}{for}\ (i\ =\ 0;\ i\ <\ h-\/>size;\ i++)\ \{}
\DoxyCodeLine{00590\ \ \ \ \ \ \ \ \ e\ =\ \&(h-\/>table[i]);}
\DoxyCodeLine{00591\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (e-\/>key\ !=\ NULL)\ \{}
\DoxyCodeLine{00592\ \ \ \ \ \ \ \ \ \ \ \ \ E\_INFOCONT(\textcolor{stringliteral}{"{}|key:"{}});}
\DoxyCodeLine{00593\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (showdisplay)}
\DoxyCodeLine{00594\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ E\_INFOCONT(\textcolor{stringliteral}{"{}\%s"{}},\ e-\/>key);}
\DoxyCodeLine{00595\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{else}}
\DoxyCodeLine{00596\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ E\_INFOCONT(\textcolor{stringliteral}{"{}\%p"{}},\ e-\/>key);}
\DoxyCodeLine{00597\ }
\DoxyCodeLine{00598\ \ \ \ \ \ \ \ \ \ \ \ \ E\_INFOCONT(\textcolor{stringliteral}{"{}|len:\%d|val=\%ld|-\/>"{}},\ e-\/>len,\ (\textcolor{keywordtype}{long})e-\/>val);}
\DoxyCodeLine{00599\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (e-\/>next\ ==\ NULL)\ \{}
\DoxyCodeLine{00600\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ E\_INFOCONT(\textcolor{stringliteral}{"{}NULL\(\backslash\)n"{}});}
\DoxyCodeLine{00601\ \ \ \ \ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00602\ \ \ \ \ \ \ \ \ \ \ \ \ j++;}
\DoxyCodeLine{00603\ }
\DoxyCodeLine{00604\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{for}\ (e\ =\ e-\/>next;\ e;\ e\ =\ e-\/>next)\ \{}
\DoxyCodeLine{00605\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ E\_INFOCONT(\textcolor{stringliteral}{"{}|key:"{}});}
\DoxyCodeLine{00606\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (showdisplay)}
\DoxyCodeLine{00607\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ E\_INFOCONT(\textcolor{stringliteral}{"{}\%s"{}},\ e-\/>key);}
\DoxyCodeLine{00608\ }
\DoxyCodeLine{00609\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ E\_INFOCONT(\textcolor{stringliteral}{"{}|len:\%d|val=\%ld|-\/>"{}},\ e-\/>len,\ (\textcolor{keywordtype}{long})e-\/>val);}
\DoxyCodeLine{00610\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (e-\/>next\ ==\ NULL)\ \{}
\DoxyCodeLine{00611\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ E\_INFOCONT(\textcolor{stringliteral}{"{}NULL\(\backslash\)n"{}});}
\DoxyCodeLine{00612\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00613\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ j++;}
\DoxyCodeLine{00614\ \ \ \ \ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00615\ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00616\ \ \ \ \ \}}
\DoxyCodeLine{00617\ }
\DoxyCodeLine{00618\ \ \ \ \ E\_INFOCONT(\textcolor{stringliteral}{"{}The\ total\ number\ of\ keys\ =\%d\(\backslash\)n"{}},\ j);}
\DoxyCodeLine{00619\ \}}
\DoxyCodeLine{00620\ }
\DoxyCodeLine{00621\ }
\DoxyCodeLine{00622\ glist\_t}
\DoxyCodeLine{00623\ hash\_table\_tolist(hash\_table\_t\ *\ h,\ int32\ *\ count)}
\DoxyCodeLine{00624\ \{}
\DoxyCodeLine{00625\ \ \ \ \ glist\_t\ g;}
\DoxyCodeLine{00626\ \ \ \ \ hash\_entry\_t\ *e;}
\DoxyCodeLine{00627\ \ \ \ \ int32\ i,\ j;}
\DoxyCodeLine{00628\ }
\DoxyCodeLine{00629\ \ \ \ \ g\ =\ NULL;}
\DoxyCodeLine{00630\ }
\DoxyCodeLine{00631\ \ \ \ \ j\ =\ 0;}
\DoxyCodeLine{00632\ \ \ \ \ \textcolor{keywordflow}{for}\ (i\ =\ 0;\ i\ <\ h-\/>size;\ i++)\ \{}
\DoxyCodeLine{00633\ \ \ \ \ \ \ \ \ e\ =\ \&(h-\/>table[i]);}
\DoxyCodeLine{00634\ }
\DoxyCodeLine{00635\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (e-\/>key\ !=\ NULL)\ \{}
\DoxyCodeLine{00636\ \ \ \ \ \ \ \ \ \ \ \ \ g\ =\ glist\_add\_ptr(g,\ (\textcolor{keywordtype}{void}\ *)\ e);}
\DoxyCodeLine{00637\ \ \ \ \ \ \ \ \ \ \ \ \ j++;}
\DoxyCodeLine{00638\ }
\DoxyCodeLine{00639\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{for}\ (e\ =\ e-\/>next;\ e;\ e\ =\ e-\/>next)\ \{}
\DoxyCodeLine{00640\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ g\ =\ glist\_add\_ptr(g,\ (\textcolor{keywordtype}{void}\ *)\ e);}
\DoxyCodeLine{00641\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ j++;}
\DoxyCodeLine{00642\ \ \ \ \ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00643\ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00644\ \ \ \ \ \}}
\DoxyCodeLine{00645\ }
\DoxyCodeLine{00646\ \ \ \ \ \textcolor{keywordflow}{if}\ (count)}
\DoxyCodeLine{00647\ \ \ \ \ \ \ \ \ *count\ =\ j;}
\DoxyCodeLine{00648\ }
\DoxyCodeLine{00649\ \ \ \ \ \textcolor{keywordflow}{return}\ g;}
\DoxyCodeLine{00650\ \}}
\DoxyCodeLine{00651\ }
\DoxyCodeLine{00652\ hash\_iter\_t\ *}
\DoxyCodeLine{00653\ hash\_table\_iter(hash\_table\_t\ *h)}
\DoxyCodeLine{00654\ \{}
\DoxyCodeLine{00655\ \ \ \ \ \ \ \ \ hash\_iter\_t\ *itor;}
\DoxyCodeLine{00656\ }
\DoxyCodeLine{00657\ \ \ \ \ \ \ \ \ itor\ =\ ckd\_calloc(1,\ \textcolor{keyword}{sizeof}(*itor));}
\DoxyCodeLine{00658\ \ \ \ \ \ \ \ \ itor-\/>ht\ =\ h;}
\DoxyCodeLine{00659\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ hash\_table\_iter\_next(itor);}
\DoxyCodeLine{00660\ \}}
\DoxyCodeLine{00661\ }
\DoxyCodeLine{00662\ hash\_iter\_t\ *}
\DoxyCodeLine{00663\ hash\_table\_iter\_next(hash\_iter\_t\ *itor)}
\DoxyCodeLine{00664\ \{}
\DoxyCodeLine{00665\ \ \ \ \ \ \ \ \ \textcolor{comment}{/*\ If\ there\ is\ an\ entry,\ walk\ down\ its\ list.\ */}}
\DoxyCodeLine{00666\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (itor-\/>ent)}
\DoxyCodeLine{00667\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ itor-\/>ent\ =\ itor-\/>ent-\/>next;}
\DoxyCodeLine{00668\ \ \ \ \ \ \ \ \ \textcolor{comment}{/*\ If\ we\ got\ to\ the\ end\ of\ the\ chain,\ or\ we\ had\ no\ entry,\ scan}}
\DoxyCodeLine{00669\ \textcolor{comment}{\ \ \ \ \ \ \ \ \ *\ forward\ in\ the\ table\ to\ find\ the\ next\ non-\/empty\ bucket.\ */}}
\DoxyCodeLine{00670\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (itor-\/>ent\ ==\ NULL)\ \{}
\DoxyCodeLine{00671\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{while}\ (itor-\/>idx\ <\ itor-\/>ht-\/>size}
\DoxyCodeLine{00672\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \&\&\ itor-\/>ht-\/>table[itor-\/>idx].key\ ==\ NULL)\ }
\DoxyCodeLine{00673\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ ++itor-\/>idx;}
\DoxyCodeLine{00674\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{comment}{/*\ If\ we\ did\ not\ find\ one\ then\ delete\ the\ iterator\ and}}
\DoxyCodeLine{00675\ \textcolor{comment}{\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ *\ return\ NULL.\ */}}
\DoxyCodeLine{00676\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (itor-\/>idx\ ==\ itor-\/>ht-\/>size)\ \{}
\DoxyCodeLine{00677\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ hash\_table\_iter\_free(itor);}
\DoxyCodeLine{00678\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ NULL;}
\DoxyCodeLine{00679\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00680\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{comment}{/*\ Otherwise\ use\ this\ next\ entry.\ */}}
\DoxyCodeLine{00681\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ itor-\/>ent\ =\ itor-\/>ht-\/>table\ +\ itor-\/>idx;}
\DoxyCodeLine{00682\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{comment}{/*\ Increase\ idx\ for\ the\ next\ time\ around.\ */}}
\DoxyCodeLine{00683\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ ++itor-\/>idx;}
\DoxyCodeLine{00684\ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00685\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ itor;}
\DoxyCodeLine{00686\ \}}
\DoxyCodeLine{00687\ }
\DoxyCodeLine{00688\ \textcolor{keywordtype}{void}}
\DoxyCodeLine{00689\ hash\_table\_iter\_free(hash\_iter\_t\ *itor)}
\DoxyCodeLine{00690\ \{}
\DoxyCodeLine{00691\ \ \ \ \ \ \ \ \ ckd\_free(itor);}
\DoxyCodeLine{00692\ \}}
\DoxyCodeLine{00693\ }
\DoxyCodeLine{00694\ \textcolor{keywordtype}{void}}
\DoxyCodeLine{00695\ hash\_table\_free(hash\_table\_t\ *\ h)}
\DoxyCodeLine{00696\ \{}
\DoxyCodeLine{00697\ \ \ \ \ hash\_entry\_t\ *e,\ *e2;}
\DoxyCodeLine{00698\ \ \ \ \ int32\ i;}
\DoxyCodeLine{00699\ }
\DoxyCodeLine{00700\ \ \ \ \ \textcolor{keywordflow}{if}\ (h\ ==\ NULL)}
\DoxyCodeLine{00701\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return};}
\DoxyCodeLine{00702\ }
\DoxyCodeLine{00703\ \ \ \ \ \textcolor{comment}{/*\ Free\ additional\ entries\ created\ for\ key\ collision\ cases\ */}}
\DoxyCodeLine{00704\ \ \ \ \ \textcolor{keywordflow}{for}\ (i\ =\ 0;\ i\ <\ h-\/>size;\ i++)\ \{}
\DoxyCodeLine{00705\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{for}\ (e\ =\ h-\/>table[i].next;\ e;\ e\ =\ e2)\ \{}
\DoxyCodeLine{00706\ \ \ \ \ \ \ \ \ \ \ \ \ e2\ =\ e-\/>next;}
\DoxyCodeLine{00707\ \ \ \ \ \ \ \ \ \ \ \ \ ckd\_free((\textcolor{keywordtype}{void}\ *)\ e);}
\DoxyCodeLine{00708\ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00709\ \ \ \ \ \}}
\DoxyCodeLine{00710\ }
\DoxyCodeLine{00711\ \ \ \ \ ckd\_free((\textcolor{keywordtype}{void}\ *)\ h-\/>table);}
\DoxyCodeLine{00712\ \ \ \ \ ckd\_free((\textcolor{keywordtype}{void}\ *)\ h);}
\DoxyCodeLine{00713\ \}}

\end{DoxyCode}
