\hypertarget{group__keyset}{
\section{KeySet :: Class Methods}
\label{group__keyset}\index{KeySet :: Class Methods@{KeySet :: Class Methods}}
}


Methods to manipulate KeySets.  


\subsection*{Functions}
\begin{DoxyCompactItemize}
\item 
\hyperlink{struct__KeySet}{KeySet} $\ast$ \hyperlink{group__keyset_ga671e1aaee3ae9dc13b4834a4ddbd2c3c}{ksNew} (size\_\-t alloc,...)
\item 
\hyperlink{struct__KeySet}{KeySet} $\ast$ \hyperlink{group__keyset_gac59e4b328245463f1451f68d5106151c}{ksDup} (const \hyperlink{struct__KeySet}{KeySet} $\ast$source)
\item 
int \hyperlink{group__keyset_gaba1f1dbea191f4d7e7eb3e4296ae7d5e}{ksCopy} (\hyperlink{struct__KeySet}{KeySet} $\ast$dest, const \hyperlink{struct__KeySet}{KeySet} $\ast$source)
\item 
int \hyperlink{group__keyset_ga27e5c16473b02a422238c8d970db7ac8}{ksDel} (\hyperlink{struct__KeySet}{KeySet} $\ast$ks)
\item 
ssize\_\-t \hyperlink{group__keyset_ga7474ad6b0a0fa969dbdf267ba5770eee}{ksGetSize} (const \hyperlink{struct__KeySet}{KeySet} $\ast$ks)
\item 
ssize\_\-t \hyperlink{group__keyset_gaa5a1d467a4d71041edce68ea7748ce45}{ksAppendKey} (\hyperlink{struct__KeySet}{KeySet} $\ast$ks, \hyperlink{struct__Key}{Key} $\ast$toAppend)
\item 
ssize\_\-t \hyperlink{group__keyset_ga21eb9c3a14a604ee3a8bdc779232e7b7}{ksAppend} (\hyperlink{struct__KeySet}{KeySet} $\ast$ks, const \hyperlink{struct__KeySet}{KeySet} $\ast$toAppend)
\item 
\hyperlink{struct__KeySet}{KeySet} $\ast$ \hyperlink{group__keyset_ga6b00cf82b59af4d883a9bad6cf4a4a4a}{ksCut} (\hyperlink{struct__KeySet}{KeySet} $\ast$ks, const \hyperlink{struct__Key}{Key} $\ast$cutpoint)
\item 
\hyperlink{struct__Key}{Key} $\ast$ \hyperlink{group__keyset_gae42530b04defb772059de0600159cf69}{ksPop} (\hyperlink{struct__KeySet}{KeySet} $\ast$ks)
\item 
int \hyperlink{group__keyset_gabe793ff51f1728e3429c84a8a9086b70}{ksRewind} (\hyperlink{struct__KeySet}{KeySet} $\ast$ks)
\item 
\hyperlink{struct__Key}{Key} $\ast$ \hyperlink{group__keyset_ga317321c9065b5a4b3e33fe1c399bcec9}{ksNext} (\hyperlink{struct__KeySet}{KeySet} $\ast$ks)
\item 
\hyperlink{struct__Key}{Key} $\ast$ \hyperlink{group__keyset_ga4287b9416912c5f2ab9c195cb74fb094}{ksCurrent} (const \hyperlink{struct__KeySet}{KeySet} $\ast$ks)
\item 
\hyperlink{struct__Key}{Key} $\ast$ \hyperlink{group__keyset_gae7dbf3aef70e67b5328475eb3d1f92f5}{ksHead} (const \hyperlink{struct__KeySet}{KeySet} $\ast$ks)
\item 
\hyperlink{struct__Key}{Key} $\ast$ \hyperlink{group__keyset_gadca442c4ab43cf532b15091d7711559e}{ksTail} (const \hyperlink{struct__KeySet}{KeySet} $\ast$ks)
\item 
cursor\_\-t \hyperlink{group__keyset_gaffe507ab9281c322eb16c3e992075d29}{ksGetCursor} (const \hyperlink{struct__KeySet}{KeySet} $\ast$ks)
\item 
int \hyperlink{group__keyset_gad94c9ffaa3e8034564c0712fd407c345}{ksSetCursor} (\hyperlink{struct__KeySet}{KeySet} $\ast$ks, cursor\_\-t cursor)
\item 
\hyperlink{struct__Key}{Key} $\ast$ \hyperlink{group__keyset_gaa34fc43a081e6b01e4120daa6c112004}{ksLookup} (\hyperlink{struct__KeySet}{KeySet} $\ast$ks, \hyperlink{struct__Key}{Key} $\ast$key, \hyperlink{group__kdb_ga98a3d6a4016c9dad9cbd1a99a9c2a45a}{option\_\-t} options)
\item 
\hyperlink{struct__Key}{Key} $\ast$ \hyperlink{group__keyset_gad2e30fb6d4739d917c5abb2ac2f9c1a1}{ksLookupByName} (\hyperlink{struct__KeySet}{KeySet} $\ast$ks, const char $\ast$name, \hyperlink{group__kdb_ga98a3d6a4016c9dad9cbd1a99a9c2a45a}{option\_\-t} options)
\end{DoxyCompactItemize}


\subsection{Detailed Description}
Methods to manipulate KeySets. A KeySet is a sorted set of keys. So the correct name actually would be KeyMap.

With \hyperlink{group__keyset_ga671e1aaee3ae9dc13b4834a4ddbd2c3c}{ksNew()} you can create a new KeySet.

You can add keys with \hyperlink{group__keyset_gaa5a1d467a4d71041edce68ea7748ce45}{ksAppendKey()} in the keyset. Using \hyperlink{group__keyset_ga21eb9c3a14a604ee3a8bdc779232e7b7}{ksAppend()} you can append a whole keyset.

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


\hyperlink{group__keyset_ga7474ad6b0a0fa969dbdf267ba5770eee}{ksGetSize()} tells you the current size of the keyset.

With \hyperlink{group__keyset_gabe793ff51f1728e3429c84a8a9086b70}{ksRewind()} and \hyperlink{group__keyset_ga317321c9065b5a4b3e33fe1c399bcec9}{ksNext()} you can navigate through the keyset. Don't expect any particular order, but it is assured that you will get every key of the set.

KeySets have an \hyperlink{group__keyset_ga4287b9416912c5f2ab9c195cb74fb094}{internal cursor }. This is used for \hyperlink{group__keyset_gaa34fc43a081e6b01e4120daa6c112004}{ksLookup()} and \hyperlink{group__kdb_ga11436b058408f83d303ca5e996832bcf}{kdbSet()}.

KeySet has a fundamental meaning inside 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. With \hyperlink{group__keyset_gad2e30fb6d4739d917c5abb2ac2f9c1a1}{ksLookupByName()} it is possible to fetch easily specific keys out of the list of keys.

You can easily create and iterate keys: 
\begin{DoxyCode}
#include <kdb.h>

// create a new keyset with 3 keys
// with a hint that about 20 keys will be inside
KeySet *myConfig = ksNew(20,
        keyNew ("user/name1", 0),
        keyNew ("user/name2", 0),
        keyNew ("user/name3", 0),
        KS_END);
// append a key in the keyset
ksAppendKey(myConfig, keyNew("user/name4", 0));

Key *current;
ksRewind(myConfig);
while ((current=ksNext(myConfig))!=0)
{
        printf("Key name is %s.\n", keyName (current));
}
ksDel (myConfig); // delete keyset and all keys appended
\end{DoxyCode}
 

\subsection{Function Documentation}
\hypertarget{group__keyset_ga21eb9c3a14a604ee3a8bdc779232e7b7}{
\index{keyset@{keyset}!ksAppend@{ksAppend}}
\index{ksAppend@{ksAppend}!keyset@{keyset}}
\subsubsection[{ksAppend}]{\setlength{\rightskip}{0pt plus 5cm}ssize\_\-t ksAppend (
\begin{DoxyParamCaption}
\item[{{\bf KeySet} $\ast$}]{ ks, }
\item[{const {\bf KeySet} $\ast$}]{ toAppend}
\end{DoxyParamCaption}
)}}
\label{group__keyset_ga21eb9c3a14a604ee3a8bdc779232e7b7}
Append all {\ttfamily toAppend} contained keys to the end of the {\ttfamily ks}.

{\ttfamily toAppend} KeySet will be left unchanged.

If a key is both in toAppend 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}{keyNextMeta()} will be shared. 
\end{DoxyNote}


\begin{DoxyPostcond}{Postcondition}
Sorted KeySet ks with all keys it had before and additionally the keys from toAppend 
\end{DoxyPostcond}
\begin{DoxyReturn}{Returns}
the size of the KeySet after transfer 

-\/1 on NULL pointers 
\end{DoxyReturn}

\begin{DoxyParams}{Parameters}
\item[{\em ks}]the KeySet that will receive the keys \item[{\em toAppend}]the KeySet that provides the keys that will be transfered \end{DoxyParams}
\begin{DoxySeeAlso}{See also}
\hyperlink{group__keyset_gaa5a1d467a4d71041edce68ea7748ce45}{ksAppendKey()} 
\end{DoxySeeAlso}
\hypertarget{group__keyset_gaa5a1d467a4d71041edce68ea7748ce45}{
\index{keyset@{keyset}!ksAppendKey@{ksAppendKey}}
\index{ksAppendKey@{ksAppendKey}!keyset@{keyset}}
\subsubsection[{ksAppendKey}]{\setlength{\rightskip}{0pt plus 5cm}ssize\_\-t ksAppendKey (
\begin{DoxyParamCaption}
\item[{{\bf KeySet} $\ast$}]{ ks, }
\item[{{\bf Key} $\ast$}]{ toAppend}
\end{DoxyParamCaption}
)}}
\label{group__keyset_gaa5a1d467a4d71041edce68ea7748ce45}
Appends a Key to the end of {\ttfamily ks}.

A pointer to the key will be stored, and not a private copy. So a future \hyperlink{group__keyset_ga27e5c16473b02a422238c8d970db7ac8}{ksDel()} on {\ttfamily ks} may \hyperlink{group__key_ga3df95bbc2494e3e6703ece5639be5bb1}{keyDel()} the {\ttfamily toAppend} object, see \hyperlink{group__key_ga4aabc4272506dd63161db2bbb42de8ae}{keyGetRef()}.

The reference counter of the key will be incremented, and thus toAppend is not const.

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


If the keyname already existed, it will be replaced with the new key.

The KeySet internal cursor will be set to the new key.

\begin{DoxyReturn}{Returns}
the size of the KeySet after insertion 

-\/1 on NULL pointers 

-\/1 if insertion failed, the key will be deleted then. 
\end{DoxyReturn}

\begin{DoxyParams}{Parameters}
\item[{\em ks}]KeySet that will receive the key \item[{\em toAppend}]Key that will be appended to ks \end{DoxyParams}
\begin{DoxySeeAlso}{See also}
\hyperlink{group__keyset_ga21eb9c3a14a604ee3a8bdc779232e7b7}{ksAppend()}, \hyperlink{group__key_gaf6893c038b3ebee90c73a9ea8356bebf}{keyNew()}, \hyperlink{group__keyset_ga27e5c16473b02a422238c8d970db7ac8}{ksDel()} 

\hyperlink{group__key_ga6970a6f254d67af7e39f8e469bb162f1}{keyIncRef()} 
\end{DoxySeeAlso}
\hypertarget{group__keyset_gaba1f1dbea191f4d7e7eb3e4296ae7d5e}{
\index{keyset@{keyset}!ksCopy@{ksCopy}}
\index{ksCopy@{ksCopy}!keyset@{keyset}}
\subsubsection[{ksCopy}]{\setlength{\rightskip}{0pt plus 5cm}int ksCopy (
\begin{DoxyParamCaption}
\item[{{\bf KeySet} $\ast$}]{ dest, }
\item[{const {\bf KeySet} $\ast$}]{ source}
\end{DoxyParamCaption}
)}}
\label{group__keyset_gaba1f1dbea191f4d7e7eb3e4296ae7d5e}
Copy a keyset.

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

You can also use it to clear a keyset when you pass a NULL pointer as {\ttfamily source}.

Note that 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}{ksCurrent()} is set properly in {\ttfamily dest}.

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}{ksDel()}.

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



\begin{DoxyCode}
int f (KeySet *ks)
{
        KeySet *c = ksNew (20, ..., KS_END);
        // c receives keys
        ksCopy (ks, c); // pass the keyset to the caller

        ksDel (c);
}       // caller needs to ksDel (ks)
\end{DoxyCode}



\begin{DoxyParams}{Parameters}
\item[{\em source}]has to be an initialized source KeySet or NULL \item[{\em dest}]has to be an initialized KeySet where to write the keys \end{DoxyParams}
\begin{DoxyReturn}{Returns}
1 on success 

0 if dest was cleared successfully (source is NULL) 

-\/1 on NULL pointer 
\end{DoxyReturn}
\begin{DoxySeeAlso}{See also}
\hyperlink{group__keyset_ga671e1aaee3ae9dc13b4834a4ddbd2c3c}{ksNew()}, \hyperlink{group__keyset_ga27e5c16473b02a422238c8d970db7ac8}{ksDel()}, \hyperlink{group__keyset_gac59e4b328245463f1451f68d5106151c}{ksDup()} 

\hyperlink{group__key_ga6a12cbbe656a1ad9f41b8c681d7a2f92}{keyCopy()} for copying keys 
\end{DoxySeeAlso}
\hypertarget{group__keyset_ga4287b9416912c5f2ab9c195cb74fb094}{
\index{keyset@{keyset}!ksCurrent@{ksCurrent}}
\index{ksCurrent@{ksCurrent}!keyset@{keyset}}
\subsubsection[{ksCurrent}]{\setlength{\rightskip}{0pt plus 5cm}{\bf Key}$\ast$ ksCurrent (
\begin{DoxyParamCaption}
\item[{const {\bf KeySet} $\ast$}]{ ks}
\end{DoxyParamCaption}
)}}
\label{group__keyset_ga4287b9416912c5f2ab9c195cb74fb094}
Return the current Key.

The pointer is NULL if you reached the end or after \hyperlink{group__keyset_gabe793ff51f1728e3429c84a8a9086b70}{ksRewind()}.

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

\begin{DoxyParams}{Parameters}
\item[{\em ks}]the keyset object to work with \end{DoxyParams}
\begin{DoxyReturn}{Returns}
pointer to the Key pointed by {\ttfamily ks's} cursor 

0 on NULL pointer 
\end{DoxyReturn}
\begin{DoxySeeAlso}{See also}
\hyperlink{group__keyset_ga317321c9065b5a4b3e33fe1c399bcec9}{ksNext()}, \hyperlink{group__keyset_gabe793ff51f1728e3429c84a8a9086b70}{ksRewind()} 
\end{DoxySeeAlso}
\hypertarget{group__keyset_ga6b00cf82b59af4d883a9bad6cf4a4a4a}{
\index{keyset@{keyset}!ksCut@{ksCut}}
\index{ksCut@{ksCut}!keyset@{keyset}}
\subsubsection[{ksCut}]{\setlength{\rightskip}{0pt plus 5cm}{\bf KeySet}$\ast$ ksCut (
\begin{DoxyParamCaption}
\item[{{\bf KeySet} $\ast$}]{ ks, }
\item[{const {\bf Key} $\ast$}]{ cutpoint}
\end{DoxyParamCaption}
)}}
\label{group__keyset_ga6b00cf82b59af4d883a9bad6cf4a4a4a}
Cuts out a keyset at the cutpoint.

Searches for the cutpoint inside the KeySet ks. If found it cuts out everything which is below (see \hyperlink{group__keytest_ga03332b5d97c76a4fd2640aca4762b8df}{keyIsBelow()}) this key. If not found an empty keyset is returned.

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

\begin{DoxyReturn}{Returns}
a new allocated KeySet which needs to deleted with \hyperlink{group__keyset_ga27e5c16473b02a422238c8d970db7ac8}{ksDel()}. 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}
\item[{\em 0}]on null pointers, no key name or allocation problems \end{DoxyRetVals}

\begin{DoxyParams}{Parameters}
\item[{\em ks}]the keyset to cut. It will be modified by removing all keys below the cutpoint. The cutpoint itself will also be removed. \item[{\em cutpoint}]the point where to cut out the keyset \end{DoxyParams}
\hypertarget{group__keyset_ga27e5c16473b02a422238c8d970db7ac8}{
\index{keyset@{keyset}!ksDel@{ksDel}}
\index{ksDel@{ksDel}!keyset@{keyset}}
\subsubsection[{ksDel}]{\setlength{\rightskip}{0pt plus 5cm}int ksDel (
\begin{DoxyParamCaption}
\item[{{\bf KeySet} $\ast$}]{ ks}
\end{DoxyParamCaption}
)}}
\label{group__keyset_ga27e5c16473b02a422238c8d970db7ac8}
A destructor for KeySet objects.

Cleans all internal dynamic attributes, decrement all reference pointers to all keys and then \hyperlink{group__key_ga3df95bbc2494e3e6703ece5639be5bb1}{keyDel()} all contained Keys, and free()s the release the KeySet object memory (that was previously allocated by \hyperlink{group__keyset_ga671e1aaee3ae9dc13b4834a4ddbd2c3c}{ksNew()}).


\begin{DoxyParams}{Parameters}
\item[{\em ks}]the keyset object to work with \end{DoxyParams}
\begin{DoxyReturn}{Returns}
0 when the keyset was freed 

-\/1 on null pointer 
\end{DoxyReturn}
\begin{DoxySeeAlso}{See also}
\hyperlink{group__keyset_ga671e1aaee3ae9dc13b4834a4ddbd2c3c}{ksNew()} 
\end{DoxySeeAlso}
\hypertarget{group__keyset_gac59e4b328245463f1451f68d5106151c}{
\index{keyset@{keyset}!ksDup@{ksDup}}
\index{ksDup@{ksDup}!keyset@{keyset}}
\subsubsection[{ksDup}]{\setlength{\rightskip}{0pt plus 5cm}{\bf KeySet}$\ast$ ksDup (
\begin{DoxyParamCaption}
\item[{const {\bf KeySet} $\ast$}]{ source}
\end{DoxyParamCaption}
)}}
\label{group__keyset_gac59e4b328245463f1451f68d5106151c}
Return a duplicate of a keyset.

Objects created with \hyperlink{group__keyset_gac59e4b328245463f1451f68d5106151c}{ksDup()} must be destroyed with \hyperlink{group__keyset_ga27e5c16473b02a422238c8d970db7ac8}{ksDel()}.

Memory will be allocated as needed for dynamic properties, so you need to \hyperlink{group__keyset_ga27e5c16473b02a422238c8d970db7ac8}{ksDel()} 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}{ksDel()}.


\begin{DoxyParams}{Parameters}
\item[{\em source}]has to be an initializised source KeySet \end{DoxyParams}
\begin{DoxyReturn}{Returns}
a flat copy of source on success 

0 on NULL pointer 
\end{DoxyReturn}
\begin{DoxySeeAlso}{See also}
\hyperlink{group__keyset_ga671e1aaee3ae9dc13b4834a4ddbd2c3c}{ksNew()}, \hyperlink{group__keyset_ga27e5c16473b02a422238c8d970db7ac8}{ksDel()} 

\hyperlink{group__key_gae6ec6a60cc4b8c1463fa08623d056ce3}{keyDup()} for \hyperlink{group__key}{Key :: Basic Methods} duplication 
\end{DoxySeeAlso}
\hypertarget{group__keyset_gaffe507ab9281c322eb16c3e992075d29}{
\index{keyset@{keyset}!ksGetCursor@{ksGetCursor}}
\index{ksGetCursor@{ksGetCursor}!keyset@{keyset}}
\subsubsection[{ksGetCursor}]{\setlength{\rightskip}{0pt plus 5cm}cursor\_\-t ksGetCursor (
\begin{DoxyParamCaption}
\item[{const {\bf KeySet} $\ast$}]{ ks}
\end{DoxyParamCaption}
)}}
\label{group__keyset_gaffe507ab9281c322eb16c3e992075d29}
Get the KeySet 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}{ksPop()}ed or \hyperlink{group__keyset_gaa34fc43a081e6b01e4120daa6c112004}{ksLookup()} with KDB\_\-O\_\-POP 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;
ksRewind (ks);
while ((key = keyNextMeta (ks))!=0)
{
        // now mark this key
        jump = ksGetCursor(ks);

        //code..
        keyNextMeta (ks); // now browse on
        // use ksCurrent(ks) to check the keys
        //code..

        // jump back to the position marked before
        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}
int f (KeySet *ks)
{
        cursor_t state = ksGetCursor(ks);

        // work with keyset

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


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

An invalid cursor will be returned directly after \hyperlink{group__keyset_gabe793ff51f1728e3429c84a8a9086b70}{ksRewind()}. When you set an invalid cursor \hyperlink{group__keyset_ga4287b9416912c5f2ab9c195cb74fb094}{ksCurrent()} is 0 and \hyperlink{group__keyset_ga317321c9065b5a4b3e33fe1c399bcec9}{ksNext()} == \hyperlink{group__keyset_gae7dbf3aef70e67b5328475eb3d1f92f5}{ksHead()}.

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

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

an invalid cursor on NULL pointer or after \hyperlink{group__keyset_gabe793ff51f1728e3429c84a8a9086b70}{ksRewind()} 
\end{DoxyReturn}
\begin{DoxySeeAlso}{See also}
\hyperlink{group__keyset_ga317321c9065b5a4b3e33fe1c399bcec9}{ksNext()}, \hyperlink{group__keyset_gad94c9ffaa3e8034564c0712fd407c345}{ksSetCursor()} 
\end{DoxySeeAlso}
\hypertarget{group__keyset_ga7474ad6b0a0fa969dbdf267ba5770eee}{
\index{keyset@{keyset}!ksGetSize@{ksGetSize}}
\index{ksGetSize@{ksGetSize}!keyset@{keyset}}
\subsubsection[{ksGetSize}]{\setlength{\rightskip}{0pt plus 5cm}ssize\_\-t ksGetSize (
\begin{DoxyParamCaption}
\item[{const {\bf KeySet} $\ast$}]{ ks}
\end{DoxyParamCaption}
)}}
\label{group__keyset_ga7474ad6b0a0fa969dbdf267ba5770eee}
Return the number of keys that {\ttfamily ks} contains.


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

-\/1 on NULL pointer 
\end{DoxyReturn}
\begin{DoxySeeAlso}{See also}
ksNew(0), \hyperlink{group__keyset_ga27e5c16473b02a422238c8d970db7ac8}{ksDel()} 
\end{DoxySeeAlso}
\hypertarget{group__keyset_gae7dbf3aef70e67b5328475eb3d1f92f5}{
\index{keyset@{keyset}!ksHead@{ksHead}}
\index{ksHead@{ksHead}!keyset@{keyset}}
\subsubsection[{ksHead}]{\setlength{\rightskip}{0pt plus 5cm}{\bf Key}$\ast$ ksHead (
\begin{DoxyParamCaption}
\item[{const {\bf KeySet} $\ast$}]{ ks}
\end{DoxyParamCaption}
)}}
\label{group__keyset_gae7dbf3aef70e67b5328475eb3d1f92f5}
Return the first key in the KeySet.

The KeySets cursor will not be effected.

If \hyperlink{group__keyset_ga4287b9416912c5f2ab9c195cb74fb094}{ksCurrent()}==ksHead() you know you are on the first key.


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

0 on NULL pointer or empty keyset 
\end{DoxyReturn}
\begin{DoxySeeAlso}{See also}
\hyperlink{group__keyset_gadca442c4ab43cf532b15091d7711559e}{ksTail()} for the last \hyperlink{group__key}{Key :: Basic Methods} 

\hyperlink{group__keyset_gabe793ff51f1728e3429c84a8a9086b70}{ksRewind()}, \hyperlink{group__keyset_ga4287b9416912c5f2ab9c195cb74fb094}{ksCurrent()} and \hyperlink{group__keyset_ga317321c9065b5a4b3e33fe1c399bcec9}{ksNext()} for iterating over the \hyperlink{group__keyset}{KeySet :: Class Methods} 
\end{DoxySeeAlso}
\hypertarget{group__keyset_gaa34fc43a081e6b01e4120daa6c112004}{
\index{keyset@{keyset}!ksLookup@{ksLookup}}
\index{ksLookup@{ksLookup}!keyset@{keyset}}
\subsubsection[{ksLookup}]{\setlength{\rightskip}{0pt plus 5cm}{\bf Key}$\ast$ ksLookup (
\begin{DoxyParamCaption}
\item[{{\bf KeySet} $\ast$}]{ ks, }
\item[{{\bf Key} $\ast$}]{ key, }
\item[{{\bf option\_\-t}}]{ options}
\end{DoxyParamCaption}
)}}
\label{group__keyset_gaa34fc43a081e6b01e4120daa6c112004}
Look for a Key contained in {\ttfamily ks} that matches the name of the {\ttfamily key}.\hypertarget{group__keyset_Introduction}{}\subsection{Introduction}\label{group__keyset_Introduction}
{\ttfamily \hyperlink{group__keyset_gaa34fc43a081e6b01e4120daa6c112004}{ksLookup()}} is designed to let you work with entirely pre-\/loaded KeySets, so instead of kdbGetKey(), key by key, the idea is to fully \hyperlink{group__kdb_ga28e385fd9cb7ccfe0b2f1ed2f62453a1}{kdbGet()} for your application root key and process it all at once with {\ttfamily \hyperlink{group__keyset_gaa34fc43a081e6b01e4120daa6c112004}{ksLookup()}}.

This function is very efficient by using binary search. Together with \hyperlink{group__kdb_ga28e385fd9cb7ccfe0b2f1ed2f62453a1}{kdbGet()} which can you load the whole configuration with only some communication to backends you can write very effective but short code for configuration.\hypertarget{group__keyset_Usage}{}\subsection{Usage}\label{group__keyset_Usage}
If found, {\ttfamily ks} internal cursor will be positioned in the matched key (also accessible by \hyperlink{group__keyset_ga4287b9416912c5f2ab9c195cb74fb094}{ksCurrent()}), and a pointer to the Key is returned. If not found, {\ttfamily ks} internal cursor will not move, and a NULL pointer is returned.

Cascading is done if the first character is a /. This leads to ignoring the prefix like system/ and user/. 
\begin{DoxyCode}
if (kdbGet(handle, "user/myapp", myConfig, 0 ) == -1)
        errorHandler ("Could not get Keys");

if (kdbGet(handle, "system/myapp", myConfig, 0 ) == -1)
        errorHandler ("Could not get Keys");

if ((myKey = ksLookup(myConfig, key, 0)) == NULL)
        errorHandler ("Could not Lookup Key");
\end{DoxyCode}


This is the way multi user Programs should get there 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.\hypertarget{group__keyset_KDB_O_NOALL}{}\subsubsection{KDB\_\-O\_\-NOALL}\label{group__keyset_KDB_O_NOALL}
When KDB\_\-O\_\-NOALL is set the keyset will be only searched from \hyperlink{group__keyset_ga4287b9416912c5f2ab9c195cb74fb094}{ksCurrent()} to \hyperlink{group__keyset_gadca442c4ab43cf532b15091d7711559e}{ksTail()}. You need to \hyperlink{group__keyset_gabe793ff51f1728e3429c84a8a9086b70}{ksRewind()} the keyset yourself. \hyperlink{group__keyset_ga4287b9416912c5f2ab9c195cb74fb094}{ksCurrent()} is always set properly after searching a key, so you can go on searching another key after the found key.

When KDB\_\-O\_\-NOALL is not set the cursor will stay untouched and all keys are considered. A much more efficient binary search will be used then.\hypertarget{group__keyset_KDB_O_POP}{}\subsubsection{KDB\_\-O\_\-POP}\label{group__keyset_KDB_O_POP}
When KDB\_\-O\_\-POP is set the key which was found will be \hyperlink{group__keyset_gae42530b04defb772059de0600159cf69}{ksPop()}ed. \hyperlink{group__keyset_ga4287b9416912c5f2ab9c195cb74fb094}{ksCurrent()} will not be changed, only iff \hyperlink{group__keyset_ga4287b9416912c5f2ab9c195cb74fb094}{ksCurrent()} is the searched key, then the keyset will be \hyperlink{group__keyset_gabe793ff51f1728e3429c84a8a9086b70}{ksRewind()}ed.

\begin{DoxyNote}{Note}
Like in \hyperlink{group__keyset_gae42530b04defb772059de0600159cf69}{ksPop()} the popped key always needs to be \hyperlink{group__key_ga3df95bbc2494e3e6703ece5639be5bb1}{keyDel()} 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 KDB\_\-O\_\-POP, so don't use this if you rely on a cursor, see \hyperlink{group__keyset_gaffe507ab9281c322eb16c3e992075d29}{ksGetCursor()}.
\end{DoxyWarning}
You can solve this problem by using KDB\_\-O\_\-NOALL, risking you have to iterate n$^\wedge$2 instead of n.

The more elegant way is to separate the keyset you use for \hyperlink{group__keyset_gaa34fc43a081e6b01e4120daa6c112004}{ksLookup()} and \hyperlink{group__keyset_gaa5a1d467a4d71041edce68ea7748ce45}{ksAppendKey()}: 
\begin{DoxyCode}
int f(KeySet *iterator, KeySet *lookup)
{
        KeySet *append = ksNew (ksGetSize(lookup), KS_END);
        Key *key;
        Key *current;

        ksRewind(iterator);
        while (current=ksNext(iterator))
        {
                key = ksLookup (lookup, current, KDB_O_POP);
                // do something...
                ksAppendKey(append, key); // now append it to append, not lookup!
      
                keyDel (key); // make sure to ALWAYS delete poped keys.
        }
        ksAppend(lookup, append);
        // now lookup needs to be sorted only once, append never
        ksDel (append);
}
\end{DoxyCode}



\begin{DoxyParams}{Parameters}
\item[{\em ks}]where to look for \item[{\em key}]the key object you are looking for \item[{\em options}]some {\ttfamily KDB\_\-O\_\-$\ast$} option bits:
\begin{DoxyItemize}
\item {\ttfamily KDB\_\-O\_\-NOCASE} \par
 Lookup ignoring case.
\item {\ttfamily KDB\_\-O\_\-WITHOWNER} \par
 Also consider correct owner.
\item {\ttfamily KDB\_\-O\_\-NOALL} \par
 Only search from \hyperlink{group__keyset_ga4287b9416912c5f2ab9c195cb74fb094}{ksCurrent()} to end of keyset, see above text.
\item {\ttfamily KDB\_\-O\_\-POP} \par
 Pop the key which was found.
\item {\ttfamily KDB\_\-O\_\-DEL} \par
 Delete the passed key. 
\end{DoxyItemize}\end{DoxyParams}
\begin{DoxyReturn}{Returns}
pointer to the Key found, 0 otherwise 

0 on NULL pointers 
\end{DoxyReturn}
\begin{DoxySeeAlso}{See also}
\hyperlink{group__keyset_gad2e30fb6d4739d917c5abb2ac2f9c1a1}{ksLookupByName()} to search by a name given by a string 

\hyperlink{group__keyset_ga4287b9416912c5f2ab9c195cb74fb094}{ksCurrent()}, \hyperlink{group__keyset_gabe793ff51f1728e3429c84a8a9086b70}{ksRewind()}, \hyperlink{group__keyset_ga317321c9065b5a4b3e33fe1c399bcec9}{ksNext()} for iterating over a \hyperlink{group__keyset}{KeySet :: Class Methods} 
\end{DoxySeeAlso}
\hypertarget{group__keyset_gad2e30fb6d4739d917c5abb2ac2f9c1a1}{
\index{keyset@{keyset}!ksLookupByName@{ksLookupByName}}
\index{ksLookupByName@{ksLookupByName}!keyset@{keyset}}
\subsubsection[{ksLookupByName}]{\setlength{\rightskip}{0pt plus 5cm}{\bf Key}$\ast$ ksLookupByName (
\begin{DoxyParamCaption}
\item[{{\bf KeySet} $\ast$}]{ ks, }
\item[{const char $\ast$}]{ name, }
\item[{{\bf option\_\-t}}]{ options}
\end{DoxyParamCaption}
)}}
\label{group__keyset_gad2e30fb6d4739d917c5abb2ac2f9c1a1}
Look for a Key contained in {\ttfamily ks} that matches {\ttfamily name}.

{\ttfamily \hyperlink{group__keyset_gad2e30fb6d4739d917c5abb2ac2f9c1a1}{ksLookupByName()}} is designed to let you work with entirely pre-\/loaded KeySets, so instead of kdbGetKey(), key by key, the idea is to fully kdbGetByName() for your application root key and process it all at once with {\ttfamily \hyperlink{group__keyset_gad2e30fb6d4739d917c5abb2ac2f9c1a1}{ksLookupByName()}}.

This function is very efficient by using binary search. Together with kdbGetByName() which can you load the whole configuration with only some communication to backends you can write very effective but short code for configuration.

If found, {\ttfamily ks} internal cursor will be positioned in the matched key (also accessible by \hyperlink{group__keyset_ga4287b9416912c5f2ab9c195cb74fb094}{ksCurrent()}), and a pointer to the Key is returned. If not found, {\ttfamily ks} internal cursor will not move, and a NULL pointer is returned. If requested to pop the key, the cursor will be rewinded.\hypertarget{group__keyset_cascading}{}\subsection{Cascading}\label{group__keyset_cascading}
Cascading is done if the first character is a /. This leads to ignoring the prefix like system/ and user/. 
\begin{DoxyCode}
if (kdbGet(handle, "user/sw/myapp/current", myConfig, parentKey ) == -1)
        errorHandler ("Could not get Keys", parentKey);

if (kdbGet(handle, "system/sw/myapp/current", myConfig, parentKey ) == -1)
        errorHandler ("Could not get Keys", parentKey);

if ((myKey = ksLookupByName (myConfig, "/myapp/current/key", 0)) == NULL)
        errorHandler ("Could not Lookup Key");
\end{DoxyCode}


This is the way multi user Programs should get there 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.

It is up to the application to implement a sophisticated cascading algorithm, for e.g. a list of profiles (specific, group and fallback): 
\begin{DoxyCode}
if ((myKey = ksLookupByName (myConfig, "/myapp/current/specific/key", 0)) == NULL
      )
        if ((myKey = ksLookupByName (myConfig, "/myapp/current/group/key", 0)) ==
       NULL)
                if ((myKey = ksLookupByName (myConfig, "/myapp/current/fallback/k
      ey", 0)) == NULL)
                        errorHandler ("All fallbacks failed to lookup key");
\end{DoxyCode}


Note that for every profile both the user and the system key are searched. The first key found will be used.\hypertarget{group__keyset_fullsearch}{}\subsection{Full Search}\label{group__keyset_fullsearch}
When KDB\_\-O\_\-NOALL is set the keyset will be only searched from \hyperlink{group__keyset_ga4287b9416912c5f2ab9c195cb74fb094}{ksCurrent()} to \hyperlink{group__keyset_gadca442c4ab43cf532b15091d7711559e}{ksTail()}. You need to \hyperlink{group__keyset_gabe793ff51f1728e3429c84a8a9086b70}{ksRewind()} the keyset yourself. \hyperlink{group__keyset_ga4287b9416912c5f2ab9c195cb74fb094}{ksCurrent()} is always set properly after searching a key, so you can go on searching another key after the found key.

When KDB\_\-O\_\-NOALL is not set the cursor will stay untouched and all keys are considered. A much more efficient binary search will be used then.


\begin{DoxyParams}{Parameters}
\item[{\em ks}]where to look for \item[{\em name}]key name you are looking for \item[{\em options}]some {\ttfamily KDB\_\-O\_\-$\ast$} option bits:
\begin{DoxyItemize}
\item {\ttfamily KDB\_\-O\_\-NOCASE} \par
 Lookup ignoring case.
\item {\ttfamily KDB\_\-O\_\-WITHOWNER} \par
 Also consider correct owner.
\item {\ttfamily KDB\_\-O\_\-NOALL} \par
 Only search from \hyperlink{group__keyset_ga4287b9416912c5f2ab9c195cb74fb094}{ksCurrent()} to end of keyset, see above text.
\item {\ttfamily KDB\_\-O\_\-POP} \par
 Pop the key which was found.
\end{DoxyItemize}\end{DoxyParams}
Currently no options supported. \begin{DoxyReturn}{Returns}
pointer to the Key found, 0 otherwise 

0 on NULL pointers 
\end{DoxyReturn}
\begin{DoxySeeAlso}{See also}
\hyperlink{group__keytest_gab98168409d302fdb65692f6e26f17945}{keyCompare()} for very powerfull Key lookups in KeySets 

\hyperlink{group__keyset_ga4287b9416912c5f2ab9c195cb74fb094}{ksCurrent()}, \hyperlink{group__keyset_gabe793ff51f1728e3429c84a8a9086b70}{ksRewind()}, \hyperlink{group__keyset_ga317321c9065b5a4b3e33fe1c399bcec9}{ksNext()} 
\end{DoxySeeAlso}
\hypertarget{group__keyset_ga671e1aaee3ae9dc13b4834a4ddbd2c3c}{
\index{keyset@{keyset}!ksNew@{ksNew}}
\index{ksNew@{ksNew}!keyset@{keyset}}
\subsubsection[{ksNew}]{\setlength{\rightskip}{0pt plus 5cm}{\bf KeySet}$\ast$ ksNew (
\begin{DoxyParamCaption}
\item[{size\_\-t}]{ alloc, }
\item[{}]{ ...}
\end{DoxyParamCaption}
)}}
\label{group__keyset_ga671e1aaee3ae9dc13b4834a4ddbd2c3c}
Allocate, initialize and return a new KeySet object.

Objects created with \hyperlink{group__keyset_ga671e1aaee3ae9dc13b4834a4ddbd2c3c}{ksNew()} must be destroyed with \hyperlink{group__keyset_ga27e5c16473b02a422238c8d970db7ac8}{ksDel()}.

You can use a various 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 KEY\_\-END.

So, terminate with ksNew(0) or ksNew(20, ..., KS\_\-END)

For most uses 
\begin{DoxyCode}
KeySet *keys = ksNew(0);
// work with it
ksDel (keys);
\end{DoxyCode}
 goes ok, the alloc size will be 16, defined in kdbprivate.h. The alloc size will be doubled whenever size reaches alloc size, so it also performs out 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 normally need about 12 up to 15 keys), use: 
\begin{DoxyCode}
KeySet * keys = ksNew (15,
        keyNew ("user/sw/app/fixedConfiguration/key01", KEY_SWITCH_VALUE, "value0
      1", 0),
        keyNew ("user/sw/app/fixedConfiguration/key02", KEY_SWITCH_VALUE, "value0
      2", 0),
        keyNew ("user/sw/app/fixedConfiguration/key03", KEY_SWITCH_VALUE, "value0
      3", 0),
        // ...
        keyNew ("user/sw/app/fixedConfiguration/key15", KEY_SWITCH_VALUE, "value1
      5", 0),
        KS_END);
// work with it
ksDel (keys);
\end{DoxyCode}


If you start having 3 keys, and your application needs approximately 200-\/500 keys, you can use: 
\begin{DoxyCode}
KeySet * config = ksNew (500,
        keyNew ("user/sw/app/fixedConfiguration/key1", KEY_SWITCH_VALUE, "value1"
      , 0),
        keyNew ("user/sw/app/fixedConfiguration/key2", KEY_SWITCH_VALUE, "value2"
      , 0),
        keyNew ("user/sw/app/fixedConfiguration/key3", KEY_SWITCH_VALUE, "value3"
      , 0),
        KS_END); // don't forget the KS_END at the end!
// work with it
ksDel (config);
\end{DoxyCode}
 Alloc size is 500, the size of the keyset will be 3 after ksNew. 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 KeySet.

Due to ABI compatibility, the {\ttfamily KeySet} structure is only declared in kdb.h, and not defined. So you can only declare {\ttfamily pointers} to {\ttfamily KeySets} in your program. See \href{http://tldp.org/HOWTO/Program-Library-HOWTO/shared-libraries.html#AEN135}{\tt http://tldp.org/HOWTO/Program-\/Library-\/HOWTO/shared-\/libraries.html\#AEN135}

\begin{DoxySeeAlso}{See also}
\hyperlink{group__keyset_ga27e5c16473b02a422238c8d970db7ac8}{ksDel()} to free the \hyperlink{group__keyset}{KeySet :: Class Methods} afterwards 

\hyperlink{group__keyset_gac59e4b328245463f1451f68d5106151c}{ksDup()} to duplicate an existing \hyperlink{group__keyset}{KeySet :: Class Methods} 
\end{DoxySeeAlso}

\begin{DoxyParams}{Parameters}
\item[{\em alloc}]gives a hint for the size how many Keys may be stored initially \end{DoxyParams}
\begin{DoxyReturn}{Returns}
a ready to use KeySet object 

0 on memory error 
\end{DoxyReturn}
\hypertarget{group__keyset_ga317321c9065b5a4b3e33fe1c399bcec9}{
\index{keyset@{keyset}!ksNext@{ksNext}}
\index{ksNext@{ksNext}!keyset@{keyset}}
\subsubsection[{ksNext}]{\setlength{\rightskip}{0pt plus 5cm}{\bf Key}$\ast$ ksNext (
\begin{DoxyParamCaption}
\item[{{\bf KeySet} $\ast$}]{ ks}
\end{DoxyParamCaption}
)}}
\label{group__keyset_ga317321c9065b5a4b3e33fe1c399bcec9}
Returns the next Key in a KeySet.

KeySets have an internal cursor that can be reset with \hyperlink{group__keyset_gabe793ff51f1728e3429c84a8a9086b70}{ksRewind()}. Every time \hyperlink{group__keyset_ga317321c9065b5a4b3e33fe1c399bcec9}{ksNext()} is called the cursor is incremented and the new current Key is returned.

You'll get a NULL pointer if the key after the end of the KeySet was reached. On subsequent calls of \hyperlink{group__keyset_ga317321c9065b5a4b3e33fe1c399bcec9}{ksNext()} it will still return the NULL 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}{ksPop()} if you want to delete it.
\end{DoxyNote}

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

0 when the end is reached 

0 on NULL pointer 
\end{DoxyReturn}
\begin{DoxySeeAlso}{See also}
\hyperlink{group__keyset_gabe793ff51f1728e3429c84a8a9086b70}{ksRewind()}, \hyperlink{group__keyset_ga4287b9416912c5f2ab9c195cb74fb094}{ksCurrent()} 
\end{DoxySeeAlso}
\hypertarget{group__keyset_gae42530b04defb772059de0600159cf69}{
\index{keyset@{keyset}!ksPop@{ksPop}}
\index{ksPop@{ksPop}!keyset@{keyset}}
\subsubsection[{ksPop}]{\setlength{\rightskip}{0pt plus 5cm}{\bf Key}$\ast$ ksPop (
\begin{DoxyParamCaption}
\item[{{\bf KeySet} $\ast$}]{ ks}
\end{DoxyParamCaption}
)}}
\label{group__keyset_gae42530b04defb772059de0600159cf69}
Remove and return the last key of {\ttfamily ks}.

The reference counter will be decremented by one.

The KeySets cursor will not be effected if it did not point to the popped key.

\begin{DoxyNote}{Note}
You need to \hyperlink{group__key_ga3df95bbc2494e3e6703ece5639be5bb1}{keyDel()} the key afterwards, if you don't append it to another keyset. It has the same semantics like a key allocated with \hyperlink{group__key_gaf6893c038b3ebee90c73a9ea8356bebf}{keyNew()} or \hyperlink{group__key_gae6ec6a60cc4b8c1463fa08623d056ce3}{keyDup()}.
\end{DoxyNote}

\begin{DoxyCode}
ks1=ksNew(0);
ks2=ksNew(0);

k1=keyNew("user/name", KEY_END); // ref counter 0
ksAppendKey(ks1, k1); // ref counter 1
ksAppendKey(ks2, k1); // ref counter 2

k1=ksPop (ks1); // ref counter 1
k1=ksPop (ks2); // ref counter 0, like after keyNew()

ksAppendKey(ks1, k1); // ref counter 1

ksDel (ks1); // key is deleted too
ksDel (ks2);
 *
\end{DoxyCode}


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

NULL if {\ttfamily ks} is empty or on NULL pointer 
\end{DoxyReturn}

\begin{DoxyParams}{Parameters}
\item[{\em ks}]KeySet to work with \end{DoxyParams}
\begin{DoxySeeAlso}{See also}
\hyperlink{group__keyset_gaa5a1d467a4d71041edce68ea7748ce45}{ksAppendKey()}, \hyperlink{group__keyset_ga21eb9c3a14a604ee3a8bdc779232e7b7}{ksAppend()} 

commandList() for an example 
\end{DoxySeeAlso}
\hypertarget{group__keyset_gabe793ff51f1728e3429c84a8a9086b70}{
\index{keyset@{keyset}!ksRewind@{ksRewind}}
\index{ksRewind@{ksRewind}!keyset@{keyset}}
\subsubsection[{ksRewind}]{\setlength{\rightskip}{0pt plus 5cm}int ksRewind (
\begin{DoxyParamCaption}
\item[{{\bf KeySet} $\ast$}]{ ks}
\end{DoxyParamCaption}
)}}
\label{group__keyset_gabe793ff51f1728e3429c84a8a9086b70}
Rewinds the KeySet internal cursor.

Use it to set the cursor to the beginning of the KeySet. \hyperlink{group__keyset_ga4287b9416912c5f2ab9c195cb74fb094}{ksCurrent()} will then always return NULL afterwards. So you want to \hyperlink{group__keyset_ga317321c9065b5a4b3e33fe1c399bcec9}{ksNext()} first.


\begin{DoxyCode}
ksRewind (ks);
while ((key = ksNext (ks))!=0) {}
\end{DoxyCode}



\begin{DoxyParams}{Parameters}
\item[{\em ks}]the keyset object to work with \end{DoxyParams}
\begin{DoxyReturn}{Returns}
0 on success 

-\/1 on NULL pointer 
\end{DoxyReturn}
\begin{DoxySeeAlso}{See also}
\hyperlink{group__keyset_ga317321c9065b5a4b3e33fe1c399bcec9}{ksNext()}, \hyperlink{group__keyset_ga4287b9416912c5f2ab9c195cb74fb094}{ksCurrent()} 
\end{DoxySeeAlso}
\hypertarget{group__keyset_gad94c9ffaa3e8034564c0712fd407c345}{
\index{keyset@{keyset}!ksSetCursor@{ksSetCursor}}
\index{ksSetCursor@{ksSetCursor}!keyset@{keyset}}
\subsubsection[{ksSetCursor}]{\setlength{\rightskip}{0pt plus 5cm}int ksSetCursor (
\begin{DoxyParamCaption}
\item[{{\bf KeySet} $\ast$}]{ ks, }
\item[{cursor\_\-t}]{ cursor}
\end{DoxyParamCaption}
)}}
\label{group__keyset_gad94c9ffaa3e8034564c0712fd407c345}
Set the KeySet internal cursor.

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

\begin{DoxyWarning}{Warning}
Cursors may get invalid when the key was \hyperlink{group__keyset_gae42530b04defb772059de0600159cf69}{ksPop()}ed or \hyperlink{group__keyset_gaa34fc43a081e6b01e4120daa6c112004}{ksLookup()} was used together with KDB\_\-O\_\-POP.
\end{DoxyWarning}

\begin{DoxyCode}
cursor_t cursor;
..
// key now in any position here
cursor = ksGetCursor (ks);
while ((key = keyNextMeta (ks))!=0) {}
ksSetCursor (ks, cursor); // reset state
ksCurrent(ks); // in same position as before
\end{DoxyCode}


An invalid cursor will set the keyset to its beginning like \hyperlink{group__keyset_gabe793ff51f1728e3429c84a8a9086b70}{ksRewind()}. When you set an invalid cursor \hyperlink{group__keyset_ga4287b9416912c5f2ab9c195cb74fb094}{ksCurrent()} is 0 and \hyperlink{group__keyset_ga317321c9065b5a4b3e33fe1c399bcec9}{ksNext()} == \hyperlink{group__keyset_gae7dbf3aef70e67b5328475eb3d1f92f5}{ksHead()}.


\begin{DoxyParams}{Parameters}
\item[{\em cursor}]the cursor to use \item[{\em ks}]the keyset object to work with \end{DoxyParams}
\begin{DoxyReturn}{Returns}
0 when the keyset is \hyperlink{group__keyset_gabe793ff51f1728e3429c84a8a9086b70}{ksRewind()}ed 

1 otherwise 

-\/1 on NULL pointer 
\end{DoxyReturn}
\begin{DoxySeeAlso}{See also}
\hyperlink{group__keyset_ga317321c9065b5a4b3e33fe1c399bcec9}{ksNext()}, \hyperlink{group__keyset_gaffe507ab9281c322eb16c3e992075d29}{ksGetCursor()} 
\end{DoxySeeAlso}
\hypertarget{group__keyset_gadca442c4ab43cf532b15091d7711559e}{
\index{keyset@{keyset}!ksTail@{ksTail}}
\index{ksTail@{ksTail}!keyset@{keyset}}
\subsubsection[{ksTail}]{\setlength{\rightskip}{0pt plus 5cm}{\bf Key}$\ast$ ksTail (
\begin{DoxyParamCaption}
\item[{const {\bf KeySet} $\ast$}]{ ks}
\end{DoxyParamCaption}
)}}
\label{group__keyset_gadca442c4ab43cf532b15091d7711559e}
Return the last key in the KeySet.

The KeySets cursor will not be effected.

If \hyperlink{group__keyset_ga4287b9416912c5f2ab9c195cb74fb094}{ksCurrent()}==ksTail() you know you are on the last key. \hyperlink{group__keyset_ga317321c9065b5a4b3e33fe1c399bcec9}{ksNext()} will return a NULL pointer afterwards.


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

0 on NULL pointer or empty keyset 
\end{DoxyReturn}
\begin{DoxySeeAlso}{See also}
\hyperlink{group__keyset_gae7dbf3aef70e67b5328475eb3d1f92f5}{ksHead()} for the first \hyperlink{group__key}{Key :: Basic Methods} 

\hyperlink{group__keyset_gabe793ff51f1728e3429c84a8a9086b70}{ksRewind()}, \hyperlink{group__keyset_ga4287b9416912c5f2ab9c195cb74fb094}{ksCurrent()} and \hyperlink{group__keyset_ga317321c9065b5a4b3e33fe1c399bcec9}{ksNext()} for iterating over the \hyperlink{group__keyset}{KeySet :: Class Methods} 
\end{DoxySeeAlso}
