src/imap/imap.c
static int IMAP_set(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)
    {
        rc = (nd->data == NULL);

        nd->data = data;
        node->size += rc;

        return rc;
    }

    rc = IMAP_set(nd, id - 1, data);

    if (rc > 0)
    {
        node->size++;
    }

    return rc;
}
/*
 * 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 .
static int IMAP_set(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)
    {
        rc = (nd->data == NULL);
        nd->data = data;
        node->size += rc;
        return rc;
    }
    rc = IMAP_set(nd, id - 1, data);
    if (rc > 0)
    {
        node->size++;
    }
    return rc;
}
static int IMAP_set ( 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 ) { rc = ( nd -> data == NULL ) ; nd -> data = data ; node -> size += rc ; return rc ; } rc = IMAP_set ( 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 .