Class: FigureSet

Inherits:
Object
  • Object
show all
Defined in:
lib/figure_set/version.rb,
ext/figure_set/methods.c

Constant Summary collapse

VERSION =
"1.0.0"

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.versionObject



5
6
7
# File 'lib/figure_set/version.rb', line 5

def version
  VERSION
end

Instance Method Details

#add(value) ⇒ Object Also known as: <<

add



71
72
73
74
75
76
77
78
79
80
81
82
# File 'ext/figure_set/methods.c', line 71

static VALUE t_add(VALUE self, VALUE value)
{
    root_node root;

    if (TYPE(value) != T_FIXNUM) return self;
    if (VALID_MIN_VALUE > value || VALID_MAX_VALUE < value) return self;

    Data_Get_Struct(self, struct _root_node, root);
    add_num(root, NUM2ULONG(value));

    return self;
}

#clearObject

cler



211
212
213
214
215
216
217
218
219
220
221
222
# File 'ext/figure_set/methods.c', line 211

static VALUE t_clear(VALUE self)
{
    root_node root;

    Data_Get_Struct(self, struct _root_node, root);

    if (root->size) {
        destroy_all_branches(root);
    }

    return self;
}

#delete(value) ⇒ Object

delete



87
88
89
90
91
92
93
94
95
96
97
98
# File 'ext/figure_set/methods.c', line 87

static VALUE t_delete(VALUE self, VALUE value)
{
    root_node root;

    if (TYPE(value) != T_FIXNUM) return self;
    if (VALID_MIN_VALUE > value || VALID_MAX_VALUE < value) return self;

    Data_Get_Struct(self, struct _root_node, root);
    delete_num(root, NUM2ULONG(value));

    return self;
}

#empty?Boolean

empty?

Returns:

  • (Boolean)


195
196
197
198
199
200
201
202
203
204
205
206
# File 'ext/figure_set/methods.c', line 195

static VALUE t_empty(VALUE self)
{
    root_node root;

    Data_Get_Struct(self, struct _root_node, root);

    if (root->size == 0) {
        return Qtrue;
    } else {
        return Qfalse;
    }
}

#initialize_copy(orig) ⇒ Object

initialize_copy



57
58
59
60
61
62
63
64
65
66
# File 'ext/figure_set/methods.c', line 57

static VALUE t_initialize_copy(VALUE self, VALUE orig)
{
    root_node root, orig_set;

    Data_Get_Struct(self, struct _root_node, root);
    Data_Get_Struct(orig, struct _root_node, orig_set);
    copy_root_node(root, orig_set);

    return self;
}

#intersection(other) ⇒ Object Also known as: &

intersection



103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
# File 'ext/figure_set/methods.c', line 103

static VALUE t_intersection(VALUE self, VALUE other)
{
    VALUE obj;
    root_node result_set, set0, set1;

    obj = Data_Make_Struct(rb_cFigureSet, struct _root_node, NULL, destroy_all, result_set);
    init_root_node(result_set);

    Data_Get_Struct(self, struct _root_node, set0);
    Data_Get_Struct(other, struct _root_node, set1);

    intersection(result_set, set0, set1);

    return obj;
}

#sample(*args) ⇒ Object

sample



157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
# File 'ext/figure_set/methods.c', line 157

static VALUE t_sample(int argc, VALUE *argv, VALUE self)
{
    root_node root;
    VALUE array;
    unsigned long sample_count = 1UL;

    Data_Get_Struct(self, struct _root_node, root);

    if (argc == 1 && TYPE(argv[0]) == T_FIXNUM) {
        sample_count = NUM2ULONG(argv[0]);
        if (sample_count < 1UL || sample_count > root->size) sample_count = 1UL;
    }

    array = rb_ary_new2(sample_count);
    if (sample_count == root->size) {
        to_array(root, array);
    } else if (root->size) {
        sample(root, array, sample_count);
    }

    return array;
}

#sizeObject Also known as: length

size



183
184
185
186
187
188
189
190
# File 'ext/figure_set/methods.c', line 183

static VALUE t_size(VALUE self)
{
    root_node root;

    Data_Get_Struct(self, struct _root_node, root);

    return ULONG2NUM(root->size);
}

#to_aObject

to_a



141
142
143
144
145
146
147
148
149
150
151
152
# File 'ext/figure_set/methods.c', line 141

static VALUE t_to_a(VALUE self)
{
    root_node root;
    VALUE array;

    Data_Get_Struct(self, struct _root_node, root);
    array = rb_ary_new2(root->size);

    to_array(root, array);

    return array;
}

#union(other) ⇒ Object Also known as: |

union



122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
# File 'ext/figure_set/methods.c', line 122

static VALUE t_union(VALUE self, VALUE other)
{
    VALUE obj;
    root_node result_set, set0, set1;

    obj = Data_Make_Struct(rb_cFigureSet, struct _root_node, NULL, destroy_all, result_set);
    init_root_node(result_set);

    Data_Get_Struct(self, struct _root_node, set0);
    Data_Get_Struct(other, struct _root_node, set1);

    join(result_set, set0, set1);

    return obj;
}