src/imap/imap.c
/*
 * Add data by id to the map.
 *
 * Returns 0 when data is overwritten and 1 if a new id/value is set.
 *
 * In case of an error we return -1.
 */
Add data by id to the map.
Returns 0 when data is overwritten and 1 if a new id/value is set.

In case of an error we return -1.
Add data by id to the map . Returns 0 when data is overwritten and 1 if a new id / value is set . In case of an error we return - 1 .
int imap_set(imap_t * imap, uint64_t id, void * data)
{
#ifdef DEBUG
    assert (data != NULL);
#endif
    int rc;
    imap_node_t * nd = imap->nodes + (id % IMAP_NODE_SZ);
    id /= IMAP_NODE_SZ;
    if (!id)
    {
        rc = (nd->data == NULL);
        imap->len += rc;
        nd->data = data;
    }
    else
    {
        rc = IMAP_set(nd, id - 1, data);
        if (rc > 0)
        {
            imap->len++;
        }
    }
    if (imap->slist != NULL && (
            rc < 1 || slist_append_safe(&imap->slist, data)))
    {
        slist_free(imap->slist);
        imap->slist = NULL;
    }
    return rc;
}
int imap_set ( imap_t * imap , uint64_t id , void * data ) { #ifdef DEBUG assert ( data != NULL ) ; #endif int rc ; imap_node_t * nd = imap -> nodes + ( id % IMAP_NODE_SZ ) ; id /= IMAP_NODE_SZ ; if ( ! id ) { rc = ( nd -> data == NULL ) ; imap -> len += rc ; nd -> data = data ; } else { rc = IMAP_set ( nd , id - 1 , data ) ; if ( rc > 0 ) { imap -> len ++ ; } } if ( imap -> slist != NULL && ( rc < 1 || slist_append_safe ( & imap -> slist , data ) ) ) { slist_free ( imap -> slist ) ; imap -> slist = NULL ; } return rc ; }
Add data by id to the map.
Add data by id to the map .
/* insert NULL is not allowed */