class FigureSet
Constants
- VERSION
Public Class Methods
new(*args)
click to toggle source
initialize
static VALUE t_initialize(int argc, VALUE *argv, VALUE self) { VALUE ary_element; root_node root; unsigned long i, len; Data_Get_Struct(self, struct _root_node, root); if (argc == 1 && TYPE(argv[0]) == T_ARRAY) { len = RARRAY_LEN(argv[0]); for(i = 0; i < len; i++) { ary_element = rb_ary_entry(argv[0], i); if ((TYPE(ary_element) == T_FIXNUM) && VALID_MIN_VALUE <= ary_element && VALID_MAX_VALUE >= ary_element) { add_num(root, NUM2ULONG(ary_element)); } } } return self; }
version()
click to toggle source
# File lib/figure_set/version.rb, line 5 def version VERSION end
Public Instance Methods
add(p1)
click to toggle source
add
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; }
Also aliased as: <<
clear()
click to toggle source
cler
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(p1)
click to toggle source
delete
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?()
click to toggle source
empty?
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(p1)
click to toggle source
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(p1)
click to toggle source
intersection
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; }
Also aliased as: &
sample(*args)
click to toggle source
sample
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()
click to toggle source
size
static VALUE t_size(VALUE self) { root_node root; Data_Get_Struct(self, struct _root_node, root); return ULONG2NUM(root->size); }
Also aliased as: length
to_a()
click to toggle source
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(p1)
click to toggle source
union
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; }
Also aliased as: |