---
name: "mdb_idls"
section: "3"
platform: "linux"
package: "lmdb-doc"
version: "0.9.31-1"
release: "Debian 13 (Trixie)"
platforms: ["linux"]
url: "https://new.carta.tech/mdb_idls"
---

# mdb\_idls(3)

ID List Management

## NAME

idls - ID List Management

## SYNOPSIS

### Data Structures

struct **MDB\_ID2**\

### Macros

\#define **MDB\_IDL\_LOGN**   16	/\* DB\_SIZE is 2^16, UM\_SIZE is 2^17 \*/\
 \#define **MDB\_IDL\_DB\_SIZE**   (1\<\<MDB\_IDL\_LOGN)\
 \#define **MDB\_IDL\_UM\_SIZE**   (1\<\<(MDB\_IDL\_LOGN+1))\
 \#define **MDB\_IDL\_DB\_MAX**   (MDB\_IDL\_DB\_SIZE-1)\
 \#define **MDB\_IDL\_UM\_MAX**   (MDB\_IDL\_UM\_SIZE-1)\
 \#define **MDB\_IDL\_SIZEOF**(ids)   (((ids)\[0\]+1) \* sizeof(**MDB\_ID**))\
 \#define **MDB\_IDL\_IS\_ZERO**(ids)   ( (ids)\[0\] == 0 )\
 \#define **MDB\_IDL\_CPY**(dst,  src)   (memcpy( dst, src, MDB\_IDL\_SIZEOF( src ) ))\
 \#define **MDB\_IDL\_FIRST**(ids)   ( (ids)\[1\] )\
 \#define **MDB\_IDL\_LAST**(ids)   ( (ids)\[(ids)\[0\]\] )\
 \#define **MDB\_IDL\_ALLOCLEN**(ids)   ( (ids)\[-1\] )\
 \#define **mdb\_midl\_xappend**(idl,  id)\
 \#define **CMP**(x,  y)   ( (x) \< (y) ? -1 : (x) \> (y) )\
 \#define **SMALL**   8\
 \#define **MIDL\_SWAP**(a,  b)   { itmp=(a); (a)=(b); (b)=itmp; }\

### Typedefs

typedef size\_t **MDB\_ID**\
 typedef **MDB\_ID** \* **MDB\_IDL**\
 typedef **MDB\_ID2** \* **MDB\_ID2L**\

### Functions

unsigned **mdb\_midl\_search** (**MDB\_IDL** ids, **MDB\_ID** id)\
 **MDB\_IDL** **mdb\_midl\_alloc** (int num)\
 void **mdb\_midl\_free** (**MDB\_IDL** ids)\
 void **mdb\_midl\_shrink** (**MDB\_IDL** \*idp)\
 int **mdb\_midl\_need** (**MDB\_IDL** \*idp, unsigned num)\
 int **mdb\_midl\_append** (**MDB\_IDL** \*idp, **MDB\_ID** id)\
 int **mdb\_midl\_append\_list** (**MDB\_IDL** \*idp, **MDB\_IDL** app)\
 int **mdb\_midl\_append\_range** (**MDB\_IDL** \*idp, **MDB\_ID** id, unsigned n)\
 void **mdb\_midl\_xmerge** (**MDB\_IDL** idl, **MDB\_IDL** merge)\
 void **mdb\_midl\_sort** (**MDB\_IDL** ids)\
 unsigned **mdb\_mid2l\_search** (**MDB\_ID2L** ids, **MDB\_ID** id)\
 int **mdb\_mid2l\_insert** (**MDB\_ID2L** ids, **MDB\_ID2** \*id)\
 int **mdb\_mid2l\_append** (**MDB\_ID2L** ids, **MDB\_ID2** \*id)\
 static int **mdb\_midl\_grow** (**MDB\_IDL** \*idp, int num)\

## Detailed Description

## Data Structure Documentation

## struct MDB\_ID2

An ID2 is an ID/pointer pair.

**Data Fields**

**MDB\_ID** **mid**\
 void \* **mptr**\

## Field Documentation

### MDB\_ID MDB\_ID2::mid

The ID

### void\* MDB\_ID2::mptr

The pointer

## Macro Definition Documentation

### #define MDB\_IDL\_ALLOCLEN(ids) ( (ids)\[-1\] )

Current max length of an **mdb\_midl\_alloc()**ed IDL

### #define mdb\_midl\_xappend(idl, id)

**Value:**

```
       do {         MDB_ID *xidl = (idl), xlen = ++(xidl[0]);         xidl[xlen] = (id);     } while (0)
```

Append ID to IDL. The IDL must be big enough.

## Typedef Documentation

### typedef size\_t MDB\_ID

A generic unsigned ID number. These were entryIDs in back-bdb. Preferably it should have the same size as a pointer.

### typedef MDB\_ID\* MDB\_IDL

An IDL is an ID List, a sorted array of IDs. The first element of the array is a counter for how many actual IDs are in the list. In the original back-bdb code, IDLs are sorted in ascending order. For libmdb IDLs are sorted in descending order.

### typedef MDB\_ID2\* MDB\_ID2L

An ID2L is an ID2 List, a sorted array of ID2s. The first element's **mid** member is a count of how many actual elements are in the array. The **mptr** member of the first element is unused. The array is sorted in ascending order by **mid**.

## Function Documentation

### unsigned mdb\_midl\_search (MDB\_IDL ids, MDB\_ID id)

Search for an ID in an IDL.

**Parameters**

*ids* The IDL to search. \
 *id* The ID to search for.

**Returns**

The index of the first ID greater than or equal to **id**.

### MDB\_IDL mdb\_midl\_alloc (int num)

Allocate an IDL. Allocates memory for an IDL of the given size.

**Returns**

IDL on success, NULL on failure.

### void mdb\_midl\_free (MDB\_IDL ids)

Free an IDL.

**Parameters**

*ids* The IDL to free.

### void mdb\_midl\_shrink (MDB\_IDL \* idp)

Shrink an IDL. Return the IDL to the default size if it has grown larger.

**Parameters**

*idp* Address of the IDL to shrink.

### int mdb\_midl\_need (MDB\_IDL \* idp, unsigned num)

Make room for num additional elements in an IDL.

**Parameters**

*idp* Address of the IDL. \
 *num* Number of elements to make room for.

**Returns**

0 on success, ENOMEM on failure.

### int mdb\_midl\_append (MDB\_IDL \* idp, MDB\_ID id)

Append an ID onto an IDL.

**Parameters**

*idp* Address of the IDL to append to. \
 *id* The ID to append.

**Returns**

0 on success, ENOMEM if the IDL is too large.

### int mdb\_midl\_append\_list (MDB\_IDL \* idp, MDB\_IDL app)

Append an IDL onto an IDL.

**Parameters**

*idp* Address of the IDL to append to. \
 *app* The IDL to append.

**Returns**

0 on success, ENOMEM if the IDL is too large.

### int mdb\_midl\_append\_range (MDB\_IDL \* idp, MDB\_ID id, unsigned n)

Append an ID range onto an IDL.

**Parameters**

*idp* Address of the IDL to append to. \
 *id* The lowest ID to append. \
 *n* Number of IDs to append.

**Returns**

0 on success, ENOMEM if the IDL is too large.

### void mdb\_midl\_xmerge (MDB\_IDL idl, MDB\_IDL merge)

Merge an IDL onto an IDL. The destination IDL must be big enough.

**Parameters**

*idl* The IDL to merge into. \
 *merge* The IDL to merge.

### void mdb\_midl\_sort (MDB\_IDL ids)

Sort an IDL.

**Parameters**

*ids* The IDL to sort.

### unsigned mdb\_mid2l\_search (MDB\_ID2L ids, MDB\_ID id)

Search for an ID in an ID2L.

**Parameters**

*ids* The ID2L to search. \
 *id* The ID to search for.

**Returns**

The index of the first ID2 whose **mid** member is greater than or equal to **id**.

### int mdb\_mid2l\_insert (MDB\_ID2L ids, MDB\_ID2 \* id)

Insert an ID2 into a ID2L.

**Parameters**

*ids* The ID2L to insert into. \
 *id* The ID2 to insert.

**Returns**

0 on success, -1 if the ID was already present in the ID2L.

### int mdb\_mid2l\_append (MDB\_ID2L ids, MDB\_ID2 \* id)

Append an ID2 into a ID2L.

**Parameters**

*ids* The ID2L to append into. \
 *id* The ID2 to append.

**Returns**

0 on success, -2 if the ID2L is too big.

## Author

Generated automatically by Doxygen for LMDB from the source code.
