\doxysection{Luby\+Sequence.\+hpp}
\hypertarget{LubySequence_8hpp_source}{}\label{LubySequence_8hpp_source}\index{/home/chr/devel/PhD/Environment/pub/PCBEnv/pcbenv/cxx/Math/LubySequence.hpp@{/home/chr/devel/PhD/Environment/pub/PCBEnv/pcbenv/cxx/Math/LubySequence.hpp}}

\begin{DoxyCode}{0}
\DoxyCodeLine{00001\ }
\DoxyCodeLine{00002\ \textcolor{preprocessor}{\#ifndef\ GYM\_PCB\_MATH\_LUBYSEQUENCE\_H}}
\DoxyCodeLine{00003\ \textcolor{preprocessor}{\#define\ GYM\_PCB\_MATH\_LUBYSEQUENCE\_H}}
\DoxyCodeLine{00004\ }
\DoxyCodeLine{00005\ \textcolor{preprocessor}{\#include\ <vector>}}
\DoxyCodeLine{00006\ }
\DoxyCodeLine{00007\ \textcolor{comment}{//\ 1,\ 1\ 2,\ 1\ 1\ 2\ 4,\ 1\ 1\ 2\ 1\ 1\ 2\ 4\ 8,\ ...}}
\DoxyCodeLine{00008\ }
\DoxyCodeLine{00009\ \textcolor{keyword}{class\ }LubySequence}
\DoxyCodeLine{00010\ \{}
\DoxyCodeLine{00011\ \textcolor{keyword}{public}:}
\DoxyCodeLine{00012\ \ \ \ \ LubySequence()\ \{\ reset();\ \}}
\DoxyCodeLine{00013\ \ \ \ \ \textcolor{keywordtype}{void}\ reset();}
\DoxyCodeLine{00014\ \ \ \ \ uint\ next();}
\DoxyCodeLine{00015\ \textcolor{keyword}{private}:}
\DoxyCodeLine{00016\ \ \ \ \ std::vector<uint>\ values;}
\DoxyCodeLine{00017\ \ \ \ \ uint\ it;}
\DoxyCodeLine{00018\ \};}
\DoxyCodeLine{00019\ \textcolor{keyword}{inline}\ \textcolor{keywordtype}{void}\ LubySequence::reset()}
\DoxyCodeLine{00020\ \{}
\DoxyCodeLine{00021\ \ \ \ \ values.resize(1);}
\DoxyCodeLine{00022\ \ \ \ \ values[0]\ =\ 1;}
\DoxyCodeLine{00023\ \ \ \ \ it\ =\ 0;}
\DoxyCodeLine{00024\ \}}
\DoxyCodeLine{00025\ \textcolor{keyword}{inline}\ uint\ LubySequence::next()}
\DoxyCodeLine{00026\ \{}
\DoxyCodeLine{00027\ \ \ \ \ \textcolor{keywordflow}{if}\ (it\ <\ values.size())}
\DoxyCodeLine{00028\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ values[it++];}
\DoxyCodeLine{00029\ \ \ \ \ values.insert(values.end(),\ values.begin(),\ values.end());}
\DoxyCodeLine{00030\ \ \ \ \ values.push\_back(values.back()\ *\ 2);}
\DoxyCodeLine{00031\ \ \ \ \ it\ =\ 1;}
\DoxyCodeLine{00032\ \ \ \ \ \textcolor{keywordflow}{return}\ 1;}
\DoxyCodeLine{00033\ \}}
\DoxyCodeLine{00034\ }
\DoxyCodeLine{00035\ \textcolor{preprocessor}{\#endif\ }\textcolor{comment}{//\ GYM\_PCB\_MATH\_LUBYSEQUENCE\_H}}

\end{DoxyCode}
