Exemple #1
0
/* Delete an element with matching score/object from the skiplist. */
int slDelete(skiplist *sl, double score, slobj *obj) {
    skiplistNode *update[SKIPLIST_MAXLEVEL], *x;
    int i;

    x = sl->header;
    for (i = sl->level-1; i >= 0; i--) {
        while (x->level[i].forward &&
            (x->level[i].forward->score < score ||
                (x->level[i].forward->score == score &&
                compareslObj(x->level[i].forward->obj,obj) < 0)))
            x = x->level[i].forward;
        update[i] = x;
    }
    /* We may have multiple elements with the same score, what we need
     * is to find the element with both the right score and object. */
    x = x->level[0].forward;
    if (x && score == x->score && equalslObj(x->obj,obj)) {
        slDeleteNode(sl, x, update);
        slFreeNode(x);
        return 1;
    } else {
        return 0; /* not found */
    }
    return 0; /* not found */
}
Exemple #2
0
 int slDelete(skiplist *sl, double score) {
     skiplistNode *update[SKIPLIST_MAXLEVEL], *node;
     int i;
 
     node = sl->header;
     for(i = sl->level-1; i >= 0; i--) {
         while (node->level[i].forward && node->level[i].forward->score < score) {
             node = node->level[i].forward;
         }
         update[i] = node;
     }
     node = node->level[0].forward;
     if (node && score == node->score) {
         slDeleteNode(sl, node, update);
         slFreeNode(node);
         return 1;
     } else {
         return 0;
     }
     return 0;
 }