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. When 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. When 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 . When the id already exists - 2 will be returned .
int imap_add(imap_t * imap, uint64_t id, void * data)
{
#ifdef DEBUG
    assert (data != NULL);
#endif
    imap_node_t * nd = imap->nodes + (id % IMAP_NODE_SZ);
    id /= IMAP_NODE_SZ;
    if (!id)
    {
        if (nd->data != NULL)
        {
            return -2;
        }
        imap->len++;
        nd->data = data;
    }
    else
    {
        int rc = IMAP_add(nd, id - 1, data);
        if (rc)
        {
            return rc;
        }
        imap->len++;
    }
    if (imap->slist != NULL && slist_append_safe(&imap->slist, data))
    {
        slist_free(imap->slist);
        imap->slist = NULL;
    }
    return 0;
}
int imap_add ( imap_t * imap , uint64_t id , void * data ) { #ifdef DEBUG assert ( data != NULL ) ; #endif imap_node_t * nd = imap -> nodes + ( id % IMAP_NODE_SZ ) ; id /= IMAP_NODE_SZ ; if ( ! id ) { if ( nd -> data != NULL ) { return -2 ; } imap -> len ++ ; nd -> data = data ; } else { int rc = IMAP_add ( nd , id - 1 , data ) ; if ( rc ) { return rc ; } imap -> len ++ ; } if ( imap -> slist != NULL && slist_append_safe ( & imap -> slist , data ) ) { slist_free ( imap -> slist ) ; imap -> slist = NULL ; } return 0 ; }
Add data by id to the map.
Add data by id to the map .
/* insert NULL is not allowed */