---
name: "libcritnib"
section: "3"
platform: "linux"
package: "libcritnib-dev"
version: "1.1-2+b2"
release: "Debian 13 (Trixie)"
platforms: ["linux"]
url: "https://new.carta.tech/libcritnib"
---

# libcritnib(3)

an ordered map data structure with lock-free reads

## NAME

libcritnib - an ordered map data structure with lock-free reads

## SYNOPSIS

**#include \<critnib.h\>**

Link with *-lcritnib*.

## DESCRIPTION

### Functions:

- **critnib \*critnib\_new(void);**

  Creates a new empty critnib structure.

- **void critnib\_delete(critnib \****c***);**

  Destroys and frees the memory.  Note that removed items are reused but won't have their memory freed until this function is called.

- **int critnib\_insert(critnib \****c***, uintptr\_t** *key***, void \****value***, int** *update***);**

  Adds a key:value pair to the critnib structure.  If *update* is non-zero, an already existing key has its value updated, otherwise the function returns **EEXIST**.  It may return **ENOMEM** if we're out of memory, or 0 if all went okay.

- **void \*critnib\_remove(critnib \****c***, uintptr\_t** *key***);**

  Removes a given key from the structure.  Its associated value is returned, or 0 (NULL) if there was no such key.

- **void \*critnib\_get(critnib \****c***, uintptr\_t** *key***);**

  Obtains a value for a given key, or 0 (NULL) if not present.

- **void \*critnib\_find\_le(critnib \****c***, uintptr\_t** *key***);**

  Searches for the largest key not exceeding the argument, and returns its value.

- **int critnib\_find(critnib \****c***, uintptr\_t** *key***, enum find\_dir\_t** *dir***, uintptr\_t \****rkey***, void \*\****rvalue***);**

  Searches for a key that's smaller (**FIND\_L**), smaller-or-equal (**FIND\_LE**), equal (**FIND\_EQ**), greater-or-equal (**FIND\_GE**), or greater (**FIND\_G**) than the argument.  If found, the key and value are assigned to *\*rkey* and *\*rvalue* (which may be null to skip assignment), and 1 is returned.

- **void critnib\_iter(critnib \****c***, uintptr\_t** *min***, uintptr\_t** *max***,** *func***, void \****privdata***);**

  Walks the structure, visiting all entries whose keys are at least *min* but no larger than *max* (give **-1** for no max), calling *func* for every entry found.  If the *func* returns a non-zero value, the walk is aborted.

  The prototype for *func* should be: **int (\****func***)(uintptr\_t** *key***, void \****value***, void \****privdata***);** where *privdata* is an optional value passed to the iterator.

  **NB. This version of the library implements the iterator in a crude** **blocking way, stalling any concurrent writers and iterators.  This** **limitation will be lifted in the future.**
