src/imap/imap.c
/*
 * Add data by id to the map.
 *
 * Returns 0 when data is added. Data will NOT be overwritten.
 *
 * In case of a memory error we return -1. If the id
 * already exists -2 will be returned.
 */
Add data by id to the map.
Returns 0 when data is added. Data will NOT be overwritten.

In case of a memory error we return -1. If the id
already exists -2 will be returned.
Add data by id to the map . Returns 0 when data is added . Data will NOT be overwritten . In case of a memory error we return - 1 . If the id already exists - 2 will be returned .
static int IMAP_add(imap_node_t * node, uint64_t id, void * data)
{
    if (!node->size)
    {
        node->nodes = (imap_node_t *) calloc(
                IMAP_NODE_SZ,
                sizeof(imap_node_t));
        if (node->nodes == NULL)
        {
            return -1;
        }
    }
    int rc;
    imap_node_t * nd = node->nodes + (id % IMAP_NODE_SZ);
    id /= IMAP_NODE_SZ;
    if (!id)
    {
        if (nd->data != NULL)
        {
            return -2;
        }
        nd->data = data;
        node->size++;
        return 0;
    }
    rc = IMAP_add(nd, id - 1, data);
    if (rc == 0)
    {
        node->size++;
    }
    return rc;
}
static int IMAP_add ( imap_node_t * node , uint64_t id , void * data ) { if ( ! node -> size ) { node -> nodes = ( imap_node_t * ) calloc ( IMAP_NODE_SZ , sizeof ( imap_node_t ) ) ; if ( node -> nodes == NULL ) { return -1 ; } } int rc ; imap_node_t * nd = node -> nodes + ( id % IMAP_NODE_SZ ) ; id /= IMAP_NODE_SZ ; if ( ! id ) { if ( nd -> data != NULL ) { return -2 ; } nd -> data = data ; node -> size ++ ; return 0 ; } rc = IMAP_add ( nd , id - 1 , data ) ; if ( rc == 0 ) { node -> size ++ ; } return rc ; }
Add data by id to the map.
Add data by id to the map .