Class: Containers::XORList

Inherits:
Object
  • Object
show all
Defined in:
lib/containers/xor_list.rb,
ext/containers/xor_list/xor_list.c

Instance Method Summary collapse

Constructor Details

#initializeObject



78
79
80
81
# File 'ext/containers/xor_list/xor_list.c', line 78

static VALUE xor_list_init(VALUE self)
{
	return self;
}

Instance Method Details

#eachObject



98
99
100
101
102
103
104
105
106
107
108
109
# File 'ext/containers/xor_list/xor_list.c', line 98

static VALUE xor_list_each(VALUE self) {
    xor_list *list = get_xor_list(self);
    node *current = list->front;
    node *prev = NULL, *next = NULL;
    while(current) {
        rb_yield(current->obj);
        next = xor(prev, current->npx);
        prev = current;
        current = next;
    }
    return self;
}

#push_front(obj) ⇒ Object



83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'ext/containers/xor_list/xor_list.c', line 83

static VALUE xor_list_push_front(VALUE self, VALUE obj) {
	xor_list *list = get_xor_list(self);
	node *current = create_node(obj);
	if(list->front) {
		current->npx = xor(NULL, list->front);
		list->front->npx = xor(current, xor(NULL, list->front->npx));
	}
	else {
		list->back = current;
	}
	list->front = current;
	list->size++;
	return obj;
}