Beispiel #1
0
int main(int argc, char* argv[]) {
    Set s = Set_new();
    int   a = 42;
    char* b = "hello";
    assert(Set_size(s) == 0);
    Set_show(s, stdout, &show_func);
    Set_add(s, &a);
    assert(Set_size(s) == 1);
    Set_show(s, stdout, &show_func);
    Set_add(s, b);
    assert(Set_size(s) == 2);
    Set_show(s, stdout, &show_func);
    Set_remove(s, b);
    assert(Set_size(s) == 1);
    Set_show(s, stdout, &show_func);
    Set_remove(s, b);
    assert(Set_size(s) == 1);
    Set_show(s, stdout, &show_func);

    fprintf(stdout, "All tests passed!\n");
}
Beispiel #2
0
oe_id Oec_IdSet_remove(T _this_, oe_id mid) {
    ID_ITEM item;
    item.mid = mid;
    ID_ITEM *removeme = (ID_ITEM *) Set_remove(_this_->members, &item);
    oe_id retid;
    if (removeme != NULL) {
        retid = mid;
    } else {
        retid = (oe_id) 0;
    }
    Mem_free(removeme, __FILE__, __LINE__);
    return retid;
}
Beispiel #3
0
static void _remove_item(Table_T items, item_ *rmitem, bool timeout) {

    if (rmitem == NULL) {
        return;
    }
    if (rmitem->group) {
        // get each item from the list, null out the list field and
        // recursively call this until the whole set is removed
        _remove_group(items, rmitem->group, timeout);
        return;
    }

    Set_T s = rmitem->items;
    item_ *item = NULL;
    if (s) {
        item = Set_remove(s, (void *) rmitem); //if this was a dummy item from a timeout, get the real one
    }
    if (!item) return;

    if (item->timer_event) {
        timeout_del(item->timer_event);
        Mem_free(item->timer_event, __FILE__, __LINE__);
    }

    if ( timeout && item->timeout_handler!=NULL ) {
        _process_fun(item->timeout_handler, item->args);
    }
    if (rmitem != item) {
        Mem_free(rmitem, __FILE__, __LINE__); //a clone
    }

    if (item->key_idx) {
        oe_scalar key = item->object[item->key_idx];
        if (s) 
        if (key && Set_length(s) <= 0) {
            if (items) {
                Table_remove(items, key);
            }
            if (s) {
                Set_free( &s );
            }
        }
    }
    Mem_free(item, __FILE__, __LINE__);
}