Esempio n. 1
0
/*
 * REQUIRES:
 *	  - cannot put duplicate key, deal it in judge_callback
 */
void skiplist_put(struct skiplist *sl, void *key)
{
    int i;
    int height;

    struct skipnode *x;
    struct skipnode *prev[SKIPLIST_MAX_LEVEL];

    memset(prev, 0, sizeof(struct skipnode*) * SKIPLIST_MAX_LEVEL);
    x = skiplist_find_greater_or_equal(sl, key, prev);
    height = _rand_height();

    /* init prev arrays */
    if (height > _get_height(sl)) {
        for (i = _get_height(sl); i < height; i++)
            prev[i] = sl->header;
        _set_height(&sl->height, &height);
    }

    x = _new_node(sl, height);
    x->key = key;

    for (i = 0; i < height; i++) {
        _set_next(&x->next[i], prev[i]->next[i]);
        _set_next(&prev[i]->next[i], x);
    }
    sl->count++;
}
Esempio n. 2
0
/*
 * call-seq:
 *   marshal_load(array) -> nil
 *
 * Provides marshalling support for use by the Marshal library.
 *
 *
 */
VALUE _marshal_load( VALUE self, VALUE data )
{
    _set_left(self, RARRAY_AREF(data,0));
    _set_top(self, RARRAY_AREF(data,1));
    _set_width(self, RARRAY_AREF(data,2));
    _set_height(self, RARRAY_AREF(data,3));

    return Qnil;
}