\doxysection{include/sphinxbase/bitvec.h File Reference}
\label{bitvec_8h}\index{include/sphinxbase/bitvec.h@{include/sphinxbase/bitvec.h}}


An implementation of bit vectors.  


{\ttfamily \#include $<$string.\+h$>$}\newline
{\ttfamily \#include $<$sphinxbase/sphinxbase\+\_\+export.\+h$>$}\newline
{\ttfamily \#include $<$sphinxbase/prim\+\_\+type.\+h$>$}\newline
{\ttfamily \#include $<$sphinxbase/ckd\+\_\+alloc.\+h$>$}\newline
\doxysubsubsection*{Macros}
\begin{DoxyCompactItemize}
\item 
\#define \textbf{ BITVEC\+\_\+\+BITS}~32
\item 
\#define \textbf{ bitvec\+\_\+size}(n)~(((n)+BITVEC\+\_\+\+BITS-\/1)/BITVEC\+\_\+\+BITS)
\begin{DoxyCompactList}\small\item\em Number of bitvec\+\_\+t in a bit vector. \end{DoxyCompactList}\item 
\#define \textbf{ bitvec\+\_\+alloc}(n)~\textbf{ ckd\+\_\+calloc}(\textbf{ bitvec\+\_\+size}(n), sizeof(bitvec\+\_\+t))
\begin{DoxyCompactList}\small\item\em Allocate a bit vector, all bits are clear. \end{DoxyCompactList}\item 
\#define \textbf{ bitvec\+\_\+free}(v)~\textbf{ ckd\+\_\+free}(v)
\begin{DoxyCompactList}\small\item\em Free a bit vector. \end{DoxyCompactList}\item 
\#define \textbf{ bitvec\+\_\+set}(v,  b)~(v[(b)/BITVEC\+\_\+\+BITS] $\vert$= (1UL $<$$<$ ((b) \& (BITVEC\+\_\+\+BITS-\/1))))
\begin{DoxyCompactList}\small\item\em Set the b-\/th bit of bit vector v. \end{DoxyCompactList}\item 
\#define \textbf{ bitvec\+\_\+set\+\_\+all}(v,  n)
\begin{DoxyCompactList}\small\item\em Set all n bits in bit vector v. \end{DoxyCompactList}\item 
\#define \textbf{ bitvec\+\_\+clear}(v,  b)~(v[(b)/BITVEC\+\_\+\+BITS] \&= $\sim$(1UL $<$$<$ ((b) \& (BITVEC\+\_\+\+BITS-\/1))))
\begin{DoxyCompactList}\small\item\em Clear the b-\/th bit of bit vector v. \end{DoxyCompactList}\item 
\#define \textbf{ bitvec\+\_\+clear\+\_\+all}(v,  n)
\begin{DoxyCompactList}\small\item\em Clear all n bits in bit vector v. \end{DoxyCompactList}\item 
\#define \textbf{ bitvec\+\_\+is\+\_\+set}(v,  b)~(v[(b)/BITVEC\+\_\+\+BITS] \& (1UL $<$$<$ ((b) \& (BITVEC\+\_\+\+BITS-\/1))))
\begin{DoxyCompactList}\small\item\em Check whether the b-\/th bit is set in vector v. \end{DoxyCompactList}\item 
\#define \textbf{ bitvec\+\_\+is\+\_\+clear}(v,  b)~(! (\textbf{ bitvec\+\_\+is\+\_\+set}(v,b)))
\begin{DoxyCompactList}\small\item\em Check whether the b-\/th bit is cleared in vector v. \end{DoxyCompactList}\end{DoxyCompactItemize}
\doxysubsubsection*{Typedefs}
\begin{DoxyCompactItemize}
\item 
typedef uint32 \textbf{ bitvec\+\_\+t}
\end{DoxyCompactItemize}
\doxysubsubsection*{Functions}
\begin{DoxyCompactItemize}
\item 
SPHINXBASE\+\_\+\+EXPORT bitvec\+\_\+t $\ast$ \textbf{ bitvec\+\_\+realloc} (bitvec\+\_\+t $\ast$vec, size\+\_\+t old\+\_\+len, size\+\_\+t new\+\_\+len)
\begin{DoxyCompactList}\small\item\em Resize a bit vector, clear the remaining bits. \end{DoxyCompactList}\item 
SPHINXBASE\+\_\+\+EXPORT size\+\_\+t \textbf{ bitvec\+\_\+count\+\_\+set} (bitvec\+\_\+t $\ast$vec, size\+\_\+t len)
\begin{DoxyCompactList}\small\item\em Return the number of bits set in the given bitvector. \end{DoxyCompactList}\end{DoxyCompactItemize}


\doxysubsection{Detailed Description}
An implementation of bit vectors. 

Implementation of basic operations of bit vectors. ~\newline
 

Definition in file \textbf{ bitvec.\+h}.



\doxysubsection{Macro Definition Documentation}
\label{bitvec_8h_a866043a7ac23e137f6c2f2466f4abc70} 
\index{bitvec.h@{bitvec.h}!bitvec\_alloc@{bitvec\_alloc}}
\index{bitvec\_alloc@{bitvec\_alloc}!bitvec.h@{bitvec.h}}
\doxysubsubsection{bitvec\_alloc}
{\footnotesize\ttfamily \#define bitvec\+\_\+alloc(\begin{DoxyParamCaption}\item[{}]{n }\end{DoxyParamCaption})~\textbf{ ckd\+\_\+calloc}(\textbf{ bitvec\+\_\+size}(n), sizeof(bitvec\+\_\+t))}



Allocate a bit vector, all bits are clear. 



Definition at line \textbf{ 75} of file \textbf{ bitvec.\+h}.

\label{bitvec_8h_aa992f8d4c7dbe0b71bfd1e01ce279167} 
\index{bitvec.h@{bitvec.h}!BITVEC\_BITS@{BITVEC\_BITS}}
\index{BITVEC\_BITS@{BITVEC\_BITS}!bitvec.h@{bitvec.h}}
\doxysubsubsection{BITVEC\_BITS}
{\footnotesize\ttfamily \#define BITVEC\+\_\+\+BITS~32}



Definition at line \textbf{ 64} of file \textbf{ bitvec.\+h}.

\label{bitvec_8h_a74b3387345ca2730a8067626878843fc} 
\index{bitvec.h@{bitvec.h}!bitvec\_clear@{bitvec\_clear}}
\index{bitvec\_clear@{bitvec\_clear}!bitvec.h@{bitvec.h}}
\doxysubsubsection{bitvec\_clear}
{\footnotesize\ttfamily \#define bitvec\+\_\+clear(\begin{DoxyParamCaption}\item[{}]{v,  }\item[{}]{b }\end{DoxyParamCaption})~(v[(b)/BITVEC\+\_\+\+BITS] \&= $\sim$(1UL $<$$<$ ((b) \& (BITVEC\+\_\+\+BITS-\/1))))}



Clear the b-\/th bit of bit vector v. 


\begin{DoxyParams}{Parameters}
{\em v} & is a vector \\
\hline
{\em b} & is the bit which will be set \\
\hline
\end{DoxyParams}


Definition at line \textbf{ 112} of file \textbf{ bitvec.\+h}.

\label{bitvec_8h_a89f80d7a8040e9225f3c1c9bf102ae1d} 
\index{bitvec.h@{bitvec.h}!bitvec\_clear\_all@{bitvec\_clear\_all}}
\index{bitvec\_clear\_all@{bitvec\_clear\_all}!bitvec.h@{bitvec.h}}
\doxysubsubsection{bitvec\_clear\_all}
{\footnotesize\ttfamily \#define bitvec\+\_\+clear\+\_\+all(\begin{DoxyParamCaption}\item[{}]{v,  }\item[{}]{n }\end{DoxyParamCaption})}

{\bfseries Value\+:}
\begin{DoxyCode}{0}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ memset(v,\ 0,\ (((n)+BITVEC\_BITS-\/1)/BITVEC\_BITS)\ *\ \(\backslash\)}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keyword}{sizeof}(bitvec\_t))}

\end{DoxyCode}


Clear all n bits in bit vector v. 


\begin{DoxyParams}{Parameters}
{\em v} & is a vector \\
\hline
{\em n} & is the number of bits \\
\hline
\end{DoxyParams}


Definition at line \textbf{ 120} of file \textbf{ bitvec.\+h}.

\label{bitvec_8h_a5628e35c88ac7e91b99dce916758824a} 
\index{bitvec.h@{bitvec.h}!bitvec\_free@{bitvec\_free}}
\index{bitvec\_free@{bitvec\_free}!bitvec.h@{bitvec.h}}
\doxysubsubsection{bitvec\_free}
{\footnotesize\ttfamily \#define bitvec\+\_\+free(\begin{DoxyParamCaption}\item[{}]{v }\end{DoxyParamCaption})~\textbf{ ckd\+\_\+free}(v)}



Free a bit vector. 



Definition at line \textbf{ 87} of file \textbf{ bitvec.\+h}.

\label{bitvec_8h_a8154409a6e05e7c1ed7f21eff5ed06d4} 
\index{bitvec.h@{bitvec.h}!bitvec\_is\_clear@{bitvec\_is\_clear}}
\index{bitvec\_is\_clear@{bitvec\_is\_clear}!bitvec.h@{bitvec.h}}
\doxysubsubsection{bitvec\_is\_clear}
{\footnotesize\ttfamily \#define bitvec\+\_\+is\+\_\+clear(\begin{DoxyParamCaption}\item[{}]{v,  }\item[{}]{b }\end{DoxyParamCaption})~(! (\textbf{ bitvec\+\_\+is\+\_\+set}(v,b)))}



Check whether the b-\/th bit is cleared in vector v. 


\begin{DoxyParams}{Parameters}
{\em v} & is a vector \\
\hline
{\em b} & is the bit which will be checked \\
\hline
\end{DoxyParams}


Definition at line \textbf{ 137} of file \textbf{ bitvec.\+h}.

\label{bitvec_8h_ae323f80288b2ff946d6d8b0e38f791c9} 
\index{bitvec.h@{bitvec.h}!bitvec\_is\_set@{bitvec\_is\_set}}
\index{bitvec\_is\_set@{bitvec\_is\_set}!bitvec.h@{bitvec.h}}
\doxysubsubsection{bitvec\_is\_set}
{\footnotesize\ttfamily \#define bitvec\+\_\+is\+\_\+set(\begin{DoxyParamCaption}\item[{}]{v,  }\item[{}]{b }\end{DoxyParamCaption})~(v[(b)/BITVEC\+\_\+\+BITS] \& (1UL $<$$<$ ((b) \& (BITVEC\+\_\+\+BITS-\/1))))}



Check whether the b-\/th bit is set in vector v. 


\begin{DoxyParams}{Parameters}
{\em v} & is a vector \\
\hline
{\em b} & is the bit which will be checked \\
\hline
\end{DoxyParams}


Definition at line \textbf{ 129} of file \textbf{ bitvec.\+h}.

\label{bitvec_8h_ae90878b8f2316f5733d83a3f47d378ac} 
\index{bitvec.h@{bitvec.h}!bitvec\_set@{bitvec\_set}}
\index{bitvec\_set@{bitvec\_set}!bitvec.h@{bitvec.h}}
\doxysubsubsection{bitvec\_set}
{\footnotesize\ttfamily \#define bitvec\+\_\+set(\begin{DoxyParamCaption}\item[{}]{v,  }\item[{}]{b }\end{DoxyParamCaption})~(v[(b)/BITVEC\+\_\+\+BITS] $\vert$= (1UL $<$$<$ ((b) \& (BITVEC\+\_\+\+BITS-\/1))))}



Set the b-\/th bit of bit vector v. 


\begin{DoxyParams}{Parameters}
{\em v} & is a vector \\
\hline
{\em b} & is the bit which will be set \\
\hline
\end{DoxyParams}


Definition at line \textbf{ 95} of file \textbf{ bitvec.\+h}.

\label{bitvec_8h_ab7abefb917e02790e9384d3149ff461e} 
\index{bitvec.h@{bitvec.h}!bitvec\_set\_all@{bitvec\_set\_all}}
\index{bitvec\_set\_all@{bitvec\_set\_all}!bitvec.h@{bitvec.h}}
\doxysubsubsection{bitvec\_set\_all}
{\footnotesize\ttfamily \#define bitvec\+\_\+set\+\_\+all(\begin{DoxyParamCaption}\item[{}]{v,  }\item[{}]{n }\end{DoxyParamCaption})}

{\bfseries Value\+:}
\begin{DoxyCode}{0}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ memset(v,\ (bitvec\_t)-\/1,\ \(\backslash\)}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ (((n)+BITVEC\_BITS-\/1)/BITVEC\_BITS)\ *\ \(\backslash\)}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keyword}{sizeof}(bitvec\_t))}

\end{DoxyCode}


Set all n bits in bit vector v. 


\begin{DoxyParams}{Parameters}
{\em v} & is a vector \\
\hline
{\em n} & is the number of bits \\
\hline
\end{DoxyParams}


Definition at line \textbf{ 103} of file \textbf{ bitvec.\+h}.

\label{bitvec_8h_a1d82193826583f234a71cba32267d3f3} 
\index{bitvec.h@{bitvec.h}!bitvec\_size@{bitvec\_size}}
\index{bitvec\_size@{bitvec\_size}!bitvec.h@{bitvec.h}}
\doxysubsubsection{bitvec\_size}
{\footnotesize\ttfamily \#define bitvec\+\_\+size(\begin{DoxyParamCaption}\item[{}]{n }\end{DoxyParamCaption})~(((n)+BITVEC\+\_\+\+BITS-\/1)/BITVEC\+\_\+\+BITS)}



Number of bitvec\+\_\+t in a bit vector. 



Definition at line \textbf{ 70} of file \textbf{ bitvec.\+h}.



\doxysubsection{Typedef Documentation}
\label{bitvec_8h_ade0d20aa7e2ccec4e6fcf06419251f71} 
\index{bitvec.h@{bitvec.h}!bitvec\_t@{bitvec\_t}}
\index{bitvec\_t@{bitvec\_t}!bitvec.h@{bitvec.h}}
\doxysubsubsection{bitvec\_t}
{\footnotesize\ttfamily typedef uint32 bitvec\+\_\+t}



Definition at line \textbf{ 65} of file \textbf{ bitvec.\+h}.



\doxysubsection{Function Documentation}
\label{bitvec_8h_ac8eeaf487cd029e23fffe676f9a77a10} 
\index{bitvec.h@{bitvec.h}!bitvec\_count\_set@{bitvec\_count\_set}}
\index{bitvec\_count\_set@{bitvec\_count\_set}!bitvec.h@{bitvec.h}}
\doxysubsubsection{bitvec\_count\_set()}
{\footnotesize\ttfamily SPHINXBASE\+\_\+\+EXPORT size\+\_\+t bitvec\+\_\+count\+\_\+set (\begin{DoxyParamCaption}\item[{bitvec\+\_\+t $\ast$}]{vec,  }\item[{size\+\_\+t}]{len }\end{DoxyParamCaption})}



Return the number of bits set in the given bitvector. 


\begin{DoxyParams}{Parameters}
{\em vec} & is the bit vector \\
\hline
{\em len} & is the length of bit vector {\ttfamily vec} \\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{Returns}
the number of bits being set in vector {\ttfamily vec} 
\end{DoxyReturn}


Definition at line \textbf{ 80} of file \textbf{ bitvec.\+c}.



References \textbf{ bitvec\+\_\+count\+\_\+set()}.



Referenced by \textbf{ bitvec\+\_\+count\+\_\+set()}.

\label{bitvec_8h_a74a1e077dae41697c547d1f077c5c6e1} 
\index{bitvec.h@{bitvec.h}!bitvec\_realloc@{bitvec\_realloc}}
\index{bitvec\_realloc@{bitvec\_realloc}!bitvec.h@{bitvec.h}}
\doxysubsubsection{bitvec\_realloc()}
{\footnotesize\ttfamily SPHINXBASE\+\_\+\+EXPORT bitvec\+\_\+t $\ast$ bitvec\+\_\+realloc (\begin{DoxyParamCaption}\item[{bitvec\+\_\+t $\ast$}]{vec,  }\item[{size\+\_\+t}]{old\+\_\+len,  }\item[{size\+\_\+t}]{new\+\_\+len }\end{DoxyParamCaption})}



Resize a bit vector, clear the remaining bits. 



Definition at line \textbf{ 64} of file \textbf{ bitvec.\+c}.



References \textbf{ bitvec\+\_\+realloc()}, \textbf{ bitvec\+\_\+size}, and \textbf{ ckd\+\_\+realloc}.



Referenced by \textbf{ bitvec\+\_\+realloc()}.

