Class: FigureSet
- Inherits:
-
Object
- Object
- FigureSet
- Defined in:
- lib/figure_set/version.rb,
ext/figure_set/figure_set/methods.c
Constant Summary collapse
- VERSION =
"1.1.0"
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
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
76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'ext/figure_set/figure_set/methods.c', line 76
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;
}
|
#clear ⇒ Object
cler
224 225 226 227 228 229 230 231 232 233 234 235 236 |
# File 'ext/figure_set/figure_set/methods.c', line 224
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
93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'ext/figure_set/figure_set/methods.c', line 93
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?
207 208 209 210 211 212 213 214 215 216 217 218 219 |
# File 'ext/figure_set/figure_set/methods.c', line 207
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
61 62 63 64 65 66 67 68 69 70 71 |
# File 'ext/figure_set/figure_set/methods.c', line 61
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
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 |
# File 'ext/figure_set/figure_set/methods.c', line 110
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
167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 |
# File 'ext/figure_set/figure_set/methods.c', line 167
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
194 195 196 197 198 199 200 201 202 |
# File 'ext/figure_set/figure_set/methods.c', line 194
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
150 151 152 153 154 155 156 157 158 159 160 161 162 |
# File 'ext/figure_set/figure_set/methods.c', line 150
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
130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 |
# File 'ext/figure_set/figure_set/methods.c', line 130
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;
}
|