Class: FigureSet
- Inherits:
-
Object
- Object
- FigureSet
- Defined in:
- lib/figure_set.rb,
ext/methods.c
Constant Summary collapse
- VERSION =
"0.0.2"
Class Method Summary collapse
Instance Method Summary collapse
-
#add(value) ⇒ Object
(also: #<<)
add.
-
#clear ⇒ Object
cler.
-
#delete(value) ⇒ Object
delete.
-
#empty? ⇒ Boolean
empty?.
-
#initialize_copy(orig) ⇒ Object
initialize_copy.
-
#intersection(other) ⇒ Object
(also: #&)
intersection.
-
#sample(*args) ⇒ Object
sample.
-
#size ⇒ Object
(also: #length)
size.
-
#to_a ⇒ Object
to_a.
-
#union(other) ⇒ Object
(also: #|)
union.
Class Method Details
.version ⇒ Object
7 8 9 |
# File 'lib/figure_set.rb', line 7 def version VERSION end |
Instance Method Details
#add(value) ⇒ Object Also known as: <<
add
70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'ext/methods.c', line 70
static VALUE t_add(VALUE self, VALUE value)
{
root_node root;
if (TYPE(value) != T_FIXNUM) return;
if (VALID_MIN_VALUE > value || VALID_MAX_VALUE < value) return;
Data_Get_Struct(self, struct _root_node, root);
add_num(root, NUM2ULONG(value));
return self;
}
|
#clear ⇒ Object
cler
210 211 212 213 214 215 216 217 218 219 220 221 |
# File 'ext/methods.c', line 210
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
86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'ext/methods.c', line 86
static VALUE t_delete(VALUE self, VALUE value)
{
root_node root;
if (TYPE(value) != T_FIXNUM) return;
if (VALID_MIN_VALUE > value || VALID_MAX_VALUE < value) return;
Data_Get_Struct(self, struct _root_node, root);
delete_num(root, NUM2ULONG(value));
return self;
}
|
#empty? ⇒ Boolean
empty?
194 195 196 197 198 199 200 201 202 203 204 205 |
# File 'ext/methods.c', line 194
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
56 57 58 59 60 61 62 63 64 65 |
# File 'ext/methods.c', line 56
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
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'ext/methods.c', line 102
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
156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 |
# File 'ext/methods.c', line 156
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;
}
|
#size ⇒ Object Also known as: length
size
182 183 184 185 186 187 188 189 |
# File 'ext/methods.c', line 182
static VALUE t_size(VALUE self)
{
root_node root;
Data_Get_Struct(self, struct _root_node, root);
return ULONG2NUM(root->size);
}
|
#to_a ⇒ Object
to_a
140 141 142 143 144 145 146 147 148 149 150 151 |
# File 'ext/methods.c', line 140
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
121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 |
# File 'ext/methods.c', line 121
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;
}
|