Class: Containers::CDeque

### Home Classes Methods

### In Files

- ext/containers/bst/bst.c

### Parent

Object

### Methods

- ::new
- #back
- #clear
- #each
- #each_backward
- #each_forward
- #empty?
- #front
- #length
- #pop_back
- #pop_front
- #push_back
- #push_front
- #reverse_each
- #size

### Files

- Makefile
- Makefile
- Makefile
- Makefile
- Makefile

### Class/Module Index

Quicksearch

- Containers
- Containers::CBst
- Containers::CDeque
- Containers::CRBTreeMap
- Containers::CSplayTreeMap
- Containers::Heap
- Containers::KDTree
- Containers::MaxHeap
- Containers::MinHeap
- Containers::PriorityQueue
- Containers::Queue
- Containers::RubyDeque
- Containers::RubyDeque
- Containers::RubyRBTreeMap
- Containers::RubyRBTreeMap
- Containers::RubySplayTreeMap
- Containers::RubySplayTreeMap
- Containers::Stack
- Containers::SuffixArray
- Containers::Trie
- Object
- Object::Deque
- Object::RBTreeMap
- Object::SplayTreeMap
- Algorithms
- Algorithms::Search
- Algorithms::String

No matching classes.

# Containers::CDeque

### Public Class Methods

new(*args) click to toggle source

    static VALUE deque_init(int argc, VALUE *argv, VALUE self)
    {
            long len, i;
            VALUE ary;

            if(argc == 0) {
                    return self;
            }
            else if(argc > 1) {
                    rb_raise(rb_eArgError, "wrong number of arguments");
            }
            else {
                    ary = rb_check_array_type(argv[0]);
                    if(!NIL_P(ary)) {
                            len = RARRAY_LEN(ary);
                            for (i = 0; i < len; i++) {
                                    deque_push_back(self, RARRAY_PTR(ary)[i]);
                            }
                    }
            }
            return self;
    }

### Public Instance Methods

back() click to toggle source

    static VALUE deque_back(VALUE self) {
            deque *deque = get_deque_from_self(self);
            if(deque->back)
                    return deque->back->obj;

            return Qnil;
    }

clear() click to toggle source

    static VALUE deque_clear(VALUE self) {
            deque *deque = get_deque_from_self(self);
            clear_deque(deque);
            return Qnil;
    }

each() click to toggle source
Alias for: each_forward
each_backward() click to toggle source

    static VALUE deque_each_backward(VALUE self) {
            deque *deque = get_deque_from_self(self);
            deque_node *node = deque->back;
            while(node) {
                    rb_yield(node->obj);
                    node = node->left;
            }
            return self;
    }

Also aliased as: reverse_each
each_forward() click to toggle source

    static VALUE deque_each_forward(VALUE self) {
            deque *deque = get_deque_from_self(self);
            deque_node *node = deque->front;
            while(node) {
                    rb_yield(node->obj);
                    node = node->right;
            }
            return self;
    }

Also aliased as: each
empty?() click to toggle source

    static VALUE deque_is_empty(VALUE self) {
            deque *deque = get_deque_from_self(self);
            return (deque->size == 0) ? Qtrue : Qfalse;
    }

front() click to toggle source

    static VALUE deque_front(VALUE self) {
            deque *deque = get_deque_from_self(self);
            if(deque->front)
                    return deque->front->obj;

            return Qnil;
    }

length() click to toggle source
Alias for: size
pop_back() click to toggle source

    static VALUE deque_pop_back(VALUE self) {
            deque *deque = get_deque_from_self(self);
            VALUE obj;
            if(!deque->back)
                    return Qnil;
            deque_node *node = deque->back;
            obj = node->obj;
            if(deque->size == 1) {
                    clear_deque(deque);
                    return obj;
            }
            deque->back->left->right = NULL;
            deque->back = deque->back->left;
            deque->size--;
            return obj;
    }

pop_front() click to toggle source

    static VALUE deque_pop_front(VALUE self) {
            deque *deque = get_deque_from_self(self);
            VALUE obj;
            if(!deque->front)
                    return Qnil;
            deque_node *node = deque->front;
            obj = node->obj;
            if(deque->size == 1) {
                    clear_deque(deque);
                    return obj;
            }
            deque->front->right->left = NULL;
            deque->front = deque->front->right;
            deque->size--;
            return obj;
    }

push_back(p1) click to toggle source

    static VALUE deque_push_back(VALUE self, VALUE obj) {
            deque *deque = get_deque_from_self(self);
            deque_node *node = create_node(obj);
            if(deque->back) {
                    node->left = deque->back;
                    deque->back->right = node;
                    deque->back = node;
            }
            else {
                    deque->front = node;
                    deque->back = node;
            }
            deque->size++;
            return obj;
    }

push_front(p1) click to toggle source

    static VALUE deque_push_front(VALUE self, VALUE obj) {
            deque *deque = get_deque_from_self(self);
            deque_node *node = create_node(obj);
            if(deque->front) {
                    node->right = deque->front;
                    deque->front->left = node;
                    deque->front = node;
            }
            else {
                    deque->front = node;
                    deque->back = node;
            }
            deque->size++;
            return obj;
    }

reverse_each() click to toggle source
Alias for: each_backward
size() click to toggle source

    static VALUE deque_size(VALUE self) {
            deque *deque = get_deque_from_self(self);
            return INT2NUM(deque->size);
    }

Also aliased as: length

[Validate]

Generated with the Darkfish Rdoc Generator 2.