Class: R2ree
- Inherits:
-
Object
- Object
- R2ree
- Defined in:
- lib/r2ree/version.rb,
ext/r2ree/r2ree.cc
Constant Summary collapse
- VERSION =
'0.1.1'.freeze
Class Method Summary collapse
Instance Method Summary collapse
- #exist?(*args) ⇒ Boolean
- #find(*args) ⇒ Object
- #size ⇒ Object (also: #length)
Class Method Details
.new(*args) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'ext/r2ree/r2ree.cc', line 35
static VALUE r2ree_s_new(int argc, VALUE *argv, VALUE self) {
int i = 0;
VALUE paths, path;
r2ree::radix_tree *tree = new r2ree::radix_tree();
rb_scan_args(argc, argv, "1", &paths);
if (TYPE(paths) == T_ARRAY) {
while (!NIL_P(path = rb_ary_entry(paths, i))) {
if (TYPE(path) != T_STRING)
rb_raise(rb_eArgError, "wrong argument type, expected String");
tree->insert(StringValuePtr(path));
++i;
}
}
return Data_Wrap_Struct(self, NULL, r2ree_free, tree);
};
|
Instance Method Details
#exist?(*args) ⇒ Boolean
59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'ext/r2ree/r2ree.cc', line 59
static VALUE r2ree_exist(int argc, VALUE *argv, VALUE self) {
VALUE path;
bool existence, leaf;
rb_scan_args(argc, argv, "1", &path);
if (TYPE(path) == T_STRING) {
tie(existence, ignore, ignore, leaf) = match(self, StringValuePtr(path));
return (existence && leaf) ? Qtrue : Qfalse;
} else {
return Qfalse;
}
};
|
#find(*args) ⇒ Object
73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'ext/r2ree/r2ree.cc', line 73
static VALUE r2ree_find(int argc, VALUE *argv, VALUE self) {
int cid;
VALUE path;
bool existence, leaf;
rb_scan_args(argc, argv, "1", &path);
if (TYPE(path) == T_STRING) {
tie(existence, cid, ignore, leaf) = match(self, StringValuePtr(path));
return (existence && leaf) ? INT2NUM(cid) : INT2NUM(-1);
} else {
rb_raise(rb_eArgError, "wrong argument type, expected String");
}
};
|
#size ⇒ Object Also known as: length
53 54 55 56 57 |
# File 'ext/r2ree/r2ree.cc', line 53
static VALUE r2ree_size(VALUE self) {
r2ree::radix_tree *tree = get_r2ree_radix_tree(self);
int cid = tree->cid;
return INT2NUM(cid >= 0 ? cid + 1 : 0);
};
|