\hypertarget{group__keyset}{}\section{Key\+Set}
\label{group__keyset}\index{Key\+Set@{Key\+Set}}


Methods to manipulate Key\+Sets.  


\subsection*{Enumerations}
\begin{DoxyCompactItemize}
\item 
enum \hyperlink{group__keyset_ga98a3d6a4016c9dad9cbd1a99a9c2a45a}{option\+\_\+t} \{ \newline
\hyperlink{group__keyset_gga98a3d6a4016c9dad9cbd1a99a9c2a45aa00738455e0ae843c8720809d8287f370}{K\+D\+B\+\_\+\+O\+\_\+\+N\+O\+NE} =0, 
\hyperlink{group__keyset_gga98a3d6a4016c9dad9cbd1a99a9c2a45aa66a5380c120f25f28f49848c4a863ead}{K\+D\+B\+\_\+\+O\+\_\+\+D\+EL} =1, 
\hyperlink{group__keyset_gga98a3d6a4016c9dad9cbd1a99a9c2a45aa52fb5f2cc86773d393da62bebebf7984}{K\+D\+B\+\_\+\+O\+\_\+\+P\+OP} =1$<$$<$1, 
\hyperlink{group__keyset_gga98a3d6a4016c9dad9cbd1a99a9c2a45aa1a70738b2126badb8db7b012c8a1c610}{K\+D\+B\+\_\+\+O\+\_\+\+N\+O\+D\+IR} =1$<$$<$2, 
\newline
\hyperlink{group__keyset_gga98a3d6a4016c9dad9cbd1a99a9c2a45aa131e99d60253d0b887a1e5886f8aa96c}{K\+D\+B\+\_\+\+O\+\_\+\+D\+I\+R\+O\+N\+LY} =1$<$$<$3, 
\hyperlink{group__keyset_gga98a3d6a4016c9dad9cbd1a99a9c2a45aa7649f575c2eb0adeaf2c9173ae16e0e6}{K\+D\+B\+\_\+\+O\+\_\+\+N\+O\+R\+E\+M\+O\+VE} =1$<$$<$6, 
\hyperlink{group__keyset_gga98a3d6a4016c9dad9cbd1a99a9c2a45aaf6ed09cee8aa8cf0d6a0e318a7105440}{K\+D\+B\+\_\+\+O\+\_\+\+R\+E\+M\+O\+V\+E\+O\+N\+LY} =1$<$$<$7, 
\hyperlink{group__keyset_gga98a3d6a4016c9dad9cbd1a99a9c2a45aa789926d8a8e15b029cf7dded4154bcda}{K\+D\+B\+\_\+\+O\+\_\+\+I\+N\+A\+C\+T\+I\+VE} =1$<$$<$8, 
\newline
\hyperlink{group__keyset_gga98a3d6a4016c9dad9cbd1a99a9c2a45aaa7d5265eacbb1590982b718f35443e2e}{K\+D\+B\+\_\+\+O\+\_\+\+S\+Y\+NC} =1$<$$<$9, 
\hyperlink{group__keyset_gga98a3d6a4016c9dad9cbd1a99a9c2a45aad9d03b36ee88ca5a774cc01b190c99b8}{K\+D\+B\+\_\+\+O\+\_\+\+S\+O\+RT} =1$<$$<$10, 
\hyperlink{group__keyset_gga98a3d6a4016c9dad9cbd1a99a9c2a45aa6adaa17b267027ce50e670bf8cc6e824}{K\+D\+B\+\_\+\+O\+\_\+\+N\+O\+R\+E\+C\+U\+R\+S\+I\+VE} =1$<$$<$11, 
\hyperlink{group__keyset_gga98a3d6a4016c9dad9cbd1a99a9c2a45aaa5586d229e048f816bf7982765442b86}{K\+D\+B\+\_\+\+O\+\_\+\+N\+O\+C\+A\+SE} =1$<$$<$12, 
\newline
\hyperlink{group__keyset_gga98a3d6a4016c9dad9cbd1a99a9c2a45aab2ff402f5de9aa67b7f786fb715a7a31}{K\+D\+B\+\_\+\+O\+\_\+\+W\+I\+T\+H\+O\+W\+N\+ER} =1$<$$<$13, 
\hyperlink{group__keyset_gga98a3d6a4016c9dad9cbd1a99a9c2a45aae8dd1961707e7d0c27228a3f98b0a94d}{K\+D\+B\+\_\+\+O\+\_\+\+N\+O\+A\+LL} =1$<$$<$14
 \}\begin{DoxyCompactList}\small\item\em Options to change the default behavior of \hyperlink{group__keyset_gaa34fc43a081e6b01e4120daa6c112004}{ks\+Lookup()} functions. \end{DoxyCompactList}
\end{DoxyCompactItemize}
\subsection*{Functions}
\begin{DoxyCompactItemize}
\item 
Key\+Set $\ast$ \hyperlink{group__keyset_ga671e1aaee3ae9dc13b4834a4ddbd2c3c}{ks\+New} (size\+\_\+t alloc,...)
\begin{DoxyCompactList}\small\item\em Allocate, initialize and return a new Key\+Set object. \end{DoxyCompactList}\item 
Key\+Set $\ast$ \hyperlink{group__keyset_ga4ff760f56693b51ab785ed7ce628e649}{ks\+V\+New} (size\+\_\+t alloc, va\+\_\+list va)
\begin{DoxyCompactList}\small\item\em Allocate, initialize and return a new Key\+Set object. \end{DoxyCompactList}\item 
Key\+Set $\ast$ \hyperlink{group__keyset_gac59e4b328245463f1451f68d5106151c}{ks\+Dup} (const Key\+Set $\ast$source)
\begin{DoxyCompactList}\small\item\em Return a duplicate of a keyset. \end{DoxyCompactList}\item 
int \hyperlink{group__keyset_gaba1f1dbea191f4d7e7eb3e4296ae7d5e}{ks\+Copy} (Key\+Set $\ast$dest, const Key\+Set $\ast$source)
\begin{DoxyCompactList}\small\item\em Replace the content of a keyset with another one. \end{DoxyCompactList}\item 
int \hyperlink{group__keyset_ga27e5c16473b02a422238c8d970db7ac8}{ks\+Del} (Key\+Set $\ast$ks)
\begin{DoxyCompactList}\small\item\em A destructor for Key\+Set objects. \end{DoxyCompactList}\item 
int \hyperlink{group__keyset_ga8f210432e664d8ba06d7d55a2aba2d0f}{ks\+Need\+Sync} (const Key\+Set $\ast$ks)
\begin{DoxyCompactList}\small\item\em Checks if Key\+Set needs sync. \end{DoxyCompactList}\item 
ssize\+\_\+t \hyperlink{group__keyset_ga7474ad6b0a0fa969dbdf267ba5770eee}{ks\+Get\+Size} (const Key\+Set $\ast$ks)
\begin{DoxyCompactList}\small\item\em Return the number of keys that {\ttfamily ks} contains. \end{DoxyCompactList}\item 
ssize\+\_\+t \hyperlink{group__keyset_gaa5a1d467a4d71041edce68ea7748ce45}{ks\+Append\+Key} (Key\+Set $\ast$ks, Key $\ast$to\+Append)
\begin{DoxyCompactList}\small\item\em Appends a Key to the end of {\ttfamily ks}. \end{DoxyCompactList}\item 
ssize\+\_\+t \hyperlink{group__keyset_ga21eb9c3a14a604ee3a8bdc779232e7b7}{ks\+Append} (Key\+Set $\ast$ks, const Key\+Set $\ast$to\+Append)
\begin{DoxyCompactList}\small\item\em Append all {\ttfamily to\+Append} contained keys to the end of the {\ttfamily ks}. \end{DoxyCompactList}\item 
Key\+Set $\ast$ \hyperlink{group__keyset_ga6b00cf82b59af4d883a9bad6cf4a4a4a}{ks\+Cut} (Key\+Set $\ast$ks, const Key $\ast$cutpoint)
\begin{DoxyCompactList}\small\item\em Cuts out a keyset at the cutpoint. \end{DoxyCompactList}\item 
Key $\ast$ \hyperlink{group__keyset_gae42530b04defb772059de0600159cf69}{ks\+Pop} (Key\+Set $\ast$ks)
\begin{DoxyCompactList}\small\item\em Remove and return the last key of {\ttfamily ks}. \end{DoxyCompactList}\item 
int \hyperlink{group__keyset_gabe793ff51f1728e3429c84a8a9086b70}{ks\+Rewind} (Key\+Set $\ast$ks)
\begin{DoxyCompactList}\small\item\em Rewinds the Key\+Set internal cursor. \end{DoxyCompactList}\item 
Key $\ast$ \hyperlink{group__keyset_ga317321c9065b5a4b3e33fe1c399bcec9}{ks\+Next} (Key\+Set $\ast$ks)
\begin{DoxyCompactList}\small\item\em Returns the next Key in a Key\+Set. \end{DoxyCompactList}\item 
Key $\ast$ \hyperlink{group__keyset_ga4287b9416912c5f2ab9c195cb74fb094}{ks\+Current} (const Key\+Set $\ast$ks)
\begin{DoxyCompactList}\small\item\em Return the current Key. \end{DoxyCompactList}\item 
Key $\ast$ \hyperlink{group__keyset_gae7dbf3aef70e67b5328475eb3d1f92f5}{ks\+Head} (const Key\+Set $\ast$ks)
\begin{DoxyCompactList}\small\item\em Return the first key in the Key\+Set. \end{DoxyCompactList}\item 
Key $\ast$ \hyperlink{group__keyset_gadca442c4ab43cf532b15091d7711559e}{ks\+Tail} (const Key\+Set $\ast$ks)
\begin{DoxyCompactList}\small\item\em Return the last key in the Key\+Set. \end{DoxyCompactList}\item 
cursor\+\_\+t \hyperlink{group__keyset_gaffe507ab9281c322eb16c3e992075d29}{ks\+Get\+Cursor} (const Key\+Set $\ast$ks)
\begin{DoxyCompactList}\small\item\em Get the Key\+Set internal cursor. \end{DoxyCompactList}\item 
Key $\ast$ \hyperlink{group__keyset_ga3604cc41505f7e19db945cece67190b6}{ks\+At\+Cursor} (Key\+Set $\ast$ks, cursor\+\_\+t pos)
\begin{DoxyCompactList}\small\item\em return key at given cursor position \end{DoxyCompactList}\item 
int \hyperlink{group__keyset_gad94c9ffaa3e8034564c0712fd407c345}{ks\+Set\+Cursor} (Key\+Set $\ast$ks, cursor\+\_\+t cursor)
\begin{DoxyCompactList}\small\item\em Set the Key\+Set internal cursor. \end{DoxyCompactList}\item 
Key $\ast$ \hyperlink{group__keyset_gaa34fc43a081e6b01e4120daa6c112004}{ks\+Lookup} (Key\+Set $\ast$ks, Key $\ast$key, \hyperlink{group__keyset_ga98a3d6a4016c9dad9cbd1a99a9c2a45a}{option\+\_\+t} options)
\begin{DoxyCompactList}\small\item\em Look for a Key contained in {\ttfamily ks} that matches the name of the {\ttfamily key}. \end{DoxyCompactList}\item 
Key $\ast$ \hyperlink{group__keyset_gad2e30fb6d4739d917c5abb2ac2f9c1a1}{ks\+Lookup\+By\+Name} (Key\+Set $\ast$ks, const char $\ast$name, \hyperlink{group__keyset_ga98a3d6a4016c9dad9cbd1a99a9c2a45a}{option\+\_\+t} options)
\begin{DoxyCompactList}\small\item\em Convenience method to look for a Key contained in {\ttfamily ks} that matches {\ttfamily name}. \end{DoxyCompactList}\end{DoxyCompactItemize}


\subsection{Detailed Description}
Methods to manipulate Key\+Sets. 

A Key\+Set is a set of keys.

Most important properties of a Key\+Set\+:


\begin{DoxyItemize}
\item Allows us to iterate over all keys (in any depth)
\item Iteration is always sorted
\item Fast key lookup
\item A Key may be shared among many Key\+Sets.
\end{DoxyItemize}

The most important methods of Key\+Set\+:


\begin{DoxyItemize}
\item With \hyperlink{group__keyset_ga671e1aaee3ae9dc13b4834a4ddbd2c3c}{ks\+New()} you can create a new Key\+Set.
\item You can append keys with \hyperlink{group__keyset_gaa5a1d467a4d71041edce68ea7748ce45}{ks\+Append\+Key()} or with \hyperlink{group__keyset_ga21eb9c3a14a604ee3a8bdc779232e7b7}{ks\+Append()} you can append a whole keyset.
\item Using \hyperlink{group__keyset_gaa34fc43a081e6b01e4120daa6c112004}{ks\+Lookup()} you can lookup (or pop with \hyperlink{group__keyset_gga98a3d6a4016c9dad9cbd1a99a9c2a45aa52fb5f2cc86773d393da62bebebf7984}{K\+D\+B\+\_\+\+O\+\_\+\+P\+OP}) a key.
\item With \hyperlink{group__keyset_gabe793ff51f1728e3429c84a8a9086b70}{ks\+Rewind()} and \hyperlink{group__keyset_ga317321c9065b5a4b3e33fe1c399bcec9}{ks\+Next()} you can iterate through the keyset. Be assured that you will get every key of the set in a stable order (parents before children).
\end{DoxyItemize}

\begin{DoxyNote}{Note}
Because the key is not copied, also the pointer to the current metadata \hyperlink{group__keymeta_ga4c88342f580a4291455a801af71ce048}{key\+Next\+Meta()} will be shared.
\end{DoxyNote}
Key\+Sets have an \hyperlink{group__keyset_ga4287b9416912c5f2ab9c195cb74fb094}{internal cursor }. Methods should avoid to change this cursor, unless they want to communicate something with it. The internal cursor is used\+:


\begin{DoxyItemize}
\item in \hyperlink{group__keyset_gaa34fc43a081e6b01e4120daa6c112004}{ks\+Lookup()}\+: points to the found key
\item in \hyperlink{group__kdb_ga11436b058408f83d303ca5e996832bcf}{kdb\+Set()}\+: points to the key which caused an error
\end{DoxyItemize}

Key\+Set is the most important data structure in Elektra. It makes it possible to get and store many keys at once inside the database. In addition to that, the class can be used as high level datastructure in applications and it can be used in plugins to manipulate or check configuration.

With \hyperlink{group__keyset_gad2e30fb6d4739d917c5abb2ac2f9c1a1}{ks\+Lookup\+By\+Name()} it is possible to fetch easily specific keys out of the list of keys.

You can easily create and iterate keys\+:


\begin{DoxyCodeInclude}
\textcolor{comment}{// create a new keyset with 3 keys}
\textcolor{comment}{// with a hint that about 20 keys will be inside}
KeySet * myConfig = \hyperlink{group__keyset_ga671e1aaee3ae9dc13b4834a4ddbd2c3c}{ksNew} (20, \hyperlink{group__key_gad23c65b44bf48d773759e1f9a4d43b89}{keyNew} (\textcolor{stringliteral}{"user/name1"}, 0), \hyperlink{group__key_gad23c65b44bf48d773759e1f9a4d43b89}{keyNew} (\textcolor{stringliteral}{"user/name2"}, 0), 
      \hyperlink{group__key_gad23c65b44bf48d773759e1f9a4d43b89}{keyNew} (\textcolor{stringliteral}{"user/name3"}, 0), \hyperlink{kdbenum_8c_a7a28fce3773b2c873c94ac80b8b4cd54}{KS\_END});
\textcolor{comment}{// append a key in the keyset}
\hyperlink{group__keyset_gaa5a1d467a4d71041edce68ea7748ce45}{ksAppendKey} (myConfig, \hyperlink{group__key_gad23c65b44bf48d773759e1f9a4d43b89}{keyNew} (\textcolor{stringliteral}{"user/name4"}, 0));

Key * current;
\hyperlink{group__keyset_gabe793ff51f1728e3429c84a8a9086b70}{ksRewind} (myConfig);
\textcolor{keywordflow}{while} ((current = \hyperlink{group__keyset_ga317321c9065b5a4b3e33fe1c399bcec9}{ksNext} (myConfig)) != 0)
\{
        printf (\textcolor{stringliteral}{"Key name is %s.\(\backslash\)n"}, \hyperlink{group__keyname_ga8e805c726a60da921d3736cda7813513}{keyName} (current));
\}
\hyperlink{group__keyset_ga27e5c16473b02a422238c8d970db7ac8}{ksDel} (myConfig); \textcolor{comment}{// delete keyset and all keys appended}
\end{DoxyCodeInclude}


\subsection{Enumeration Type Documentation}
\mbox{\Hypertarget{group__keyset_ga98a3d6a4016c9dad9cbd1a99a9c2a45a}\label{group__keyset_ga98a3d6a4016c9dad9cbd1a99a9c2a45a}} 
\index{Key\+Set@{Key\+Set}!option\+\_\+t@{option\+\_\+t}}
\index{option\+\_\+t@{option\+\_\+t}!Key\+Set@{Key\+Set}}
\subsubsection{\texorpdfstring{option\+\_\+t}{option\_t}}
{\footnotesize\ttfamily enum \hyperlink{group__keyset_ga98a3d6a4016c9dad9cbd1a99a9c2a45a}{option\+\_\+t}}



Options to change the default behavior of \hyperlink{group__keyset_gaa34fc43a081e6b01e4120daa6c112004}{ks\+Lookup()} functions. 

These options can be O\+Red. That is the $\vert$-\/\+Operator in C.

\begin{DoxySeeAlso}{See also}
\hyperlink{group__kdb_ga28e385fd9cb7ccfe0b2f1ed2f62453a1}{kdb\+Get()}, \hyperlink{group__kdb_ga11436b058408f83d303ca5e996832bcf}{kdb\+Set()} 
\end{DoxySeeAlso}
\begin{DoxyEnumFields}{Enumerator}
\raisebox{\heightof{T}}[0pt][0pt]{\index{K\+D\+B\+\_\+\+O\+\_\+\+N\+O\+NE@{K\+D\+B\+\_\+\+O\+\_\+\+N\+O\+NE}!Key\+Set@{Key\+Set}}\index{Key\+Set@{Key\+Set}!K\+D\+B\+\_\+\+O\+\_\+\+N\+O\+NE@{K\+D\+B\+\_\+\+O\+\_\+\+N\+O\+NE}}}\mbox{\Hypertarget{group__keyset_gga98a3d6a4016c9dad9cbd1a99a9c2a45aa00738455e0ae843c8720809d8287f370}\label{group__keyset_gga98a3d6a4016c9dad9cbd1a99a9c2a45aa00738455e0ae843c8720809d8287f370}} 
K\+D\+B\+\_\+\+O\+\_\+\+N\+O\+NE&No Option set. \begin{DoxySeeAlso}{See also}
\hyperlink{group__keyset_gaa34fc43a081e6b01e4120daa6c112004}{ks\+Lookup()} 
\end{DoxySeeAlso}
\\
\hline

\raisebox{\heightof{T}}[0pt][0pt]{\index{K\+D\+B\+\_\+\+O\+\_\+\+D\+EL@{K\+D\+B\+\_\+\+O\+\_\+\+D\+EL}!Key\+Set@{Key\+Set}}\index{Key\+Set@{Key\+Set}!K\+D\+B\+\_\+\+O\+\_\+\+D\+EL@{K\+D\+B\+\_\+\+O\+\_\+\+D\+EL}}}\mbox{\Hypertarget{group__keyset_gga98a3d6a4016c9dad9cbd1a99a9c2a45aa66a5380c120f25f28f49848c4a863ead}\label{group__keyset_gga98a3d6a4016c9dad9cbd1a99a9c2a45aa66a5380c120f25f28f49848c4a863ead}} 
K\+D\+B\+\_\+\+O\+\_\+\+D\+EL&Delete parent\+Key key in \hyperlink{group__keyset_gaa34fc43a081e6b01e4120daa6c112004}{ks\+Lookup()}. \begin{DoxySeeAlso}{See also}
\hyperlink{group__keyset_gaa34fc43a081e6b01e4120daa6c112004}{ks\+Lookup()} 
\end{DoxySeeAlso}
\\
\hline

\raisebox{\heightof{T}}[0pt][0pt]{\index{K\+D\+B\+\_\+\+O\+\_\+\+P\+OP@{K\+D\+B\+\_\+\+O\+\_\+\+P\+OP}!Key\+Set@{Key\+Set}}\index{Key\+Set@{Key\+Set}!K\+D\+B\+\_\+\+O\+\_\+\+P\+OP@{K\+D\+B\+\_\+\+O\+\_\+\+P\+OP}}}\mbox{\Hypertarget{group__keyset_gga98a3d6a4016c9dad9cbd1a99a9c2a45aa52fb5f2cc86773d393da62bebebf7984}\label{group__keyset_gga98a3d6a4016c9dad9cbd1a99a9c2a45aa52fb5f2cc86773d393da62bebebf7984}} 
K\+D\+B\+\_\+\+O\+\_\+\+P\+OP&Pop Parent out of keyset key in \hyperlink{group__keyset_gaa34fc43a081e6b01e4120daa6c112004}{ks\+Lookup()}. \begin{DoxySeeAlso}{See also}
\hyperlink{group__keyset_gae42530b04defb772059de0600159cf69}{ks\+Pop()}. 
\end{DoxySeeAlso}
\\
\hline

\raisebox{\heightof{T}}[0pt][0pt]{\index{K\+D\+B\+\_\+\+O\+\_\+\+N\+O\+D\+IR@{K\+D\+B\+\_\+\+O\+\_\+\+N\+O\+D\+IR}!Key\+Set@{Key\+Set}}\index{Key\+Set@{Key\+Set}!K\+D\+B\+\_\+\+O\+\_\+\+N\+O\+D\+IR@{K\+D\+B\+\_\+\+O\+\_\+\+N\+O\+D\+IR}}}\mbox{\Hypertarget{group__keyset_gga98a3d6a4016c9dad9cbd1a99a9c2a45aa1a70738b2126badb8db7b012c8a1c610}\label{group__keyset_gga98a3d6a4016c9dad9cbd1a99a9c2a45aa1a70738b2126badb8db7b012c8a1c610}} 
K\+D\+B\+\_\+\+O\+\_\+\+N\+O\+D\+IR&Feature not available. T\+O\+DO\+: remove for 1.\+0 \\
\hline

\raisebox{\heightof{T}}[0pt][0pt]{\index{K\+D\+B\+\_\+\+O\+\_\+\+D\+I\+R\+O\+N\+LY@{K\+D\+B\+\_\+\+O\+\_\+\+D\+I\+R\+O\+N\+LY}!Key\+Set@{Key\+Set}}\index{Key\+Set@{Key\+Set}!K\+D\+B\+\_\+\+O\+\_\+\+D\+I\+R\+O\+N\+LY@{K\+D\+B\+\_\+\+O\+\_\+\+D\+I\+R\+O\+N\+LY}}}\mbox{\Hypertarget{group__keyset_gga98a3d6a4016c9dad9cbd1a99a9c2a45aa131e99d60253d0b887a1e5886f8aa96c}\label{group__keyset_gga98a3d6a4016c9dad9cbd1a99a9c2a45aa131e99d60253d0b887a1e5886f8aa96c}} 
K\+D\+B\+\_\+\+O\+\_\+\+D\+I\+R\+O\+N\+LY&Feature not available. T\+O\+DO\+: remove for 1.\+0 \\
\hline

\raisebox{\heightof{T}}[0pt][0pt]{\index{K\+D\+B\+\_\+\+O\+\_\+\+N\+O\+R\+E\+M\+O\+VE@{K\+D\+B\+\_\+\+O\+\_\+\+N\+O\+R\+E\+M\+O\+VE}!Key\+Set@{Key\+Set}}\index{Key\+Set@{Key\+Set}!K\+D\+B\+\_\+\+O\+\_\+\+N\+O\+R\+E\+M\+O\+VE@{K\+D\+B\+\_\+\+O\+\_\+\+N\+O\+R\+E\+M\+O\+VE}}}\mbox{\Hypertarget{group__keyset_gga98a3d6a4016c9dad9cbd1a99a9c2a45aa7649f575c2eb0adeaf2c9173ae16e0e6}\label{group__keyset_gga98a3d6a4016c9dad9cbd1a99a9c2a45aa7649f575c2eb0adeaf2c9173ae16e0e6}} 
K\+D\+B\+\_\+\+O\+\_\+\+N\+O\+R\+E\+M\+O\+VE&Feature not available. T\+O\+DO\+: remove for 1.\+0 \\
\hline

\raisebox{\heightof{T}}[0pt][0pt]{\index{K\+D\+B\+\_\+\+O\+\_\+\+R\+E\+M\+O\+V\+E\+O\+N\+LY@{K\+D\+B\+\_\+\+O\+\_\+\+R\+E\+M\+O\+V\+E\+O\+N\+LY}!Key\+Set@{Key\+Set}}\index{Key\+Set@{Key\+Set}!K\+D\+B\+\_\+\+O\+\_\+\+R\+E\+M\+O\+V\+E\+O\+N\+LY@{K\+D\+B\+\_\+\+O\+\_\+\+R\+E\+M\+O\+V\+E\+O\+N\+LY}}}\mbox{\Hypertarget{group__keyset_gga98a3d6a4016c9dad9cbd1a99a9c2a45aaf6ed09cee8aa8cf0d6a0e318a7105440}\label{group__keyset_gga98a3d6a4016c9dad9cbd1a99a9c2a45aaf6ed09cee8aa8cf0d6a0e318a7105440}} 
K\+D\+B\+\_\+\+O\+\_\+\+R\+E\+M\+O\+V\+E\+O\+N\+LY&Feature not available. T\+O\+DO\+: remove for 1.\+0 \\
\hline

\raisebox{\heightof{T}}[0pt][0pt]{\index{K\+D\+B\+\_\+\+O\+\_\+\+I\+N\+A\+C\+T\+I\+VE@{K\+D\+B\+\_\+\+O\+\_\+\+I\+N\+A\+C\+T\+I\+VE}!Key\+Set@{Key\+Set}}\index{Key\+Set@{Key\+Set}!K\+D\+B\+\_\+\+O\+\_\+\+I\+N\+A\+C\+T\+I\+VE@{K\+D\+B\+\_\+\+O\+\_\+\+I\+N\+A\+C\+T\+I\+VE}}}\mbox{\Hypertarget{group__keyset_gga98a3d6a4016c9dad9cbd1a99a9c2a45aa789926d8a8e15b029cf7dded4154bcda}\label{group__keyset_gga98a3d6a4016c9dad9cbd1a99a9c2a45aa789926d8a8e15b029cf7dded4154bcda}} 
K\+D\+B\+\_\+\+O\+\_\+\+I\+N\+A\+C\+T\+I\+VE&Feature not available. T\+O\+DO\+: remove for 1.\+0 \\
\hline

\raisebox{\heightof{T}}[0pt][0pt]{\index{K\+D\+B\+\_\+\+O\+\_\+\+S\+Y\+NC@{K\+D\+B\+\_\+\+O\+\_\+\+S\+Y\+NC}!Key\+Set@{Key\+Set}}\index{Key\+Set@{Key\+Set}!K\+D\+B\+\_\+\+O\+\_\+\+S\+Y\+NC@{K\+D\+B\+\_\+\+O\+\_\+\+S\+Y\+NC}}}\mbox{\Hypertarget{group__keyset_gga98a3d6a4016c9dad9cbd1a99a9c2a45aaa7d5265eacbb1590982b718f35443e2e}\label{group__keyset_gga98a3d6a4016c9dad9cbd1a99a9c2a45aaa7d5265eacbb1590982b718f35443e2e}} 
K\+D\+B\+\_\+\+O\+\_\+\+S\+Y\+NC&Feature not available. T\+O\+DO\+: remove for 1.\+0 \\
\hline

\raisebox{\heightof{T}}[0pt][0pt]{\index{K\+D\+B\+\_\+\+O\+\_\+\+S\+O\+RT@{K\+D\+B\+\_\+\+O\+\_\+\+S\+O\+RT}!Key\+Set@{Key\+Set}}\index{Key\+Set@{Key\+Set}!K\+D\+B\+\_\+\+O\+\_\+\+S\+O\+RT@{K\+D\+B\+\_\+\+O\+\_\+\+S\+O\+RT}}}\mbox{\Hypertarget{group__keyset_gga98a3d6a4016c9dad9cbd1a99a9c2a45aad9d03b36ee88ca5a774cc01b190c99b8}\label{group__keyset_gga98a3d6a4016c9dad9cbd1a99a9c2a45aad9d03b36ee88ca5a774cc01b190c99b8}} 
K\+D\+B\+\_\+\+O\+\_\+\+S\+O\+RT&Feature not available. T\+O\+DO\+: remove for 1.\+0 \\
\hline

\raisebox{\heightof{T}}[0pt][0pt]{\index{K\+D\+B\+\_\+\+O\+\_\+\+N\+O\+R\+E\+C\+U\+R\+S\+I\+VE@{K\+D\+B\+\_\+\+O\+\_\+\+N\+O\+R\+E\+C\+U\+R\+S\+I\+VE}!Key\+Set@{Key\+Set}}\index{Key\+Set@{Key\+Set}!K\+D\+B\+\_\+\+O\+\_\+\+N\+O\+R\+E\+C\+U\+R\+S\+I\+VE@{K\+D\+B\+\_\+\+O\+\_\+\+N\+O\+R\+E\+C\+U\+R\+S\+I\+VE}}}\mbox{\Hypertarget{group__keyset_gga98a3d6a4016c9dad9cbd1a99a9c2a45aa6adaa17b267027ce50e670bf8cc6e824}\label{group__keyset_gga98a3d6a4016c9dad9cbd1a99a9c2a45aa6adaa17b267027ce50e670bf8cc6e824}} 
K\+D\+B\+\_\+\+O\+\_\+\+N\+O\+R\+E\+C\+U\+R\+S\+I\+VE&Feature not available. T\+O\+DO\+: remove for 1.\+0 \\
\hline

\raisebox{\heightof{T}}[0pt][0pt]{\index{K\+D\+B\+\_\+\+O\+\_\+\+N\+O\+C\+A\+SE@{K\+D\+B\+\_\+\+O\+\_\+\+N\+O\+C\+A\+SE}!Key\+Set@{Key\+Set}}\index{Key\+Set@{Key\+Set}!K\+D\+B\+\_\+\+O\+\_\+\+N\+O\+C\+A\+SE@{K\+D\+B\+\_\+\+O\+\_\+\+N\+O\+C\+A\+SE}}}\mbox{\Hypertarget{group__keyset_gga98a3d6a4016c9dad9cbd1a99a9c2a45aaa5586d229e048f816bf7982765442b86}\label{group__keyset_gga98a3d6a4016c9dad9cbd1a99a9c2a45aaa5586d229e048f816bf7982765442b86}} 
K\+D\+B\+\_\+\+O\+\_\+\+N\+O\+C\+A\+SE&Ignore case. do not use without K\+D\+B\+\_\+\+O\+\_\+\+N\+O\+A\+LL

T\+O\+DO\+: remove for 1.\+0

\begin{DoxySeeAlso}{See also}
\hyperlink{group__keyset_gaa34fc43a081e6b01e4120daa6c112004}{ks\+Lookup()} 
\end{DoxySeeAlso}
\\
\hline

\raisebox{\heightof{T}}[0pt][0pt]{\index{K\+D\+B\+\_\+\+O\+\_\+\+W\+I\+T\+H\+O\+W\+N\+ER@{K\+D\+B\+\_\+\+O\+\_\+\+W\+I\+T\+H\+O\+W\+N\+ER}!Key\+Set@{Key\+Set}}\index{Key\+Set@{Key\+Set}!K\+D\+B\+\_\+\+O\+\_\+\+W\+I\+T\+H\+O\+W\+N\+ER@{K\+D\+B\+\_\+\+O\+\_\+\+W\+I\+T\+H\+O\+W\+N\+ER}}}\mbox{\Hypertarget{group__keyset_gga98a3d6a4016c9dad9cbd1a99a9c2a45aab2ff402f5de9aa67b7f786fb715a7a31}\label{group__keyset_gga98a3d6a4016c9dad9cbd1a99a9c2a45aab2ff402f5de9aa67b7f786fb715a7a31}} 
K\+D\+B\+\_\+\+O\+\_\+\+W\+I\+T\+H\+O\+W\+N\+ER&Search with owner. The owner concept is deprecated, do not use.

T\+O\+DO\+: remove for 1.\+0

\begin{DoxySeeAlso}{See also}
\hyperlink{group__keyset_gaa34fc43a081e6b01e4120daa6c112004}{ks\+Lookup()} 
\end{DoxySeeAlso}
\\
\hline

\raisebox{\heightof{T}}[0pt][0pt]{\index{K\+D\+B\+\_\+\+O\+\_\+\+N\+O\+A\+LL@{K\+D\+B\+\_\+\+O\+\_\+\+N\+O\+A\+LL}!Key\+Set@{Key\+Set}}\index{Key\+Set@{Key\+Set}!K\+D\+B\+\_\+\+O\+\_\+\+N\+O\+A\+LL@{K\+D\+B\+\_\+\+O\+\_\+\+N\+O\+A\+LL}}}\mbox{\Hypertarget{group__keyset_gga98a3d6a4016c9dad9cbd1a99a9c2a45aae8dd1961707e7d0c27228a3f98b0a94d}\label{group__keyset_gga98a3d6a4016c9dad9cbd1a99a9c2a45aae8dd1961707e7d0c27228a3f98b0a94d}} 
K\+D\+B\+\_\+\+O\+\_\+\+N\+O\+A\+LL&Linear search from start -\/$>$ cursor to cursor -\/$>$ end. T\+O\+DO\+: remove for 1.\+0

\begin{DoxySeeAlso}{See also}
\hyperlink{group__keyset_gaa34fc43a081e6b01e4120daa6c112004}{ks\+Lookup()} 
\end{DoxySeeAlso}
\\
\hline

\end{DoxyEnumFields}


\subsection{Function Documentation}
\mbox{\Hypertarget{group__keyset_ga21eb9c3a14a604ee3a8bdc779232e7b7}\label{group__keyset_ga21eb9c3a14a604ee3a8bdc779232e7b7}} 
\index{Key\+Set@{Key\+Set}!ks\+Append@{ks\+Append}}
\index{ks\+Append@{ks\+Append}!Key\+Set@{Key\+Set}}
\subsubsection{\texorpdfstring{ks\+Append()}{ksAppend()}}
{\footnotesize\ttfamily ssize\+\_\+t ks\+Append (\begin{DoxyParamCaption}\item[{Key\+Set $\ast$}]{ks,  }\item[{const Key\+Set $\ast$}]{to\+Append }\end{DoxyParamCaption})}



Append all {\ttfamily to\+Append} contained keys to the end of the {\ttfamily ks}. 

{\ttfamily to\+Append} Key\+Set will be left unchanged.

If a key is both in to\+Append and ks, the Key in ks will be overridden.

\begin{DoxyNote}{Note}
Because the key is not copied, also the pointer to the current metadata \hyperlink{group__keymeta_ga4c88342f580a4291455a801af71ce048}{key\+Next\+Meta()} will be shared.
\end{DoxyNote}
\begin{DoxyPostcond}{Postcondition}
Sorted Key\+Set ks with all keys it had before and additionally the keys from to\+Append 
\end{DoxyPostcond}
\begin{DoxyReturn}{Returns}
the size of the Key\+Set after transfer 
\end{DoxyReturn}

\begin{DoxyRetVals}{Return values}
{\em -\/1} & on N\+U\+LL pointers \\
\hline
\end{DoxyRetVals}

\begin{DoxyParams}{Parameters}
{\em ks} & the Key\+Set that will receive the keys \\
\hline
{\em to\+Append} & the Key\+Set that provides the keys that will be transferred \\
\hline
\end{DoxyParams}
\begin{DoxySeeAlso}{See also}
\hyperlink{group__keyset_gaa5a1d467a4d71041edce68ea7748ce45}{ks\+Append\+Key()} 
\end{DoxySeeAlso}
\mbox{\Hypertarget{group__keyset_gaa5a1d467a4d71041edce68ea7748ce45}\label{group__keyset_gaa5a1d467a4d71041edce68ea7748ce45}} 
\index{Key\+Set@{Key\+Set}!ks\+Append\+Key@{ks\+Append\+Key}}
\index{ks\+Append\+Key@{ks\+Append\+Key}!Key\+Set@{Key\+Set}}
\subsubsection{\texorpdfstring{ks\+Append\+Key()}{ksAppendKey()}}
{\footnotesize\ttfamily ssize\+\_\+t ks\+Append\+Key (\begin{DoxyParamCaption}\item[{Key\+Set $\ast$}]{ks,  }\item[{Key $\ast$}]{to\+Append }\end{DoxyParamCaption})}



Appends a Key to the end of {\ttfamily ks}. 

Will take ownership of the key {\ttfamily to\+Append}. That means ks\+Del(ks) will remove the key unless the key\+:
\begin{DoxyItemize}
\item was duplicated before inserting
\item got its refcount incremented by \hyperlink{group__key_ga6970a6f254d67af7e39f8e469bb162f1}{key\+Inc\+Ref()} before inserting
\item was also inserted into another keyset with \hyperlink{group__keyset_gaa5a1d467a4d71041edce68ea7748ce45}{ks\+Append\+Key()}
\end{DoxyItemize}

The reference counter of the key will be incremented to show this ownership, and thus {\ttfamily to\+Append} is not const.

\begin{DoxyNote}{Note}
Because the key is not copied, also the pointer to the current metadata \hyperlink{group__keymeta_ga4c88342f580a4291455a801af71ce048}{key\+Next\+Meta()} will be shared.
\end{DoxyNote}
\begin{DoxySeeAlso}{See also}
\hyperlink{group__key_ga4aabc4272506dd63161db2bbb42de8ae}{key\+Get\+Ref()}.
\end{DoxySeeAlso}
If the keyname already existed in the keyset, it will be replaced with the new key.

The Key\+Set internal cursor will be set to the new key.

It is save to directly append newly created keys\+: 
\begin{DoxyCodeInclude}
KeySet * ks = \hyperlink{group__keyset_ga671e1aaee3ae9dc13b4834a4ddbd2c3c}{ksNew} (1, \hyperlink{kdbenum_8c_a7a28fce3773b2c873c94ac80b8b4cd54}{KS\_END});
\hyperlink{group__keyset_gaa5a1d467a4d71041edce68ea7748ce45}{ksAppendKey} (ks, \hyperlink{group__key_gad23c65b44bf48d773759e1f9a4d43b89}{keyNew} (\textcolor{stringliteral}{"user/my/new/key"}, \hyperlink{group__key_gga91fb3178848bd682000958089abbaf40aa8adb6fcb92dec58fb19410eacfdd403}{KEY\_END}));
\hyperlink{group__keyset_ga27e5c16473b02a422238c8d970db7ac8}{ksDel} (ks);
\textcolor{comment}{// key deleted, too!}
\end{DoxyCodeInclude}
 If you want the key to outlive the keyset, make sure to do proper ref counting\+: 
\begin{DoxyCodeInclude}
KeySet * ks = \hyperlink{group__keyset_ga671e1aaee3ae9dc13b4834a4ddbd2c3c}{ksNew} (1, \hyperlink{kdbenum_8c_a7a28fce3773b2c873c94ac80b8b4cd54}{KS\_END});
Key * k = \hyperlink{group__key_gad23c65b44bf48d773759e1f9a4d43b89}{keyNew} (\textcolor{stringliteral}{"user/ref/key"}, \hyperlink{group__key_gga91fb3178848bd682000958089abbaf40aa8adb6fcb92dec58fb19410eacfdd403}{KEY\_END});
\hyperlink{group__key_ga6970a6f254d67af7e39f8e469bb162f1}{keyIncRef} (k);
\hyperlink{group__keyset_gaa5a1d467a4d71041edce68ea7748ce45}{ksAppendKey} (ks, k);
\hyperlink{group__keyset_ga27e5c16473b02a422238c8d970db7ac8}{ksDel} (ks);
\textcolor{comment}{// now we still can work with the key k!}
\hyperlink{group__key_ga2c6433ca22109e4e141946057eccb283}{keyDecRef} (k);
\hyperlink{group__key_ga3df95bbc2494e3e6703ece5639be5bb1}{keyDel} (k);
\end{DoxyCodeInclude}
 Or if you want to avoid aliasing at all, you can duplicate the key. But then key in the keyset has another identity\+: 
\begin{DoxyCodeInclude}
KeySet * ks = \hyperlink{group__keyset_ga671e1aaee3ae9dc13b4834a4ddbd2c3c}{ksNew} (1, \hyperlink{kdbenum_8c_a7a28fce3773b2c873c94ac80b8b4cd54}{KS\_END});
Key * k = \hyperlink{group__key_gad23c65b44bf48d773759e1f9a4d43b89}{keyNew} (\textcolor{stringliteral}{"user/ref/key"}, \hyperlink{group__key_gga91fb3178848bd682000958089abbaf40aa8adb6fcb92dec58fb19410eacfdd403}{KEY\_END});
\hyperlink{group__keyset_gaa5a1d467a4d71041edce68ea7748ce45}{ksAppendKey} (ks, \hyperlink{group__key_gae6ec6a60cc4b8c1463fa08623d056ce3}{keyDup} (k));
\hyperlink{group__keyset_ga27e5c16473b02a422238c8d970db7ac8}{ksDel} (ks);
\textcolor{comment}{// now we still can work with the key k!}
\hyperlink{group__key_ga3df95bbc2494e3e6703ece5639be5bb1}{keyDel} (k);
\end{DoxyCodeInclude}


\begin{DoxyReturn}{Returns}
the size of the Key\+Set after insertion 
\end{DoxyReturn}

\begin{DoxyRetVals}{Return values}
{\em -\/1} & on N\+U\+LL pointers \\
\hline
{\em -\/1} & if insertion failed, the key will be deleted then. \\
\hline
\end{DoxyRetVals}

\begin{DoxyParams}{Parameters}
{\em ks} & Key\+Set that will receive the key \\
\hline
{\em to\+Append} & Key that will be appended to ks or deleted \\
\hline
\end{DoxyParams}
\begin{DoxySeeAlso}{See also}
\hyperlink{group__keyset_ga21eb9c3a14a604ee3a8bdc779232e7b7}{ks\+Append()}, \hyperlink{group__key_gad23c65b44bf48d773759e1f9a4d43b89}{key\+New()}, \hyperlink{group__keyset_ga27e5c16473b02a422238c8d970db7ac8}{ks\+Del()} 

\hyperlink{group__key_ga6970a6f254d67af7e39f8e469bb162f1}{key\+Inc\+Ref()} 
\end{DoxySeeAlso}
\mbox{\Hypertarget{group__keyset_ga3604cc41505f7e19db945cece67190b6}\label{group__keyset_ga3604cc41505f7e19db945cece67190b6}} 
\index{Key\+Set@{Key\+Set}!ks\+At\+Cursor@{ks\+At\+Cursor}}
\index{ks\+At\+Cursor@{ks\+At\+Cursor}!Key\+Set@{Key\+Set}}
\subsubsection{\texorpdfstring{ks\+At\+Cursor()}{ksAtCursor()}}
{\footnotesize\ttfamily Key$\ast$ ks\+At\+Cursor (\begin{DoxyParamCaption}\item[{Key\+Set $\ast$}]{ks,  }\item[{cursor\+\_\+t}]{pos }\end{DoxyParamCaption})}



return key at given cursor position 


\begin{DoxyParams}{Parameters}
{\em ks} & the keyset to pop key from \\
\hline
{\em pos} & where to get \\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{Returns}
the key at the cursor position on success 
\end{DoxyReturn}

\begin{DoxyRetVals}{Return values}
{\em N\+U\+LL} & on N\+U\+LL pointer, negative cursor position or a position that does not lie within the keyset \\
\hline
\end{DoxyRetVals}
\mbox{\Hypertarget{group__keyset_gaba1f1dbea191f4d7e7eb3e4296ae7d5e}\label{group__keyset_gaba1f1dbea191f4d7e7eb3e4296ae7d5e}} 
\index{Key\+Set@{Key\+Set}!ks\+Copy@{ks\+Copy}}
\index{ks\+Copy@{ks\+Copy}!Key\+Set@{Key\+Set}}
\subsubsection{\texorpdfstring{ks\+Copy()}{ksCopy()}}
{\footnotesize\ttfamily int ks\+Copy (\begin{DoxyParamCaption}\item[{Key\+Set $\ast$}]{dest,  }\item[{const Key\+Set $\ast$}]{source }\end{DoxyParamCaption})}



Replace the content of a keyset with another one. 

Most often you may want a duplicate of a keyset, see \hyperlink{group__keyset_gac59e4b328245463f1451f68d5106151c}{ks\+Dup()} or append keys, see \hyperlink{group__keyset_ga21eb9c3a14a604ee3a8bdc779232e7b7}{ks\+Append()}. But in some situations you need to copy a keyset to a existing keyset, for that this function exists.

\begin{DoxyNote}{Note}
You can also use it to clear a keyset when you pass a N\+U\+LL pointer as {\ttfamily source}.
\end{DoxyNote}
\begin{DoxyParagraph}{Implementation\+:}
First all keys in {\ttfamily dest} will be deleted. Afterwards the content of the source will be added to the destination and the \hyperlink{group__keyset_ga4287b9416912c5f2ab9c195cb74fb094}{ks\+Current()} is set properly in {\ttfamily dest}.
\end{DoxyParagraph}
A flat copy is made, so the keys will not be duplicated, but there reference counter is updated, so both keysets need to be \hyperlink{group__keyset_ga27e5c16473b02a422238c8d970db7ac8}{ks\+Del()}.

\begin{DoxyNote}{Note}
Because the key is not copied, also the pointer to the current metadata \hyperlink{group__keymeta_ga4c88342f580a4291455a801af71ce048}{key\+Next\+Meta()} will be shared.
\end{DoxyNote}

\begin{DoxyCode}
\textcolor{keywordtype}{int} f (KeySet *ks)
\{
        KeySet *c = \hyperlink{group__keyset_ga671e1aaee3ae9dc13b4834a4ddbd2c3c}{ksNew} (20, ..., \hyperlink{kdbenum_8c_a7a28fce3773b2c873c94ac80b8b4cd54}{KS\_END});
        \textcolor{comment}{// c receives keys}
        \hyperlink{group__keyset_gaba1f1dbea191f4d7e7eb3e4296ae7d5e}{ksCopy} (ks, c); \textcolor{comment}{// pass the keyset to the caller}

        \hyperlink{group__keyset_ga27e5c16473b02a422238c8d970db7ac8}{ksDel} (c);
\}       \textcolor{comment}{// caller needs to ksDel (ks)}
\end{DoxyCode}



\begin{DoxyParams}{Parameters}
{\em source} & has to be an initialized source Key\+Set or N\+U\+LL \\
\hline
{\em dest} & has to be an initialized Key\+Set where to write the keys \\
\hline
\end{DoxyParams}

\begin{DoxyRetVals}{Return values}
{\em 1} & on success \\
\hline
{\em 0} & if dest was cleared successfully (source is N\+U\+LL) \\
\hline
{\em -\/1} & on N\+U\+LL pointer \\
\hline
\end{DoxyRetVals}
\begin{DoxySeeAlso}{See also}
\hyperlink{group__keyset_ga671e1aaee3ae9dc13b4834a4ddbd2c3c}{ks\+New()}, \hyperlink{group__keyset_ga27e5c16473b02a422238c8d970db7ac8}{ks\+Del()}, \hyperlink{group__keyset_gac59e4b328245463f1451f68d5106151c}{ks\+Dup()} 

\hyperlink{group__key_ga6a12cbbe656a1ad9f41b8c681d7a2f92}{key\+Copy()} for copying keys 
\end{DoxySeeAlso}
\mbox{\Hypertarget{group__keyset_ga4287b9416912c5f2ab9c195cb74fb094}\label{group__keyset_ga4287b9416912c5f2ab9c195cb74fb094}} 
\index{Key\+Set@{Key\+Set}!ks\+Current@{ks\+Current}}
\index{ks\+Current@{ks\+Current}!Key\+Set@{Key\+Set}}
\subsubsection{\texorpdfstring{ks\+Current()}{ksCurrent()}}
{\footnotesize\ttfamily Key$\ast$ ks\+Current (\begin{DoxyParamCaption}\item[{const Key\+Set $\ast$}]{ks }\end{DoxyParamCaption})}



Return the current Key. 

The pointer is N\+U\+LL if you reached the end or after \hyperlink{group__keyset_gabe793ff51f1728e3429c84a8a9086b70}{ks\+Rewind()}.

\begin{DoxyNote}{Note}
You must not delete the key or change the key, use \hyperlink{group__keyset_gae42530b04defb772059de0600159cf69}{ks\+Pop()} if you want to delete it.
\end{DoxyNote}

\begin{DoxyParams}{Parameters}
{\em ks} & the keyset object to work with \\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{Returns}
pointer to the Key pointed by {\ttfamily ks\textquotesingle{}s} cursor 
\end{DoxyReturn}

\begin{DoxyRetVals}{Return values}
{\em 0} & on N\+U\+LL pointer \\
\hline
\end{DoxyRetVals}
\begin{DoxySeeAlso}{See also}
\hyperlink{group__keyset_ga317321c9065b5a4b3e33fe1c399bcec9}{ks\+Next()}, \hyperlink{group__keyset_gabe793ff51f1728e3429c84a8a9086b70}{ks\+Rewind()} 
\end{DoxySeeAlso}
\mbox{\Hypertarget{group__keyset_ga6b00cf82b59af4d883a9bad6cf4a4a4a}\label{group__keyset_ga6b00cf82b59af4d883a9bad6cf4a4a4a}} 
\index{Key\+Set@{Key\+Set}!ks\+Cut@{ks\+Cut}}
\index{ks\+Cut@{ks\+Cut}!Key\+Set@{Key\+Set}}
\subsubsection{\texorpdfstring{ks\+Cut()}{ksCut()}}
{\footnotesize\ttfamily Key\+Set$\ast$ ks\+Cut (\begin{DoxyParamCaption}\item[{Key\+Set $\ast$}]{ks,  }\item[{const Key $\ast$}]{cutpoint }\end{DoxyParamCaption})}



Cuts out a keyset at the cutpoint. 

Searches for the cutpoint inside the Key\+Set ks. If found it cuts out everything which is below (see \hyperlink{group__keytest_ga03332b5d97c76a4fd2640aca4762b8df}{key\+Is\+Below()}) this key. These keys will be missing in the keyset {\ttfamily ks}. Instead, they will be moved to the returned keyset. If {\ttfamily cutpoint} is not found an empty keyset is returned and {\ttfamily ks} is not changed.

The cursor will stay at the same key as it was before. If the cursor was inside the region of cut (moved) keys, the cursor will be set to the key before the cutpoint.

If you use \hyperlink{group__keyset_ga6b00cf82b59af4d883a9bad6cf4a4a4a}{ks\+Cut()} on a keyset you got from \hyperlink{group__kdb_ga28e385fd9cb7ccfe0b2f1ed2f62453a1}{kdb\+Get()} and plan to make a \hyperlink{group__kdb_ga11436b058408f83d303ca5e996832bcf}{kdb\+Set()} later, make sure that you keep all keys that should not be removed permanently. You have to keep the Key\+Set that was returned and the Key\+Set {\ttfamily ks}.

\begin{DoxyParagraph}{Example\+:}

\end{DoxyParagraph}
You have the keyset {\ttfamily ks\+:} 
\begin{DoxyItemize}
\item {\ttfamily system/mountpoint/interest} 
\item {\ttfamily system/mountpoint/interest/folder} 
\item {\ttfamily system/mountpoint/interest/folder/key1} 
\item {\ttfamily system/mountpoint/interest/folder/key2} 
\item {\ttfamily system/mountpoint/other/key1} 
\end{DoxyItemize}

When you use 
\begin{DoxyCodeInclude}
        Key * parentKey = \hyperlink{group__key_gad23c65b44bf48d773759e1f9a4d43b89}{keyNew} (\textcolor{stringliteral}{"system/mountpoint/interest"}, \hyperlink{group__key_gga91fb3178848bd682000958089abbaf40aa8adb6fcb92dec58fb19410eacfdd403}{KEY\_END});
        KDB * kdb = \hyperlink{group__kdb_ga6808defe5870f328dd17910aacbdc6ca}{kdbOpen} (parentKey);
        KeySet * ks = \hyperlink{group__keyset_ga671e1aaee3ae9dc13b4834a4ddbd2c3c}{ksNew} (0, \hyperlink{kdbenum_8c_a7a28fce3773b2c873c94ac80b8b4cd54}{KS\_END});
        \hyperlink{group__kdb_ga28e385fd9cb7ccfe0b2f1ed2f62453a1}{kdbGet} (kdb, ks, parentKey);
        KeySet * returned = \hyperlink{group__keyset_ga6b00cf82b59af4d883a9bad6cf4a4a4a}{ksCut} (ks, parentKey);
        \hyperlink{group__kdb_ga11436b058408f83d303ca5e996832bcf}{kdbSet} (kdb, ks, parentKey); \textcolor{comment}{// all keys below cutpoint are now removed}
        \hyperlink{group__kdb_gadb54dc9fda17ee07deb9444df745c96f}{kdbClose} (kdb, parentKey);
\end{DoxyCodeInclude}
 Then in {\ttfamily returned} are\+:
\begin{DoxyItemize}
\item {\ttfamily system/mountpoint/interest} 
\item {\ttfamily system/mountpoint/interest/folder} 
\item {\ttfamily system/mountpoint/interest/folder/key1} 
\item {\ttfamily system/mountpoint/interest/folder/key2} 
\end{DoxyItemize}

And in {\ttfamily ks} are\+:
\begin{DoxyItemize}
\item {\ttfamily system/mountpoint/other/key1} 
\end{DoxyItemize}

So \hyperlink{group__kdb_ga11436b058408f83d303ca5e996832bcf}{kdb\+Set()} permanently removes all keys below {\ttfamily system/mountpoint/interest}.

\begin{DoxySeeAlso}{See also}
\hyperlink{group__kdb_ga28e385fd9cb7ccfe0b2f1ed2f62453a1}{kdb\+Get()} for explanation why you might get more keys than you requested.
\end{DoxySeeAlso}
\begin{DoxyReturn}{Returns}
a new allocated Key\+Set which needs to deleted with \hyperlink{group__keyset_ga27e5c16473b02a422238c8d970db7ac8}{ks\+Del()}. The keyset consists of all keys (of the original keyset ks) below the cutpoint. If the key cutpoint exists, it will also be appended. 
\end{DoxyReturn}

\begin{DoxyRetVals}{Return values}
{\em 0} & on null pointers, no key name or allocation problems \\
\hline
\end{DoxyRetVals}

\begin{DoxyParams}{Parameters}
{\em ks} & the keyset to cut. It will be modified by removing all keys below the cutpoint. The cutpoint itself will also be removed. \\
\hline
{\em cutpoint} & the point where to cut out the keyset \\
\hline
\end{DoxyParams}
\mbox{\Hypertarget{group__keyset_ga27e5c16473b02a422238c8d970db7ac8}\label{group__keyset_ga27e5c16473b02a422238c8d970db7ac8}} 
\index{Key\+Set@{Key\+Set}!ks\+Del@{ks\+Del}}
\index{ks\+Del@{ks\+Del}!Key\+Set@{Key\+Set}}
\subsubsection{\texorpdfstring{ks\+Del()}{ksDel()}}
{\footnotesize\ttfamily int ks\+Del (\begin{DoxyParamCaption}\item[{Key\+Set $\ast$}]{ks }\end{DoxyParamCaption})}



A destructor for Key\+Set objects. 

Cleans all internal dynamic attributes, decrement all reference pointers to all keys and then \hyperlink{group__key_ga3df95bbc2494e3e6703ece5639be5bb1}{key\+Del()} all contained Keys, and elektra\+Free ()s the release the Key\+Set object memory (that was previously allocated by \hyperlink{group__keyset_ga671e1aaee3ae9dc13b4834a4ddbd2c3c}{ks\+New()}).


\begin{DoxyParams}{Parameters}
{\em ks} & the keyset object to work with \\
\hline
\end{DoxyParams}

\begin{DoxyRetVals}{Return values}
{\em 0} & when the keyset was freed \\
\hline
{\em -\/1} & on null pointer \\
\hline
\end{DoxyRetVals}
\begin{DoxySeeAlso}{See also}
\hyperlink{group__keyset_ga671e1aaee3ae9dc13b4834a4ddbd2c3c}{ks\+New()} 
\end{DoxySeeAlso}
\mbox{\Hypertarget{group__keyset_gac59e4b328245463f1451f68d5106151c}\label{group__keyset_gac59e4b328245463f1451f68d5106151c}} 
\index{Key\+Set@{Key\+Set}!ks\+Dup@{ks\+Dup}}
\index{ks\+Dup@{ks\+Dup}!Key\+Set@{Key\+Set}}
\subsubsection{\texorpdfstring{ks\+Dup()}{ksDup()}}
{\footnotesize\ttfamily Key\+Set$\ast$ ks\+Dup (\begin{DoxyParamCaption}\item[{const Key\+Set $\ast$}]{source }\end{DoxyParamCaption})}



Return a duplicate of a keyset. 

Objects created with \hyperlink{group__keyset_gac59e4b328245463f1451f68d5106151c}{ks\+Dup()} must be destroyed with \hyperlink{group__keyset_ga27e5c16473b02a422238c8d970db7ac8}{ks\+Del()}.

Memory will be allocated as needed for dynamic properties, so you need to \hyperlink{group__keyset_ga27e5c16473b02a422238c8d970db7ac8}{ks\+Del()} the returned pointer.

A flat copy is made, so the keys will not be duplicated, but there reference counter is updated, so both keysets need \hyperlink{group__keyset_ga27e5c16473b02a422238c8d970db7ac8}{ks\+Del()}.


\begin{DoxyParams}{Parameters}
{\em source} & has to be an initialized source Key\+Set \\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{Returns}
a flat copy of source on success 
\end{DoxyReturn}

\begin{DoxyRetVals}{Return values}
{\em 0} & on N\+U\+LL pointer \\
\hline
\end{DoxyRetVals}
\begin{DoxySeeAlso}{See also}
\hyperlink{group__keyset_ga671e1aaee3ae9dc13b4834a4ddbd2c3c}{ks\+New()}, \hyperlink{group__keyset_ga27e5c16473b02a422238c8d970db7ac8}{ks\+Del()} 

\hyperlink{group__key_gae6ec6a60cc4b8c1463fa08623d056ce3}{key\+Dup()} for \hyperlink{group__key}{Key} duplication 
\end{DoxySeeAlso}
\mbox{\Hypertarget{group__keyset_gaffe507ab9281c322eb16c3e992075d29}\label{group__keyset_gaffe507ab9281c322eb16c3e992075d29}} 
\index{Key\+Set@{Key\+Set}!ks\+Get\+Cursor@{ks\+Get\+Cursor}}
\index{ks\+Get\+Cursor@{ks\+Get\+Cursor}!Key\+Set@{Key\+Set}}
\subsubsection{\texorpdfstring{ks\+Get\+Cursor()}{ksGetCursor()}}
{\footnotesize\ttfamily cursor\+\_\+t ks\+Get\+Cursor (\begin{DoxyParamCaption}\item[{const Key\+Set $\ast$}]{ks }\end{DoxyParamCaption})}



Get the Key\+Set internal cursor. 

Use it to get the cursor of the actual position.

\begin{DoxyWarning}{Warning}
Cursors are getting invalid when the key was \hyperlink{group__keyset_gae42530b04defb772059de0600159cf69}{ks\+Pop()}ed or \hyperlink{group__keyset_gaa34fc43a081e6b01e4120daa6c112004}{ks\+Lookup()} with K\+D\+B\+\_\+\+O\+\_\+\+P\+OP was used.
\end{DoxyWarning}
\hypertarget{group__keyset_readahead}{}\subsection{Read ahead}\label{group__keyset_readahead}
With the cursors it is possible to read ahead in a keyset\+:


\begin{DoxyCode}
cursor\_t jump;
\hyperlink{group__keyset_gabe793ff51f1728e3429c84a8a9086b70}{ksRewind} (ks);
\textcolor{keywordflow}{while} ((key = \hyperlink{group__keymeta_ga4c88342f580a4291455a801af71ce048}{keyNextMeta} (ks))!=0)
\{
        \textcolor{comment}{// now mark this key}
        jump = \hyperlink{group__keyset_gaffe507ab9281c322eb16c3e992075d29}{ksGetCursor}(ks);

        \textcolor{comment}{//code..}
        \hyperlink{group__keymeta_ga4c88342f580a4291455a801af71ce048}{keyNextMeta} (ks); \textcolor{comment}{// now browse on}
        \textcolor{comment}{// use ksCurrent(ks) to check the keys}
        \textcolor{comment}{//code..}

        \textcolor{comment}{// jump back to the position marked before}
        \hyperlink{group__keyset_gad94c9ffaa3e8034564c0712fd407c345}{ksSetCursor}(ks, jump);
\}
\end{DoxyCode}
\hypertarget{group__keyset_restore}{}\subsection{Restoring state}\label{group__keyset_restore}
It can also be used to restore the state of a keyset in a function


\begin{DoxyCode}
\textcolor{keywordtype}{int} f (KeySet *ks)
\{
        cursor\_t state = \hyperlink{group__keyset_gaffe507ab9281c322eb16c3e992075d29}{ksGetCursor}(ks);

        \textcolor{comment}{// work with keyset}

        \textcolor{comment}{// now bring the keyset to the state before}
        \hyperlink{group__keyset_gad94c9ffaa3e8034564c0712fd407c345}{ksSetCursor} (ks, state);
\}
\end{DoxyCode}


It is of course possible to make the Key\+Set const and cast its const away to set the cursor. Another way to achieve the same is to \hyperlink{group__keyset_gac59e4b328245463f1451f68d5106151c}{ks\+Dup()} the keyset, but it is not as efficient.

An invalid cursor will be returned directly after \hyperlink{group__keyset_gabe793ff51f1728e3429c84a8a9086b70}{ks\+Rewind()}. When you set an invalid cursor \hyperlink{group__keyset_ga4287b9416912c5f2ab9c195cb74fb094}{ks\+Current()} is 0 and \hyperlink{group__keyset_ga317321c9065b5a4b3e33fe1c399bcec9}{ks\+Next()} == \hyperlink{group__keyset_gae7dbf3aef70e67b5328475eb3d1f92f5}{ks\+Head()}.

\begin{DoxyNote}{Note}
Only use a cursor for the same keyset which it was made for.
\end{DoxyNote}

\begin{DoxyParams}{Parameters}
{\em ks} & the keyset object to work with \\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{Returns}
a valid cursor on success 

an invalid cursor on N\+U\+LL pointer or after \hyperlink{group__keyset_gabe793ff51f1728e3429c84a8a9086b70}{ks\+Rewind()} 
\end{DoxyReturn}
\begin{DoxySeeAlso}{See also}
\hyperlink{group__keyset_ga317321c9065b5a4b3e33fe1c399bcec9}{ks\+Next()}, \hyperlink{group__keyset_gad94c9ffaa3e8034564c0712fd407c345}{ks\+Set\+Cursor()} 
\end{DoxySeeAlso}
\mbox{\Hypertarget{group__keyset_ga7474ad6b0a0fa969dbdf267ba5770eee}\label{group__keyset_ga7474ad6b0a0fa969dbdf267ba5770eee}} 
\index{Key\+Set@{Key\+Set}!ks\+Get\+Size@{ks\+Get\+Size}}
\index{ks\+Get\+Size@{ks\+Get\+Size}!Key\+Set@{Key\+Set}}
\subsubsection{\texorpdfstring{ks\+Get\+Size()}{ksGetSize()}}
{\footnotesize\ttfamily ssize\+\_\+t ks\+Get\+Size (\begin{DoxyParamCaption}\item[{const Key\+Set $\ast$}]{ks }\end{DoxyParamCaption})}



Return the number of keys that {\ttfamily ks} contains. 


\begin{DoxyParams}{Parameters}
{\em ks} & the keyset object to work with \\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{Returns}
the number of keys that {\ttfamily ks} contains. 
\end{DoxyReturn}

\begin{DoxyRetVals}{Return values}
{\em -\/1} & on N\+U\+LL pointer \\
\hline
\end{DoxyRetVals}
\begin{DoxySeeAlso}{See also}
ks\+New(0, K\+S\+\_\+\+E\+N\+D), \hyperlink{group__keyset_ga27e5c16473b02a422238c8d970db7ac8}{ks\+Del()} 
\end{DoxySeeAlso}
\mbox{\Hypertarget{group__keyset_gae7dbf3aef70e67b5328475eb3d1f92f5}\label{group__keyset_gae7dbf3aef70e67b5328475eb3d1f92f5}} 
\index{Key\+Set@{Key\+Set}!ks\+Head@{ks\+Head}}
\index{ks\+Head@{ks\+Head}!Key\+Set@{Key\+Set}}
\subsubsection{\texorpdfstring{ks\+Head()}{ksHead()}}
{\footnotesize\ttfamily Key$\ast$ ks\+Head (\begin{DoxyParamCaption}\item[{const Key\+Set $\ast$}]{ks }\end{DoxyParamCaption})}



Return the first key in the Key\+Set. 

The Key\+Sets cursor will not be affected.

If \hyperlink{group__keyset_ga4287b9416912c5f2ab9c195cb74fb094}{ks\+Current()}==\hyperlink{group__keyset_gae7dbf3aef70e67b5328475eb3d1f92f5}{ks\+Head()} you know you are on the first key.


\begin{DoxyParams}{Parameters}
{\em ks} & the keyset object to work with \\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{Returns}
the first Key of a keyset 
\end{DoxyReturn}

\begin{DoxyRetVals}{Return values}
{\em 0} & on N\+U\+LL pointer or empty keyset \\
\hline
\end{DoxyRetVals}
\begin{DoxySeeAlso}{See also}
\hyperlink{group__keyset_gadca442c4ab43cf532b15091d7711559e}{ks\+Tail()} for the last \hyperlink{group__key}{Key} 

\hyperlink{group__keyset_gabe793ff51f1728e3429c84a8a9086b70}{ks\+Rewind()}, \hyperlink{group__keyset_ga4287b9416912c5f2ab9c195cb74fb094}{ks\+Current()} and \hyperlink{group__keyset_ga317321c9065b5a4b3e33fe1c399bcec9}{ks\+Next()} for iterating over the \hyperlink{group__keyset}{Key\+Set} 
\end{DoxySeeAlso}
\mbox{\Hypertarget{group__keyset_gaa34fc43a081e6b01e4120daa6c112004}\label{group__keyset_gaa34fc43a081e6b01e4120daa6c112004}} 
\index{Key\+Set@{Key\+Set}!ks\+Lookup@{ks\+Lookup}}
\index{ks\+Lookup@{ks\+Lookup}!Key\+Set@{Key\+Set}}
\subsubsection{\texorpdfstring{ks\+Lookup()}{ksLookup()}}
{\footnotesize\ttfamily Key$\ast$ ks\+Lookup (\begin{DoxyParamCaption}\item[{Key\+Set $\ast$}]{ks,  }\item[{Key $\ast$}]{key,  }\item[{\hyperlink{group__keyset_ga98a3d6a4016c9dad9cbd1a99a9c2a45a}{option\+\_\+t}}]{options }\end{DoxyParamCaption})}



Look for a Key contained in {\ttfamily ks} that matches the name of the {\ttfamily key}. 

\begin{DoxyNote}{Note}
Applications should only use \hyperlink{group__keyset_gaa34fc43a081e6b01e4120daa6c112004}{ks\+Lookup()} with cascading keys (key name starting with {\ttfamily /}). Furthermore, a lookup should be done for every key (also when iterating over keys) so that the specifications are honored correctly. Keys of all namespaces need to be present so that \hyperlink{group__keyset_gaa34fc43a081e6b01e4120daa6c112004}{ks\+Lookup()} can work correctly, so make sure to also use \hyperlink{group__kdb_ga28e385fd9cb7ccfe0b2f1ed2f62453a1}{kdb\+Get()} with a cascading key.
\end{DoxyNote}
{\ttfamily \hyperlink{group__keyset_gaa34fc43a081e6b01e4120daa6c112004}{ks\+Lookup()}} is designed to let you work with a Key\+Set containing all keys of the application. The idea is to fully \hyperlink{group__kdb_ga28e385fd9cb7ccfe0b2f1ed2f62453a1}{kdb\+Get()} the whole configuration of your application and process it all at once with many {\ttfamily \hyperlink{group__keyset_gaa34fc43a081e6b01e4120daa6c112004}{ks\+Lookup()}}.

This function is efficient (at least using binary search). Together with \hyperlink{group__kdb_ga28e385fd9cb7ccfe0b2f1ed2f62453a1}{kdb\+Get()} which can you load the whole configuration you can write very effective but short code for configuration\+:


\begin{DoxyCodeInclude}
Key * key = \hyperlink{group__key_gad23c65b44bf48d773759e1f9a4d43b89}{keyNew} (\textcolor{stringliteral}{"/sw/tests/myapp/#0/current/"},  \hyperlink{group__key_gga91fb3178848bd682000958089abbaf40aa8adb6fcb92dec58fb19410eacfdd403}{KEY\_END});
KDB * handle = \hyperlink{group__kdb_ga6808defe5870f328dd17910aacbdc6ca}{kdbOpen} (key);
\hyperlink{group__kdb_ga28e385fd9cb7ccfe0b2f1ed2f62453a1}{kdbGet} (handle, myConfig, key);
Key * result = \hyperlink{group__keyset_gad2e30fb6d4739d917c5abb2ac2f9c1a1}{ksLookupByName} (myConfig, \textcolor{stringliteral}{"/sw/tests/myapp/#0/current/testkey1"}, 0);
\end{DoxyCodeInclude}
 This is the way programs should get their configuration and search after the values. It is guaranteed that more namespaces can be added easily and that all values can be set by admin and user. Furthermore, using the kdb-\/tool, it is possible to introspect which values an application will get (by doing the same cascading lookup).

If found, {\ttfamily ks} internal cursor will be positioned in the matched key (also accessible by \hyperlink{group__keyset_ga4287b9416912c5f2ab9c195cb74fb094}{ks\+Current()}), and a pointer to the Key is returned. If not found, {\ttfamily ks} internal cursor will not move, and a N\+U\+LL pointer is returned.

Cascading lookups will by default search in all namespaces (proc/, dir/, user/ and system/), but will also correctly consider the specification (=metadata) in spec/\+:


\begin{DoxyItemize}
\item {\ttfamily override/\#} will make sure that another key is considered before
\item {\ttfamily namespace/\#} will change the number and/or order in which the namespaces are searched
\item {\ttfamily fallback/\#} will search for other keys when the other possibilities up to now were not successful
\item {\ttfamily default} to return the given value when not even {\ttfamily fallback} keys were found.
\end{DoxyItemize}

\begin{DoxyNote}{Note}
override and fallback work recursively, while default does not.
\end{DoxyNote}
This process is very flexible, but it would be boring to manually follow all this links to find out which key will be taken in the end. Use {\ttfamily kdb get -\/v} to trace the keys.

\begin{DoxyParagraph}{K\+D\+B\+\_\+\+O\+\_\+\+P\+OP}
When \hyperlink{group__keyset_gga98a3d6a4016c9dad9cbd1a99a9c2a45aa52fb5f2cc86773d393da62bebebf7984}{K\+D\+B\+\_\+\+O\+\_\+\+P\+OP} is set the key which was found will be \hyperlink{group__keyset_gae42530b04defb772059de0600159cf69}{ks\+Pop()}ed. \hyperlink{group__keyset_ga4287b9416912c5f2ab9c195cb74fb094}{ks\+Current()} will not be changed, only iff \hyperlink{group__keyset_ga4287b9416912c5f2ab9c195cb74fb094}{ks\+Current()} is the searched key, then the keyset will be \hyperlink{group__keyset_gabe793ff51f1728e3429c84a8a9086b70}{ks\+Rewind()}ed.
\end{DoxyParagraph}
\begin{DoxyNote}{Note}
Like in \hyperlink{group__keyset_gae42530b04defb772059de0600159cf69}{ks\+Pop()} the popped key always needs to be \hyperlink{group__key_ga3df95bbc2494e3e6703ece5639be5bb1}{key\+Del()} afterwards, even if it is appended to another keyset.
\end{DoxyNote}
\begin{DoxyWarning}{Warning}
All cursors on the keyset will be invalid iff you use \hyperlink{group__keyset_gga98a3d6a4016c9dad9cbd1a99a9c2a45aa52fb5f2cc86773d393da62bebebf7984}{K\+D\+B\+\_\+\+O\+\_\+\+P\+OP}, so don\textquotesingle{}t use this if you rely on a cursor, see \hyperlink{group__keyset_gaffe507ab9281c322eb16c3e992075d29}{ks\+Get\+Cursor()}.
\end{DoxyWarning}
The invalidation of cursors does not matter if you use multiple keysets, e.\+g. by using \hyperlink{group__keyset_gac59e4b328245463f1451f68d5106151c}{ks\+Dup()}. E.\+g., to separate \hyperlink{group__keyset_gaa34fc43a081e6b01e4120daa6c112004}{ks\+Lookup()} with \hyperlink{group__keyset_gga98a3d6a4016c9dad9cbd1a99a9c2a45aa52fb5f2cc86773d393da62bebebf7984}{K\+D\+B\+\_\+\+O\+\_\+\+P\+OP} and \hyperlink{group__keyset_gaa5a1d467a4d71041edce68ea7748ce45}{ks\+Append\+Key()}\+:


\begin{DoxyCodeInclude}
\textcolor{keywordtype}{void} f (KeySet * iterator, KeySet * lookup)
\{
        KeySet * append = \hyperlink{group__keyset_ga671e1aaee3ae9dc13b4834a4ddbd2c3c}{ksNew} (\hyperlink{group__keyset_ga7474ad6b0a0fa969dbdf267ba5770eee}{ksGetSize} (lookup), \hyperlink{kdbenum_8c_a7a28fce3773b2c873c94ac80b8b4cd54}{KS\_END});
        Key * current;

        \hyperlink{group__keyset_gabe793ff51f1728e3429c84a8a9086b70}{ksRewind} (iterator);
        \textcolor{keywordflow}{while} ((current = \hyperlink{group__keyset_ga317321c9065b5a4b3e33fe1c399bcec9}{ksNext} (iterator)))
        \{
                Key * key = \hyperlink{group__keyset_gaa34fc43a081e6b01e4120daa6c112004}{ksLookup} (lookup, current, \hyperlink{group__keyset_gga98a3d6a4016c9dad9cbd1a99a9c2a45aa52fb5f2cc86773d393da62bebebf7984}{KDB\_O\_POP});
                \textcolor{comment}{// do something...}
                \hyperlink{group__keyset_gaa5a1d467a4d71041edce68ea7748ce45}{ksAppendKey} (append, key); \textcolor{comment}{// now append it to append, not lookup!}
                \hyperlink{group__key_ga3df95bbc2494e3e6703ece5639be5bb1}{keyDel} (key);                \textcolor{comment}{// make sure to ALWAYS delete poped keys.}
        \}
        \hyperlink{group__keyset_ga21eb9c3a14a604ee3a8bdc779232e7b7}{ksAppend} (lookup, append);
        \textcolor{comment}{// now lookup needs to be sorted only once, append never}
        \hyperlink{group__keyset_ga27e5c16473b02a422238c8d970db7ac8}{ksDel} (append);
\}
\end{DoxyCodeInclude}
 This is also a nice example how a complete application with \hyperlink{group__keyset_gaa34fc43a081e6b01e4120daa6c112004}{ks\+Lookup()} can look like.

\begin{DoxyParagraph}{K\+D\+B\+\_\+\+O\+\_\+\+D\+EL}
Passing \hyperlink{group__keyset_gga98a3d6a4016c9dad9cbd1a99a9c2a45aa66a5380c120f25f28f49848c4a863ead}{K\+D\+B\+\_\+\+O\+\_\+\+D\+EL} will cause the deletion of the parameter {\ttfamily key} using \hyperlink{group__key_ga3df95bbc2494e3e6703ece5639be5bb1}{key\+Del()}.
\end{DoxyParagraph}
\begin{DoxyParagraph}{K\+D\+B\+\_\+\+O\+\_\+\+N\+O\+A\+LL (deprecated)}
When \hyperlink{group__keyset_gga98a3d6a4016c9dad9cbd1a99a9c2a45aae8dd1961707e7d0c27228a3f98b0a94d}{K\+D\+B\+\_\+\+O\+\_\+\+N\+O\+A\+LL} is set the keyset will be only searched from \hyperlink{group__keyset_ga4287b9416912c5f2ab9c195cb74fb094}{ks\+Current()} to \hyperlink{group__keyset_gadca442c4ab43cf532b15091d7711559e}{ks\+Tail()}. You need to \hyperlink{group__keyset_gabe793ff51f1728e3429c84a8a9086b70}{ks\+Rewind()} the keyset yourself. \hyperlink{group__keyset_ga4287b9416912c5f2ab9c195cb74fb094}{ks\+Current()} is always set properly after searching a key, so you can go on searching another key after the found key. ~\newline
When \hyperlink{group__keyset_gga98a3d6a4016c9dad9cbd1a99a9c2a45aae8dd1961707e7d0c27228a3f98b0a94d}{K\+D\+B\+\_\+\+O\+\_\+\+N\+O\+A\+LL} is not set the cursor will stay untouched and all keys are considered. A much more efficient binary search will be used then.
\end{DoxyParagraph}
\begin{DoxyParagraph}{K\+D\+B\+\_\+\+O\+\_\+\+W\+I\+T\+H\+O\+W\+N\+ER (deprecated)}
Also consider correct owner (needs \hyperlink{group__keyset_gga98a3d6a4016c9dad9cbd1a99a9c2a45aae8dd1961707e7d0c27228a3f98b0a94d}{K\+D\+B\+\_\+\+O\+\_\+\+N\+O\+A\+LL}).
\end{DoxyParagraph}
\begin{DoxyParagraph}{K\+D\+B\+\_\+\+O\+\_\+\+N\+O\+C\+A\+SE (deprecated)}
Lookup ignoring case (needs \hyperlink{group__keyset_gga98a3d6a4016c9dad9cbd1a99a9c2a45aae8dd1961707e7d0c27228a3f98b0a94d}{K\+D\+B\+\_\+\+O\+\_\+\+N\+O\+A\+LL}).
\end{DoxyParagraph}
\begin{DoxyParagraph}{Hybrid search}
When Elektra is compiled with {\ttfamily E\+N\+A\+B\+L\+E\+\_\+\+O\+P\+T\+I\+M\+I\+Z\+A\+T\+I\+O\+NS=ON} a hybrid search decides dynamically between the binary search and the \href{https://master.libelektra.org/doc/dev/data-structures.md#order-preserving-minimal-perfect-hash-map-aka-opmphm}{\tt O\+P\+M\+P\+HM}. The hybrid search can be overruled by passing \hyperlink{group__proposal_gga93673533c4c8eb1fdfca76b98c5f49b0afe9f6ff6e374540baf600a918b07ee6e}{K\+D\+B\+\_\+\+O\+\_\+\+O\+P\+M\+P\+HM} or \hyperlink{group__proposal_gga93673533c4c8eb1fdfca76b98c5f49b0ac67a43bd273203575090d26010f6c995}{K\+D\+B\+\_\+\+O\+\_\+\+B\+I\+N\+S\+E\+A\+R\+CH} in the options to \hyperlink{group__keyset_gaa34fc43a081e6b01e4120daa6c112004}{ks\+Lookup()}.
\end{DoxyParagraph}

\begin{DoxyParams}{Parameters}
{\em ks} & where to look for \\
\hline
{\em key} & the key object you are looking for \\
\hline
{\em options} & of type \hyperlink{group__keyset_ga98a3d6a4016c9dad9cbd1a99a9c2a45a}{option\+\_\+t} with some {\ttfamily K\+D\+B\+\_\+\+O\+\_\+$\ast$} option bits as explained above \\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{Returns}
pointer to the Key found, 0 otherwise 
\end{DoxyReturn}

\begin{DoxyRetVals}{Return values}
{\em 0} & on N\+U\+LL pointers \\
\hline
\end{DoxyRetVals}
\begin{DoxySeeAlso}{See also}
\hyperlink{group__keyset_gad2e30fb6d4739d917c5abb2ac2f9c1a1}{ks\+Lookup\+By\+Name()} to search by a name given by a string 

\hyperlink{group__keyset_ga4287b9416912c5f2ab9c195cb74fb094}{ks\+Current()}, \hyperlink{group__keyset_gabe793ff51f1728e3429c84a8a9086b70}{ks\+Rewind()}, \hyperlink{group__keyset_ga317321c9065b5a4b3e33fe1c399bcec9}{ks\+Next()} for iterating over a \hyperlink{group__keyset}{Key\+Set} 
\end{DoxySeeAlso}
\mbox{\Hypertarget{group__keyset_gad2e30fb6d4739d917c5abb2ac2f9c1a1}\label{group__keyset_gad2e30fb6d4739d917c5abb2ac2f9c1a1}} 
\index{Key\+Set@{Key\+Set}!ks\+Lookup\+By\+Name@{ks\+Lookup\+By\+Name}}
\index{ks\+Lookup\+By\+Name@{ks\+Lookup\+By\+Name}!Key\+Set@{Key\+Set}}
\subsubsection{\texorpdfstring{ks\+Lookup\+By\+Name()}{ksLookupByName()}}
{\footnotesize\ttfamily Key$\ast$ ks\+Lookup\+By\+Name (\begin{DoxyParamCaption}\item[{Key\+Set $\ast$}]{ks,  }\item[{const char $\ast$}]{name,  }\item[{\hyperlink{group__keyset_ga98a3d6a4016c9dad9cbd1a99a9c2a45a}{option\+\_\+t}}]{options }\end{DoxyParamCaption})}



Convenience method to look for a Key contained in {\ttfamily ks} that matches {\ttfamily name}. 

\begin{DoxySeeAlso}{See also}
\hyperlink{group__keyset_gaa34fc43a081e6b01e4120daa6c112004}{ks\+Lookup()} for explanation of the functionality and example.
\end{DoxySeeAlso}

\begin{DoxyParams}{Parameters}
{\em ks} & where to look for \\
\hline
{\em name} & key name you are looking for \\
\hline
{\em options} & some {\ttfamily K\+D\+B\+\_\+\+O\+\_\+$\ast$} option bits\+:
\begin{DoxyItemize}
\item {\ttfamily K\+D\+B\+\_\+\+O\+\_\+\+P\+OP} ~\newline
 Pop the key which was found.
\item See \hyperlink{group__keyset_gaa34fc43a081e6b01e4120daa6c112004}{ks\+Lookup()} for others
\end{DoxyItemize}\\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{Returns}
pointer to the Key found, 0 otherwise 
\end{DoxyReturn}

\begin{DoxyRetVals}{Return values}
{\em 0} & on N\+U\+LL pointers \\
\hline
\end{DoxyRetVals}
\begin{DoxySeeAlso}{See also}
\hyperlink{group__keyset_gaa34fc43a081e6b01e4120daa6c112004}{ks\+Lookup()} to search with a given \hyperlink{group__key}{Key} 

\hyperlink{group__keyset_ga4287b9416912c5f2ab9c195cb74fb094}{ks\+Current()}, \hyperlink{group__keyset_gabe793ff51f1728e3429c84a8a9086b70}{ks\+Rewind()}, \hyperlink{group__keyset_ga317321c9065b5a4b3e33fe1c399bcec9}{ks\+Next()} 
\end{DoxySeeAlso}
\mbox{\Hypertarget{group__keyset_ga8f210432e664d8ba06d7d55a2aba2d0f}\label{group__keyset_ga8f210432e664d8ba06d7d55a2aba2d0f}} 
\index{Key\+Set@{Key\+Set}!ks\+Need\+Sync@{ks\+Need\+Sync}}
\index{ks\+Need\+Sync@{ks\+Need\+Sync}!Key\+Set@{Key\+Set}}
\subsubsection{\texorpdfstring{ks\+Need\+Sync()}{ksNeedSync()}}
{\footnotesize\ttfamily int ks\+Need\+Sync (\begin{DoxyParamCaption}\item[{const Key\+Set $\ast$}]{ks }\end{DoxyParamCaption})}



Checks if Key\+Set needs sync. 

When keys are changed this is reflected into \hyperlink{group__keytest_gaf247df0de7aca04b32ef80e39ef12950}{key\+Need\+Sync()}.

But when keys are popped from a keyset this can\textquotesingle{}t be seen by looking at the individual keys.

\hyperlink{group__keyset_ga8f210432e664d8ba06d7d55a2aba2d0f}{ks\+Need\+Sync()} allows the backends to know if a key was popped from the keyset to know that this keyset needs to be written out.

\begin{DoxyRefDesc}{Deprecated}
\item[\hyperlink{deprecated__deprecated000011}{Deprecated}]Backends now work differently and do not rely on this information.\end{DoxyRefDesc}



\begin{DoxyParams}{Parameters}
{\em ks} & the keyset to work with \\
\hline
\end{DoxyParams}

\begin{DoxyRetVals}{Return values}
{\em -\/1} & on null keyset \\
\hline
{\em 0} & if it does not need sync \\
\hline
{\em 1} & if it needs sync \\
\hline
\end{DoxyRetVals}
\mbox{\Hypertarget{group__keyset_ga671e1aaee3ae9dc13b4834a4ddbd2c3c}\label{group__keyset_ga671e1aaee3ae9dc13b4834a4ddbd2c3c}} 
\index{Key\+Set@{Key\+Set}!ks\+New@{ks\+New}}
\index{ks\+New@{ks\+New}!Key\+Set@{Key\+Set}}
\subsubsection{\texorpdfstring{ks\+New()}{ksNew()}}
{\footnotesize\ttfamily Key\+Set$\ast$ ks\+New (\begin{DoxyParamCaption}\item[{size\+\_\+t}]{alloc,  }\item[{}]{... }\end{DoxyParamCaption})}



Allocate, initialize and return a new Key\+Set object. 

Objects created with \hyperlink{group__keyset_ga671e1aaee3ae9dc13b4834a4ddbd2c3c}{ks\+New()} must be destroyed with \hyperlink{group__keyset_ga27e5c16473b02a422238c8d970db7ac8}{ks\+Del()}.

You can use a arbitrary long list of parameters to preload the keyset with a list of keys. Either your first and only parameter is 0 or your last parameter must be K\+E\+Y\+\_\+\+E\+ND.

So, terminate with ks\+New(0, K\+S\+\_\+\+E\+N\+D) or ks\+New(20, ..., K\+S\+\_\+\+E\+ND)

\begin{DoxyWarning}{Warning}
Never use ks\+New(0, key\+New(...), K\+S\+\_\+\+E\+ND). If the first parameter is 0, other arguments are ignored.
\end{DoxyWarning}
For most uses


\begin{DoxyCodeInclude}
KeySet * keys = \hyperlink{group__keyset_ga671e1aaee3ae9dc13b4834a4ddbd2c3c}{ksNew} (0, \hyperlink{kdbenum_8c_a7a28fce3773b2c873c94ac80b8b4cd54}{KS\_END});
\textcolor{comment}{// work with it}
\hyperlink{group__keyset_ga27e5c16473b02a422238c8d970db7ac8}{ksDel} (keys);
\end{DoxyCodeInclude}
 will be fine, the alloc size will be 16, defined in \hyperlink{kdbprivate_8h}{kdbprivate.\+h}. The alloc size will be doubled whenever size reaches alloc size, so it also performs well with large keysets.

But if you have any clue how large your keyset may be you should read the next statements.

If you want a keyset with length 15 (because you know of your application that you only need up to 15 keys), use\+:


\begin{DoxyCodeInclude}
KeySet * keys = \hyperlink{group__keyset_ga671e1aaee3ae9dc13b4834a4ddbd2c3c}{ksNew} (15, \hyperlink{group__key_gad23c65b44bf48d773759e1f9a4d43b89}{keyNew} (\textcolor{stringliteral}{"user/sw/org/app/#0/current/fixedConfiguration/key01"}, 
      \hyperlink{group__key_gga91fb3178848bd682000958089abbaf40ac66e4a49d09212b79f5754ca6db5bd2e}{KEY\_VALUE}, \textcolor{stringliteral}{"value01"}, 0),
                       \hyperlink{group__key_gad23c65b44bf48d773759e1f9a4d43b89}{keyNew} (\textcolor{stringliteral}{"user/sw/org/app/#0/current/fixedConfiguration/key02"}, 
      \hyperlink{group__key_gga91fb3178848bd682000958089abbaf40ac66e4a49d09212b79f5754ca6db5bd2e}{KEY\_VALUE}, \textcolor{stringliteral}{"value02"}, 0),
                       \hyperlink{group__key_gad23c65b44bf48d773759e1f9a4d43b89}{keyNew} (\textcolor{stringliteral}{"user/sw/org/app/#0/current/fixedConfiguration/key03"}, 
      \hyperlink{group__key_gga91fb3178848bd682000958089abbaf40ac66e4a49d09212b79f5754ca6db5bd2e}{KEY\_VALUE}, \textcolor{stringliteral}{"value03"}, 0),
                       \textcolor{comment}{// ...}
                       \hyperlink{group__key_gad23c65b44bf48d773759e1f9a4d43b89}{keyNew} (\textcolor{stringliteral}{"user/sw/org/app/#0/current/fixedConfiguration/key15"}, 
      \hyperlink{group__key_gga91fb3178848bd682000958089abbaf40ac66e4a49d09212b79f5754ca6db5bd2e}{KEY\_VALUE}, \textcolor{stringliteral}{"value15"}, 0), \hyperlink{kdbenum_8c_a7a28fce3773b2c873c94ac80b8b4cd54}{KS\_END});
\textcolor{comment}{// work with it}
\hyperlink{group__keyset_ga27e5c16473b02a422238c8d970db7ac8}{ksDel} (keys);
\end{DoxyCodeInclude}
 If you start having 3 keys, and your application needs approximately 200 up to 500 keys, you can use\+:


\begin{DoxyCodeInclude}
KeySet * config = \hyperlink{group__keyset_ga671e1aaee3ae9dc13b4834a4ddbd2c3c}{ksNew} (500, \hyperlink{group__key_gad23c65b44bf48d773759e1f9a4d43b89}{keyNew} (\textcolor{stringliteral}{"user/sw/org/app/#0/current/fixedConfiguration/key1"}, 
      \hyperlink{group__key_gga91fb3178848bd682000958089abbaf40ac66e4a49d09212b79f5754ca6db5bd2e}{KEY\_VALUE}, \textcolor{stringliteral}{"value1"}, 0),
                         \hyperlink{group__key_gad23c65b44bf48d773759e1f9a4d43b89}{keyNew} (\textcolor{stringliteral}{"user/sw/org/app/#0/current/fixedConfiguration/key2"}, 
      \hyperlink{group__key_gga91fb3178848bd682000958089abbaf40ac66e4a49d09212b79f5754ca6db5bd2e}{KEY\_VALUE}, \textcolor{stringliteral}{"value2"}, 0),
                         \hyperlink{group__key_gad23c65b44bf48d773759e1f9a4d43b89}{keyNew} (\textcolor{stringliteral}{"user/sw/org/app/#0/current/fixedConfiguration/key3"}, 
      \hyperlink{group__key_gga91fb3178848bd682000958089abbaf40ac66e4a49d09212b79f5754ca6db5bd2e}{KEY\_VALUE}, \textcolor{stringliteral}{"value3"}, 0),
                         \hyperlink{kdbenum_8c_a7a28fce3773b2c873c94ac80b8b4cd54}{KS\_END}); \textcolor{comment}{// don't forget the KS\_END at the end!}
\textcolor{comment}{// work with it}
\hyperlink{group__keyset_ga27e5c16473b02a422238c8d970db7ac8}{ksDel} (config);
\end{DoxyCodeInclude}
 Alloc size is 500, the size of the keyset will be 3 after ks\+New. This means the keyset will reallocate when appending more than 497 keys.

The main benefit of taking a list of variant length parameters is to be able to have one C-\/\+Statement for any possible Key\+Set. If you prefer, you can always create an empty Key\+Set and use \hyperlink{group__keyset_gaa5a1d467a4d71041edce68ea7748ce45}{ks\+Append\+Key()}.

\begin{DoxyPostcond}{Postcondition}
the keyset is rewinded properly
\end{DoxyPostcond}
\begin{DoxySeeAlso}{See also}
\hyperlink{group__keyset_ga27e5c16473b02a422238c8d970db7ac8}{ks\+Del()} to free the \hyperlink{group__keyset}{Key\+Set} afterwards 

\hyperlink{group__keyset_gac59e4b328245463f1451f68d5106151c}{ks\+Dup()} to duplicate an existing \hyperlink{group__keyset}{Key\+Set} 

\hyperlink{group__keyset_gaa5a1d467a4d71041edce68ea7748ce45}{ks\+Append\+Key()} to append individual keys 
\end{DoxySeeAlso}

\begin{DoxyParams}{Parameters}
{\em alloc} & gives a hint for the size how many Keys may be stored initially \\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{Returns}
a ready to use Key\+Set object 
\end{DoxyReturn}

\begin{DoxyRetVals}{Return values}
{\em 0} & on memory error \\
\hline
\end{DoxyRetVals}
\mbox{\Hypertarget{group__keyset_ga317321c9065b5a4b3e33fe1c399bcec9}\label{group__keyset_ga317321c9065b5a4b3e33fe1c399bcec9}} 
\index{Key\+Set@{Key\+Set}!ks\+Next@{ks\+Next}}
\index{ks\+Next@{ks\+Next}!Key\+Set@{Key\+Set}}
\subsubsection{\texorpdfstring{ks\+Next()}{ksNext()}}
{\footnotesize\ttfamily Key$\ast$ ks\+Next (\begin{DoxyParamCaption}\item[{Key\+Set $\ast$}]{ks }\end{DoxyParamCaption})}



Returns the next Key in a Key\+Set. 

Key\+Sets have an internal cursor that can be reset with \hyperlink{group__keyset_gabe793ff51f1728e3429c84a8a9086b70}{ks\+Rewind()}. Every time \hyperlink{group__keyset_ga317321c9065b5a4b3e33fe1c399bcec9}{ks\+Next()} is called the cursor is incremented and the new current Key is returned.

You\textquotesingle{}ll get a N\+U\+LL pointer if the key after the end of the Key\+Set was reached. On subsequent calls of \hyperlink{group__keyset_ga317321c9065b5a4b3e33fe1c399bcec9}{ks\+Next()} it will still return the N\+U\+LL pointer.

The {\ttfamily ks} internal cursor will be changed, so it is not const.

\begin{DoxyNote}{Note}
You must not delete or change the key, use \hyperlink{group__keyset_gae42530b04defb772059de0600159cf69}{ks\+Pop()} if you want to delete it.

That applications must do \hyperlink{group__keyset_gaa34fc43a081e6b01e4120daa6c112004}{ks\+Lookup()} with an cascading key for every single key before using it, because specifications allow to hide or override keys.
\end{DoxyNote}

\begin{DoxyParams}{Parameters}
{\em ks} & the keyset object to work with \\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{Returns}
the new current Key 
\end{DoxyReturn}

\begin{DoxyRetVals}{Return values}
{\em 0} & when the end is reached \\
\hline
{\em 0} & on N\+U\+LL pointer \\
\hline
\end{DoxyRetVals}
\begin{DoxySeeAlso}{See also}
\hyperlink{group__keyset_gabe793ff51f1728e3429c84a8a9086b70}{ks\+Rewind()}, \hyperlink{group__keyset_ga4287b9416912c5f2ab9c195cb74fb094}{ks\+Current()} 

\hyperlink{group__keyset_gaa34fc43a081e6b01e4120daa6c112004}{ks\+Lookup()} to honor specifications 
\end{DoxySeeAlso}
\mbox{\Hypertarget{group__keyset_gae42530b04defb772059de0600159cf69}\label{group__keyset_gae42530b04defb772059de0600159cf69}} 
\index{Key\+Set@{Key\+Set}!ks\+Pop@{ks\+Pop}}
\index{ks\+Pop@{ks\+Pop}!Key\+Set@{Key\+Set}}
\subsubsection{\texorpdfstring{ks\+Pop()}{ksPop()}}
{\footnotesize\ttfamily Key$\ast$ ks\+Pop (\begin{DoxyParamCaption}\item[{Key\+Set $\ast$}]{ks }\end{DoxyParamCaption})}



Remove and return the last key of {\ttfamily ks}. 

The reference counter will be decremented by one.

The Key\+Sets cursor will not be affected if it did not point to the popped key.

\begin{DoxyNote}{Note}
You need to \hyperlink{group__key_ga3df95bbc2494e3e6703ece5639be5bb1}{key\+Del()} the key afterwards, if you don\textquotesingle{}t append it to another keyset. It has the same semantics like a key allocated with \hyperlink{group__key_gad23c65b44bf48d773759e1f9a4d43b89}{key\+New()} or \hyperlink{group__key_gae6ec6a60cc4b8c1463fa08623d056ce3}{key\+Dup()}.
\end{DoxyNote}

\begin{DoxyCode}
ks1=\hyperlink{group__keyset_ga671e1aaee3ae9dc13b4834a4ddbd2c3c}{ksNew}(0, \hyperlink{kdbenum_8c_a7a28fce3773b2c873c94ac80b8b4cd54}{KS\_END});
ks2=\hyperlink{group__keyset_ga671e1aaee3ae9dc13b4834a4ddbd2c3c}{ksNew}(0, \hyperlink{kdbenum_8c_a7a28fce3773b2c873c94ac80b8b4cd54}{KS\_END});

k1=\hyperlink{group__key_gad23c65b44bf48d773759e1f9a4d43b89}{keyNew}(\textcolor{stringliteral}{"user/name"}, \hyperlink{group__key_gga91fb3178848bd682000958089abbaf40aa8adb6fcb92dec58fb19410eacfdd403}{KEY\_END}); \textcolor{comment}{// ref counter 0}
\hyperlink{group__keyset_gaa5a1d467a4d71041edce68ea7748ce45}{ksAppendKey}(ks1, k1); \textcolor{comment}{// ref counter 1}
\hyperlink{group__keyset_gaa5a1d467a4d71041edce68ea7748ce45}{ksAppendKey}(ks2, k1); \textcolor{comment}{// ref counter 2}

k1=\hyperlink{group__keyset_gae42530b04defb772059de0600159cf69}{ksPop} (ks1); \textcolor{comment}{// ref counter 1}
k1=\hyperlink{group__keyset_gae42530b04defb772059de0600159cf69}{ksPop} (ks2); \textcolor{comment}{// ref counter 0, like after keyNew()}

\hyperlink{group__keyset_gaa5a1d467a4d71041edce68ea7748ce45}{ksAppendKey}(ks1, k1); \textcolor{comment}{// ref counter 1}

\hyperlink{group__keyset_ga27e5c16473b02a422238c8d970db7ac8}{ksDel} (ks1); \textcolor{comment}{// key is deleted too}
\hyperlink{group__keyset_ga27e5c16473b02a422238c8d970db7ac8}{ksDel} (ks2);
\end{DoxyCode}


\begin{DoxyReturn}{Returns}
the last key of {\ttfamily ks} 
\end{DoxyReturn}

\begin{DoxyRetVals}{Return values}
{\em N\+U\+LL} & if {\ttfamily ks} is empty or on N\+U\+LL pointer \\
\hline
\end{DoxyRetVals}

\begin{DoxyParams}{Parameters}
{\em ks} & Key\+Set to work with \\
\hline
\end{DoxyParams}
\begin{DoxySeeAlso}{See also}
\hyperlink{group__keyset_gaa34fc43a081e6b01e4120daa6c112004}{ks\+Lookup()} to pop keys by name 

\hyperlink{group__keyset_gaba1f1dbea191f4d7e7eb3e4296ae7d5e}{ks\+Copy()} to pop all keys 

command\+List() for an example 
\end{DoxySeeAlso}
\mbox{\Hypertarget{group__keyset_gabe793ff51f1728e3429c84a8a9086b70}\label{group__keyset_gabe793ff51f1728e3429c84a8a9086b70}} 
\index{Key\+Set@{Key\+Set}!ks\+Rewind@{ks\+Rewind}}
\index{ks\+Rewind@{ks\+Rewind}!Key\+Set@{Key\+Set}}
\subsubsection{\texorpdfstring{ks\+Rewind()}{ksRewind()}}
{\footnotesize\ttfamily int ks\+Rewind (\begin{DoxyParamCaption}\item[{Key\+Set $\ast$}]{ks }\end{DoxyParamCaption})}



Rewinds the Key\+Set internal cursor. 

Use it to set the cursor to the beginning of the Key\+Set. \hyperlink{group__keyset_ga4287b9416912c5f2ab9c195cb74fb094}{ks\+Current()} will then always return N\+U\+LL afterwards. So you want to \hyperlink{group__keyset_ga317321c9065b5a4b3e33fe1c399bcec9}{ks\+Next()} first.


\begin{DoxyCode}
\hyperlink{group__keyset_gabe793ff51f1728e3429c84a8a9086b70}{ksRewind} (ks);
\textcolor{keywordflow}{while} ((key = \hyperlink{group__keyset_ga317321c9065b5a4b3e33fe1c399bcec9}{ksNext} (ks))!=0) \{\}
\end{DoxyCode}



\begin{DoxyParams}{Parameters}
{\em ks} & the keyset object to work with \\
\hline
\end{DoxyParams}

\begin{DoxyRetVals}{Return values}
{\em 0} & on success \\
\hline
{\em -\/1} & on N\+U\+LL pointer \\
\hline
\end{DoxyRetVals}
\begin{DoxySeeAlso}{See also}
\hyperlink{group__keyset_ga317321c9065b5a4b3e33fe1c399bcec9}{ks\+Next()}, \hyperlink{group__keyset_ga4287b9416912c5f2ab9c195cb74fb094}{ks\+Current()} 
\end{DoxySeeAlso}
\mbox{\Hypertarget{group__keyset_gad94c9ffaa3e8034564c0712fd407c345}\label{group__keyset_gad94c9ffaa3e8034564c0712fd407c345}} 
\index{Key\+Set@{Key\+Set}!ks\+Set\+Cursor@{ks\+Set\+Cursor}}
\index{ks\+Set\+Cursor@{ks\+Set\+Cursor}!Key\+Set@{Key\+Set}}
\subsubsection{\texorpdfstring{ks\+Set\+Cursor()}{ksSetCursor()}}
{\footnotesize\ttfamily int ks\+Set\+Cursor (\begin{DoxyParamCaption}\item[{Key\+Set $\ast$}]{ks,  }\item[{cursor\+\_\+t}]{cursor }\end{DoxyParamCaption})}



Set the Key\+Set internal cursor. 

Use it to set the cursor to a stored position. \hyperlink{group__keyset_ga4287b9416912c5f2ab9c195cb74fb094}{ks\+Current()} will then be the position which you got with.

\begin{DoxyWarning}{Warning}
Cursors may get invalid when the key was \hyperlink{group__keyset_gae42530b04defb772059de0600159cf69}{ks\+Pop()}ed or \hyperlink{group__keyset_gaa34fc43a081e6b01e4120daa6c112004}{ks\+Lookup()} was used together with K\+D\+B\+\_\+\+O\+\_\+\+P\+OP.
\end{DoxyWarning}

\begin{DoxyCode}
cursor\_t cursor;
..
\textcolor{comment}{// key now in any position here}
cursor = \hyperlink{group__keyset_gaffe507ab9281c322eb16c3e992075d29}{ksGetCursor} (ks);
\textcolor{keywordflow}{while} ((key = \hyperlink{group__keymeta_ga4c88342f580a4291455a801af71ce048}{keyNextMeta} (ks))!=0) \{\}
\hyperlink{group__keyset_gad94c9ffaa3e8034564c0712fd407c345}{ksSetCursor} (ks, cursor); \textcolor{comment}{// reset state}
\hyperlink{group__keyset_ga4287b9416912c5f2ab9c195cb74fb094}{ksCurrent}(ks); \textcolor{comment}{// in same position as before}
\end{DoxyCode}


An invalid cursor will set the keyset to its beginning like \hyperlink{group__keyset_gabe793ff51f1728e3429c84a8a9086b70}{ks\+Rewind()}. When you set an invalid cursor \hyperlink{group__keyset_ga4287b9416912c5f2ab9c195cb74fb094}{ks\+Current()} is 0 and \hyperlink{group__keyset_ga317321c9065b5a4b3e33fe1c399bcec9}{ks\+Next()} == \hyperlink{group__keyset_gae7dbf3aef70e67b5328475eb3d1f92f5}{ks\+Head()}.


\begin{DoxyParams}{Parameters}
{\em cursor} & the cursor to use \\
\hline
{\em ks} & the keyset object to work with \\
\hline
\end{DoxyParams}

\begin{DoxyRetVals}{Return values}
{\em 0} & when the keyset is \hyperlink{group__keyset_gabe793ff51f1728e3429c84a8a9086b70}{ks\+Rewind()}ed \\
\hline
{\em 1} & otherwise \\
\hline
{\em -\/1} & on N\+U\+LL pointer \\
\hline
\end{DoxyRetVals}
\begin{DoxySeeAlso}{See also}
\hyperlink{group__keyset_ga317321c9065b5a4b3e33fe1c399bcec9}{ks\+Next()}, \hyperlink{group__keyset_gaffe507ab9281c322eb16c3e992075d29}{ks\+Get\+Cursor()} 
\end{DoxySeeAlso}
\mbox{\Hypertarget{group__keyset_gadca442c4ab43cf532b15091d7711559e}\label{group__keyset_gadca442c4ab43cf532b15091d7711559e}} 
\index{Key\+Set@{Key\+Set}!ks\+Tail@{ks\+Tail}}
\index{ks\+Tail@{ks\+Tail}!Key\+Set@{Key\+Set}}
\subsubsection{\texorpdfstring{ks\+Tail()}{ksTail()}}
{\footnotesize\ttfamily Key$\ast$ ks\+Tail (\begin{DoxyParamCaption}\item[{const Key\+Set $\ast$}]{ks }\end{DoxyParamCaption})}



Return the last key in the Key\+Set. 

The Key\+Sets cursor will not be affected.

If \hyperlink{group__keyset_ga4287b9416912c5f2ab9c195cb74fb094}{ks\+Current()}==\hyperlink{group__keyset_gadca442c4ab43cf532b15091d7711559e}{ks\+Tail()} you know you are on the last key. \hyperlink{group__keyset_ga317321c9065b5a4b3e33fe1c399bcec9}{ks\+Next()} will return a N\+U\+LL pointer afterwards.


\begin{DoxyParams}{Parameters}
{\em ks} & the keyset object to work with \\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{Returns}
the last Key of a keyset 
\end{DoxyReturn}

\begin{DoxyRetVals}{Return values}
{\em 0} & on N\+U\+LL pointer or empty keyset \\
\hline
\end{DoxyRetVals}
\begin{DoxySeeAlso}{See also}
\hyperlink{group__keyset_gae7dbf3aef70e67b5328475eb3d1f92f5}{ks\+Head()} for the first \hyperlink{group__key}{Key} 

\hyperlink{group__keyset_gabe793ff51f1728e3429c84a8a9086b70}{ks\+Rewind()}, \hyperlink{group__keyset_ga4287b9416912c5f2ab9c195cb74fb094}{ks\+Current()} and \hyperlink{group__keyset_ga317321c9065b5a4b3e33fe1c399bcec9}{ks\+Next()} for iterating over the \hyperlink{group__keyset}{Key\+Set} 
\end{DoxySeeAlso}
\mbox{\Hypertarget{group__keyset_ga4ff760f56693b51ab785ed7ce628e649}\label{group__keyset_ga4ff760f56693b51ab785ed7ce628e649}} 
\index{Key\+Set@{Key\+Set}!ks\+V\+New@{ks\+V\+New}}
\index{ks\+V\+New@{ks\+V\+New}!Key\+Set@{Key\+Set}}
\subsubsection{\texorpdfstring{ks\+V\+New()}{ksVNew()}}
{\footnotesize\ttfamily Key\+Set$\ast$ ks\+V\+New (\begin{DoxyParamCaption}\item[{size\+\_\+t}]{alloc,  }\item[{va\+\_\+list}]{va }\end{DoxyParamCaption})}



Allocate, initialize and return a new Key\+Set object. 

Objects created with \hyperlink{group__keyset_ga671e1aaee3ae9dc13b4834a4ddbd2c3c}{ks\+New()} must be destroyed with \hyperlink{group__keyset_ga27e5c16473b02a422238c8d970db7ac8}{ks\+Del()}.

You can use a arbitrary long list of parameters to preload the keyset with a list of keys. Either your first and only parameter is 0 or your last parameter must be K\+E\+Y\+\_\+\+E\+ND.

So, terminate with ks\+New(0, K\+S\+\_\+\+E\+N\+D) or ks\+New(20, ..., K\+S\+\_\+\+E\+ND)

\begin{DoxyWarning}{Warning}
Never use ks\+New(0, key\+New(...), K\+S\+\_\+\+E\+ND). If the first parameter is 0, other arguments are ignored.
\end{DoxyWarning}
For most uses


\begin{DoxyCodeInclude}
KeySet * keys = \hyperlink{group__keyset_ga671e1aaee3ae9dc13b4834a4ddbd2c3c}{ksNew} (0, \hyperlink{kdbenum_8c_a7a28fce3773b2c873c94ac80b8b4cd54}{KS\_END});
\textcolor{comment}{// work with it}
\hyperlink{group__keyset_ga27e5c16473b02a422238c8d970db7ac8}{ksDel} (keys);
\end{DoxyCodeInclude}
 will be fine, the alloc size will be 16, defined in \hyperlink{kdbprivate_8h}{kdbprivate.\+h}. The alloc size will be doubled whenever size reaches alloc size, so it also performs well with large keysets.

But if you have any clue how large your keyset may be you should read the next statements.

If you want a keyset with length 15 (because you know of your application that you only need up to 15 keys), use\+:


\begin{DoxyCodeInclude}
KeySet * keys = \hyperlink{group__keyset_ga671e1aaee3ae9dc13b4834a4ddbd2c3c}{ksNew} (15, \hyperlink{group__key_gad23c65b44bf48d773759e1f9a4d43b89}{keyNew} (\textcolor{stringliteral}{"user/sw/org/app/#0/current/fixedConfiguration/key01"}, 
      \hyperlink{group__key_gga91fb3178848bd682000958089abbaf40ac66e4a49d09212b79f5754ca6db5bd2e}{KEY\_VALUE}, \textcolor{stringliteral}{"value01"}, 0),
                       \hyperlink{group__key_gad23c65b44bf48d773759e1f9a4d43b89}{keyNew} (\textcolor{stringliteral}{"user/sw/org/app/#0/current/fixedConfiguration/key02"}, 
      \hyperlink{group__key_gga91fb3178848bd682000958089abbaf40ac66e4a49d09212b79f5754ca6db5bd2e}{KEY\_VALUE}, \textcolor{stringliteral}{"value02"}, 0),
                       \hyperlink{group__key_gad23c65b44bf48d773759e1f9a4d43b89}{keyNew} (\textcolor{stringliteral}{"user/sw/org/app/#0/current/fixedConfiguration/key03"}, 
      \hyperlink{group__key_gga91fb3178848bd682000958089abbaf40ac66e4a49d09212b79f5754ca6db5bd2e}{KEY\_VALUE}, \textcolor{stringliteral}{"value03"}, 0),
                       \textcolor{comment}{// ...}
                       \hyperlink{group__key_gad23c65b44bf48d773759e1f9a4d43b89}{keyNew} (\textcolor{stringliteral}{"user/sw/org/app/#0/current/fixedConfiguration/key15"}, 
      \hyperlink{group__key_gga91fb3178848bd682000958089abbaf40ac66e4a49d09212b79f5754ca6db5bd2e}{KEY\_VALUE}, \textcolor{stringliteral}{"value15"}, 0), \hyperlink{kdbenum_8c_a7a28fce3773b2c873c94ac80b8b4cd54}{KS\_END});
\textcolor{comment}{// work with it}
\hyperlink{group__keyset_ga27e5c16473b02a422238c8d970db7ac8}{ksDel} (keys);
\end{DoxyCodeInclude}
 If you start having 3 keys, and your application needs approximately 200 up to 500 keys, you can use\+:


\begin{DoxyCodeInclude}
KeySet * config = \hyperlink{group__keyset_ga671e1aaee3ae9dc13b4834a4ddbd2c3c}{ksNew} (500, \hyperlink{group__key_gad23c65b44bf48d773759e1f9a4d43b89}{keyNew} (\textcolor{stringliteral}{"user/sw/org/app/#0/current/fixedConfiguration/key1"}, 
      \hyperlink{group__key_gga91fb3178848bd682000958089abbaf40ac66e4a49d09212b79f5754ca6db5bd2e}{KEY\_VALUE}, \textcolor{stringliteral}{"value1"}, 0),
                         \hyperlink{group__key_gad23c65b44bf48d773759e1f9a4d43b89}{keyNew} (\textcolor{stringliteral}{"user/sw/org/app/#0/current/fixedConfiguration/key2"}, 
      \hyperlink{group__key_gga91fb3178848bd682000958089abbaf40ac66e4a49d09212b79f5754ca6db5bd2e}{KEY\_VALUE}, \textcolor{stringliteral}{"value2"}, 0),
                         \hyperlink{group__key_gad23c65b44bf48d773759e1f9a4d43b89}{keyNew} (\textcolor{stringliteral}{"user/sw/org/app/#0/current/fixedConfiguration/key3"}, 
      \hyperlink{group__key_gga91fb3178848bd682000958089abbaf40ac66e4a49d09212b79f5754ca6db5bd2e}{KEY\_VALUE}, \textcolor{stringliteral}{"value3"}, 0),
                         \hyperlink{kdbenum_8c_a7a28fce3773b2c873c94ac80b8b4cd54}{KS\_END}); \textcolor{comment}{// don't forget the KS\_END at the end!}
\textcolor{comment}{// work with it}
\hyperlink{group__keyset_ga27e5c16473b02a422238c8d970db7ac8}{ksDel} (config);
\end{DoxyCodeInclude}
 Alloc size is 500, the size of the keyset will be 3 after ks\+New. This means the keyset will reallocate when appending more than 497 keys.

The main benefit of taking a list of variant length parameters is to be able to have one C-\/\+Statement for any possible Key\+Set. If you prefer, you can always create an empty Key\+Set and use \hyperlink{group__keyset_gaa5a1d467a4d71041edce68ea7748ce45}{ks\+Append\+Key()}.

\begin{DoxyPostcond}{Postcondition}
the keyset is rewinded properly
\end{DoxyPostcond}
\begin{DoxySeeAlso}{See also}
\hyperlink{group__keyset_ga27e5c16473b02a422238c8d970db7ac8}{ks\+Del()} to free the \hyperlink{group__keyset}{Key\+Set} afterwards 

\hyperlink{group__keyset_gac59e4b328245463f1451f68d5106151c}{ks\+Dup()} to duplicate an existing \hyperlink{group__keyset}{Key\+Set} 

\hyperlink{group__keyset_gaa5a1d467a4d71041edce68ea7748ce45}{ks\+Append\+Key()} to append individual keys 
\end{DoxySeeAlso}

\begin{DoxyParams}{Parameters}
{\em alloc} & gives a hint for the size how many Keys may be stored initially \\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{Returns}
a ready to use Key\+Set object 
\end{DoxyReturn}

\begin{DoxyRetVals}{Return values}
{\em 0} & on memory error\\
\hline
\end{DoxyRetVals}
\begin{DoxyPrecond}{Precondition}
caller must call va\+\_\+start and va\+\_\+end 
\end{DoxyPrecond}
\begin{DoxyParagraph}{va the list of arguments}

\end{DoxyParagraph}

\begin{DoxyParams}{Parameters}
{\em alloc} & the allocation size \\
\hline
{\em va} & the list of variable arguments \\
\hline
\end{DoxyParams}
