Welcome to little lamb

Code » limb » release » tree

[release] / src / doc / cdb.h / cdb_traverse_init.3.md

% limb manual
% cdb_traverse_init(3)
% limb 0.1.0
% 2023-07-24

# NAME

cdb_traverse_init, cdb_traverse_next - iterate over a cdb

# SYNOPSIS

    #include <limb/cdb.h>

```pre hl
void cdb_traverse_init(cdb_traverse *<em>trav</em>)
int cdb_traverse_next(const cdb *<em>c</em>, cdb_data *<em>key</em>, cdb_data *<em>data</em>, cdb_traverse *<em>trav</em>)
```

# DESCRIPTION

The `cdb_traverse_init`() macro initialize the state pointed by `trav` so that
the next invocation of `cdb_traverse_next`() using that state will find the
first element in the database.

The `cdb_traverse_next`() function find the next element in the *cdb* pointed by
`c`, as per the state pointed by `trav`.
When found, information about the key is placed into the *cdb_data* pointed by
`key` while information about the data associated with the element is placed
into the *cdb_data* pointed by `data`.
The state pointed by `trav` is also updated so that the next call using the same
arguments for `c` and `trav` return the next element in the database, if any,
until all elements have been found.

# RETURN VALUE

The `cdb_traverse_next`() function returns -1 when either the *cdb* pointed by
`c` or the state pointed by `trav` is invalid; It returns 1 on success, i.e. an
element was found and information about its key and associated data were set
inside the *cdb_data* pointed by `key` and `data`, respectively.

Otherwise, i.e. no more element were found (i.e. the entire database has been
iterated over), it returns 0.