\doxysection{include/osmocom/core/hashtable.h File Reference}
\label{hashtable_8h}\index{include/osmocom/core/hashtable.h@{include/osmocom/core/hashtable.h}}
{\ttfamily \#include $<$osmocom/core/linuxlist.\+h$>$}\newline
{\ttfamily \#include $<$osmocom/core/hash.\+h$>$}\newline
\doxysubsection*{Macros}
\begin{DoxyCompactItemize}
\item 
\#define \textbf{ DEFINE\+\_\+\+HASHTABLE}(\textbf{ name},  bits)
\item 
\#define \textbf{ DECLARE\+\_\+\+HASHTABLE}(\textbf{ name},  bits)~ struct \textbf{ hlist\+\_\+head} \textbf{ name}[1 $<$$<$ (bits)]
\item 
\#define \textbf{ HASH\+\_\+\+SIZE}(\textbf{ name})~(\textbf{ ARRAY\+\_\+\+SIZE}(\textbf{ name}))
\item 
\#define \textbf{ HASH\+\_\+\+BITS}(\textbf{ name})~\textbf{ ilog2}(\textbf{ HASH\+\_\+\+SIZE}(\textbf{ name}))
\item 
\#define \textbf{ hash\+\_\+min}(val,  bits)~ (sizeof(val) $<$= 4 ? \textbf{ hash\+\_\+32}(val, bits) \+: \textbf{ hash\+\_\+long}(val, bits))
\item 
\#define \textbf{ hash\+\_\+init}(hashtable)~\textbf{ \+\_\+\+\_\+hash\+\_\+init}(hashtable, \textbf{ HASH\+\_\+\+SIZE}(hashtable))
\begin{DoxyCompactList}\small\item\em hash\+\_\+init -\/ initialize a hash table @hashtable\+: hashtable to be initialized \end{DoxyCompactList}\item 
\#define \textbf{ hash\+\_\+add}(hashtable,  \textbf{ node},  key)~ \textbf{ hlist\+\_\+add\+\_\+head}(\textbf{ node}, \&hashtable[\textbf{ hash\+\_\+min}(key, \textbf{ HASH\+\_\+\+BITS}(hashtable))])
\begin{DoxyCompactList}\small\item\em hash\+\_\+add -\/ add an object to a hashtable @hashtable\+: hashtable to add to @node\+: the \&struct \doxyref{hlist\+\_\+node}{p.}{structhlist__node} of the object to be added @key\+: the key of the object to be added \end{DoxyCompactList}\item 
\#define \textbf{ hash\+\_\+empty}(hashtable)~\textbf{ \+\_\+\+\_\+hash\+\_\+empty}(hashtable, \textbf{ HASH\+\_\+\+SIZE}(hashtable))
\begin{DoxyCompactList}\small\item\em hash\+\_\+empty -\/ check whether a hashtable is empty @hashtable\+: hashtable to check \end{DoxyCompactList}\end{DoxyCompactItemize}
\begin{Indent}\textbf{ \+: hashtable to iterate}\par
{\em hash\+\_\+for\+\_\+each\+\_\+possible\+\_\+safe -\/ iterate over all possible objects hashing to the same bucket safe against removals

@obj\+: the type $\ast$ to use as a loop cursor for each entry @tmp\+: a \&struct \doxyref{hlist\+\_\+node}{p.}{structhlist__node} used for temporary storage @member\+: the name of the \doxyref{hlist\+\_\+node}{p.}{structhlist__node} within the struct @key\+: the key of the objects to iterate over }\begin{DoxyCompactItemize}
\item 
\#define \textbf{ hash\+\_\+for\+\_\+each}(\textbf{ name},  bkt,  obj,  member)
\item 
\#define \textbf{ hash\+\_\+for\+\_\+each\+\_\+safe}(\textbf{ name},  bkt,  tmp,  obj,  member)
\item 
\#define \textbf{ hash\+\_\+for\+\_\+each\+\_\+possible}(\textbf{ name},  obj,  member,  key)~ \textbf{ hlist\+\_\+for\+\_\+each\+\_\+entry}(obj, \&\textbf{ name}[\textbf{ hash\+\_\+min}(key, \textbf{ HASH\+\_\+\+BITS}(\textbf{ name}))], member)
\item 
\#define \textbf{ hash\+\_\+for\+\_\+each\+\_\+possible\+\_\+safe}(\textbf{ name},  obj,  tmp,  member,  key)
\end{DoxyCompactItemize}
\end{Indent}
\doxysubsection*{Functions}
\begin{DoxyCompactItemize}
\item 
static void \textbf{ \+\_\+\+\_\+hash\+\_\+init} (struct \textbf{ hlist\+\_\+head} $\ast$ht, unsigned int sz)
\item 
static bool \textbf{ hash\+\_\+hashed} (struct \textbf{ hlist\+\_\+node} $\ast$\textbf{ node})
\begin{DoxyCompactList}\small\item\em hash\+\_\+hashed -\/ check whether an object is in any hashtable @node\+: the \&struct \doxyref{hlist\+\_\+node}{p.}{structhlist__node} of the object to be checked \end{DoxyCompactList}\item 
static bool \textbf{ \+\_\+\+\_\+hash\+\_\+empty} (struct \textbf{ hlist\+\_\+head} $\ast$ht, unsigned int sz)
\item 
static void \textbf{ hash\+\_\+del} (struct \textbf{ hlist\+\_\+node} $\ast$\textbf{ node})
\begin{DoxyCompactList}\small\item\em hash\+\_\+del -\/ remove an object from a hashtable @node\+: \&struct \doxyref{hlist\+\_\+node}{p.}{structhlist__node} of the object to remove \end{DoxyCompactList}\end{DoxyCompactItemize}


\doxysubsection{Macro Definition Documentation}
\mbox{\label{hashtable_8h_aea57b868a0088ac159518f6be812569e}} 
\index{hashtable.h@{hashtable.h}!DECLARE\_HASHTABLE@{DECLARE\_HASHTABLE}}
\index{DECLARE\_HASHTABLE@{DECLARE\_HASHTABLE}!hashtable.h@{hashtable.h}}
\doxysubsubsection{DECLARE\_HASHTABLE}
{\footnotesize\ttfamily \#define DECLARE\+\_\+\+HASHTABLE(\begin{DoxyParamCaption}\item[{}]{\textbf{ name},  }\item[{}]{bits }\end{DoxyParamCaption})~ struct \textbf{ hlist\+\_\+head} \textbf{ name}[1 $<$$<$ (bits)]}

\mbox{\label{hashtable_8h_a43705d0172283e68e89a74f155486058}} 
\index{hashtable.h@{hashtable.h}!DEFINE\_HASHTABLE@{DEFINE\_HASHTABLE}}
\index{DEFINE\_HASHTABLE@{DEFINE\_HASHTABLE}!hashtable.h@{hashtable.h}}
\doxysubsubsection{DEFINE\_HASHTABLE}
{\footnotesize\ttfamily \#define DEFINE\+\_\+\+HASHTABLE(\begin{DoxyParamCaption}\item[{}]{\textbf{ name},  }\item[{}]{bits }\end{DoxyParamCaption})}

{\bfseries Value\+:}
\begin{DoxyCode}{0}
\DoxyCodeLine{        \textcolor{keyword}{struct }hlist\_head name[1 << (bits)] =                                     \(\backslash\)}
\DoxyCodeLine{                        \{ [0 ... ((1 << (bits)) -\/ 1)] = HLIST\_HEAD\_INIT \}}

\end{DoxyCode}
\mbox{\label{hashtable_8h_afbc4fbecc911ebb341099133827dc804}} 
\index{hashtable.h@{hashtable.h}!hash\_add@{hash\_add}}
\index{hash\_add@{hash\_add}!hashtable.h@{hashtable.h}}
\doxysubsubsection{hash\_add}
{\footnotesize\ttfamily \#define hash\+\_\+add(\begin{DoxyParamCaption}\item[{}]{hashtable,  }\item[{}]{\textbf{ node},  }\item[{}]{key }\end{DoxyParamCaption})~ \textbf{ hlist\+\_\+add\+\_\+head}(\textbf{ node}, \&hashtable[\textbf{ hash\+\_\+min}(key, \textbf{ HASH\+\_\+\+BITS}(hashtable))])}



hash\+\_\+add -\/ add an object to a hashtable @hashtable\+: hashtable to add to @node\+: the \&struct \doxyref{hlist\+\_\+node}{p.}{structhlist__node} of the object to be added @key\+: the key of the object to be added 

\mbox{\label{hashtable_8h_a685993f49fd05df2e53c9e3b0def928f}} 
\index{hashtable.h@{hashtable.h}!HASH\_BITS@{HASH\_BITS}}
\index{HASH\_BITS@{HASH\_BITS}!hashtable.h@{hashtable.h}}
\doxysubsubsection{HASH\_BITS}
{\footnotesize\ttfamily \#define HASH\+\_\+\+BITS(\begin{DoxyParamCaption}\item[{}]{\textbf{ name} }\end{DoxyParamCaption})~\textbf{ ilog2}(\textbf{ HASH\+\_\+\+SIZE}(\textbf{ name}))}

\mbox{\label{hashtable_8h_a255106554d807b733a38195cfcf11279}} 
\index{hashtable.h@{hashtable.h}!hash\_empty@{hash\_empty}}
\index{hash\_empty@{hash\_empty}!hashtable.h@{hashtable.h}}
\doxysubsubsection{hash\_empty}
{\footnotesize\ttfamily \#define hash\+\_\+empty(\begin{DoxyParamCaption}\item[{}]{hashtable }\end{DoxyParamCaption})~\textbf{ \+\_\+\+\_\+hash\+\_\+empty}(hashtable, \textbf{ HASH\+\_\+\+SIZE}(hashtable))}



hash\+\_\+empty -\/ check whether a hashtable is empty @hashtable\+: hashtable to check 

This has to be a macro since \doxyref{HASH\+\_\+\+BITS()}{p.}{hashtable_8h_a685993f49fd05df2e53c9e3b0def928f} will not work on pointers since it calculates the size during preprocessing. \mbox{\label{hashtable_8h_a3546403fdb77a5ebb8a48863776f8bfd}} 
\index{hashtable.h@{hashtable.h}!hash\_for\_each@{hash\_for\_each}}
\index{hash\_for\_each@{hash\_for\_each}!hashtable.h@{hashtable.h}}
\doxysubsubsection{hash\_for\_each}
{\footnotesize\ttfamily \#define hash\+\_\+for\+\_\+each(\begin{DoxyParamCaption}\item[{}]{\textbf{ name},  }\item[{}]{bkt,  }\item[{}]{obj,  }\item[{}]{member }\end{DoxyParamCaption})}

{\bfseries Value\+:}
\begin{DoxyCode}{0}
\DoxyCodeLine{        \textcolor{keywordflow}{for} ((bkt) = 0, obj = NULL; obj == NULL \&\& (bkt) < HASH\_SIZE(name);\(\backslash\)}
\DoxyCodeLine{                        (bkt)++)\(\backslash\)}
\DoxyCodeLine{                hlist\_for\_each\_entry(obj, \&name[bkt], member)}

\end{DoxyCode}
\mbox{\label{hashtable_8h_a35414f669cf86a08128f5dc7f81f4164}} 
\index{hashtable.h@{hashtable.h}!hash\_for\_each\_possible@{hash\_for\_each\_possible}}
\index{hash\_for\_each\_possible@{hash\_for\_each\_possible}!hashtable.h@{hashtable.h}}
\doxysubsubsection{hash\_for\_each\_possible}
{\footnotesize\ttfamily \#define hash\+\_\+for\+\_\+each\+\_\+possible(\begin{DoxyParamCaption}\item[{}]{\textbf{ name},  }\item[{}]{obj,  }\item[{}]{member,  }\item[{}]{key }\end{DoxyParamCaption})~ \textbf{ hlist\+\_\+for\+\_\+each\+\_\+entry}(obj, \&\textbf{ name}[\textbf{ hash\+\_\+min}(key, \textbf{ HASH\+\_\+\+BITS}(\textbf{ name}))], member)}

\mbox{\label{hashtable_8h_a8c4248acd9c1bbf9bfea0f5ca549d317}} 
\index{hashtable.h@{hashtable.h}!hash\_for\_each\_possible\_safe@{hash\_for\_each\_possible\_safe}}
\index{hash\_for\_each\_possible\_safe@{hash\_for\_each\_possible\_safe}!hashtable.h@{hashtable.h}}
\doxysubsubsection{hash\_for\_each\_possible\_safe}
{\footnotesize\ttfamily \#define hash\+\_\+for\+\_\+each\+\_\+possible\+\_\+safe(\begin{DoxyParamCaption}\item[{}]{\textbf{ name},  }\item[{}]{obj,  }\item[{}]{tmp,  }\item[{}]{member,  }\item[{}]{key }\end{DoxyParamCaption})}

{\bfseries Value\+:}
\begin{DoxyCode}{0}
\DoxyCodeLine{        hlist\_for\_each\_entry\_safe(obj, tmp,\(\backslash\)}
\DoxyCodeLine{                \&name[hash\_min(key, HASH\_BITS(name))], member)}

\end{DoxyCode}
\mbox{\label{hashtable_8h_a5cc3f5cd60a35100c9c4b1486553e4f5}} 
\index{hashtable.h@{hashtable.h}!hash\_for\_each\_safe@{hash\_for\_each\_safe}}
\index{hash\_for\_each\_safe@{hash\_for\_each\_safe}!hashtable.h@{hashtable.h}}
\doxysubsubsection{hash\_for\_each\_safe}
{\footnotesize\ttfamily \#define hash\+\_\+for\+\_\+each\+\_\+safe(\begin{DoxyParamCaption}\item[{}]{\textbf{ name},  }\item[{}]{bkt,  }\item[{}]{tmp,  }\item[{}]{obj,  }\item[{}]{member }\end{DoxyParamCaption})}

{\bfseries Value\+:}
\begin{DoxyCode}{0}
\DoxyCodeLine{        \textcolor{keywordflow}{for} ((bkt) = 0, obj = NULL; obj == NULL \&\& (bkt) < HASH\_SIZE(name);\(\backslash\)}
\DoxyCodeLine{                        (bkt)++)\(\backslash\)}
\DoxyCodeLine{                hlist\_for\_each\_entry\_safe(obj, tmp, \&name[bkt], member)}

\end{DoxyCode}
\mbox{\label{hashtable_8h_aae9c1a12353e78fee6002a93ac29fbda}} 
\index{hashtable.h@{hashtable.h}!hash\_init@{hash\_init}}
\index{hash\_init@{hash\_init}!hashtable.h@{hashtable.h}}
\doxysubsubsection{hash\_init}
{\footnotesize\ttfamily \#define hash\+\_\+init(\begin{DoxyParamCaption}\item[{}]{hashtable }\end{DoxyParamCaption})~\textbf{ \+\_\+\+\_\+hash\+\_\+init}(hashtable, \textbf{ HASH\+\_\+\+SIZE}(hashtable))}



hash\+\_\+init -\/ initialize a hash table @hashtable\+: hashtable to be initialized 

Calculates the size of the hashtable from the given parameter, otherwise same as hash\+\_\+init\+\_\+size.

This has to be a macro since \doxyref{HASH\+\_\+\+BITS()}{p.}{hashtable_8h_a685993f49fd05df2e53c9e3b0def928f} will not work on pointers since it calculates the size during preprocessing. \mbox{\label{hashtable_8h_a563b466ae0807988b2c78686ebe6fc68}} 
\index{hashtable.h@{hashtable.h}!hash\_min@{hash\_min}}
\index{hash\_min@{hash\_min}!hashtable.h@{hashtable.h}}
\doxysubsubsection{hash\_min}
{\footnotesize\ttfamily \#define hash\+\_\+min(\begin{DoxyParamCaption}\item[{}]{val,  }\item[{}]{bits }\end{DoxyParamCaption})~ (sizeof(val) $<$= 4 ? \textbf{ hash\+\_\+32}(val, bits) \+: \textbf{ hash\+\_\+long}(val, bits))}

\mbox{\label{hashtable_8h_ad1ce2da85d284fbc14e9192b36ff4e9f}} 
\index{hashtable.h@{hashtable.h}!HASH\_SIZE@{HASH\_SIZE}}
\index{HASH\_SIZE@{HASH\_SIZE}!hashtable.h@{hashtable.h}}
\doxysubsubsection{HASH\_SIZE}
{\footnotesize\ttfamily \#define HASH\+\_\+\+SIZE(\begin{DoxyParamCaption}\item[{}]{\textbf{ name} }\end{DoxyParamCaption})~(\textbf{ ARRAY\+\_\+\+SIZE}(\textbf{ name}))}



\doxysubsection{Function Documentation}
\mbox{\label{hashtable_8h_a34ed811be03f9bba1826a86dee49fbeb}} 
\index{hashtable.h@{hashtable.h}!\_\_hash\_empty@{\_\_hash\_empty}}
\index{\_\_hash\_empty@{\_\_hash\_empty}!hashtable.h@{hashtable.h}}
\doxysubsubsection{\_\_hash\_empty()}
{\footnotesize\ttfamily static bool \+\_\+\+\_\+hash\+\_\+empty (\begin{DoxyParamCaption}\item[{struct \textbf{ hlist\+\_\+head} $\ast$}]{ht,  }\item[{unsigned int}]{sz }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [inline]}, {\ttfamily [static]}}



References \textbf{ hlist\+\_\+empty()}.

\mbox{\label{hashtable_8h_af206b6fc1e929ea73928c3e209ab567c}} 
\index{hashtable.h@{hashtable.h}!\_\_hash\_init@{\_\_hash\_init}}
\index{\_\_hash\_init@{\_\_hash\_init}!hashtable.h@{hashtable.h}}
\doxysubsubsection{\_\_hash\_init()}
{\footnotesize\ttfamily static void \+\_\+\+\_\+hash\+\_\+init (\begin{DoxyParamCaption}\item[{struct \textbf{ hlist\+\_\+head} $\ast$}]{ht,  }\item[{unsigned int}]{sz }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [inline]}, {\ttfamily [static]}}



References \textbf{ INIT\+\_\+\+HLIST\+\_\+\+HEAD}.

\mbox{\label{hashtable_8h_a2a182ec8baf498309485cec53ab687b9}} 
\index{hashtable.h@{hashtable.h}!hash\_del@{hash\_del}}
\index{hash\_del@{hash\_del}!hashtable.h@{hashtable.h}}
\doxysubsubsection{hash\_del()}
{\footnotesize\ttfamily static void hash\+\_\+del (\begin{DoxyParamCaption}\item[{struct \textbf{ hlist\+\_\+node} $\ast$}]{node }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [inline]}, {\ttfamily [static]}}



hash\+\_\+del -\/ remove an object from a hashtable @node\+: \&struct \doxyref{hlist\+\_\+node}{p.}{structhlist__node} of the object to remove 



References \textbf{ hlist\+\_\+del\+\_\+init()}, and \textbf{ node}.

\mbox{\label{hashtable_8h_a4be7b340dad5a56e5d255815445bd9a7}} 
\index{hashtable.h@{hashtable.h}!hash\_hashed@{hash\_hashed}}
\index{hash\_hashed@{hash\_hashed}!hashtable.h@{hashtable.h}}
\doxysubsubsection{hash\_hashed()}
{\footnotesize\ttfamily static bool hash\+\_\+hashed (\begin{DoxyParamCaption}\item[{struct \textbf{ hlist\+\_\+node} $\ast$}]{node }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [inline]}, {\ttfamily [static]}}



hash\+\_\+hashed -\/ check whether an object is in any hashtable @node\+: the \&struct \doxyref{hlist\+\_\+node}{p.}{structhlist__node} of the object to be checked 



References \textbf{ hlist\+\_\+unhashed()}, and \textbf{ node}.

