ext/trie/trie.c in tyler-trie-0.2.0 vs ext/trie/trie.c in tyler-trie-0.2.1
- old
+ new
@@ -93,11 +93,11 @@
if(size < 1 || size > 2)
return Qnil;
VALUE key;
key = RARRAY(args)->ptr[0];
- short value = size == 2 ? NUM2INT(RARRAY(args)->ptr[1]) : TRIE_DATA_ERROR;
+ int32 value = size == 2 ? NUM2INT(RARRAY(args)->ptr[1]) : TRIE_DATA_ERROR;
const TrieChar *sb_key = stringToTrieChar(key);
if(sb_trie_store(sb_trie, sb_key, value))
return Qtrue;
@@ -115,10 +115,20 @@
return Qtrue;
else
return Qnil;
}
+static VALUE trie_save(VALUE self) {
+ SBTrie *sb_trie;
+ Data_Get_Struct(self, SBTrie, sb_trie);
+
+ if(sb_trie_save(sb_trie) == -1)
+ return Qnil;
+ else
+ return Qtrue;
+}
+
static VALUE walk_all_paths(VALUE children, SBTrieState *state, char *prefix) {
int c;
for(c = 1; c < TRIE_CHAR_MAX; c++) {
if(sb_trie_state_is_walkable(state,c)) {
SBTrieState *next_state = sb_trie_state_clone(state);
@@ -324,9 +334,10 @@
rb_define_method(cTrie, "delete", trie_delete, 1);
rb_define_method(cTrie, "close", trie_close, 0);
rb_define_method(cTrie, "children", trie_children, 1);
rb_define_method(cTrie, "walk_to_terminal", trie_walk_to_terminal, -2);
rb_define_method(cTrie, "root", trie_root, 0);
+ rb_define_method(cTrie, "save", trie_save, 0);
cTrieNode = rb_define_class("TrieNode", rb_cObject);
rb_define_alloc_func(cTrieNode, trie_node_alloc);
rb_define_method(cTrieNode, "state", trie_node_get_state, 0);
rb_define_method(cTrieNode, "full_state", trie_node_get_full_state, 0);