示例#1
0
 public Btrie_fast_mgr Add(byte[] key, Object val) {
   if (val == null)
     throw Err_.new_("null objects cannot be registered").Add("key", String_.new_u8(key));
   int key_len = key.length;
   int key_end = key_len - 1;
   ByteTrieItm_fast cur = root;
   for (int i = 0; i < key_len; i++) {
     byte b = key[i];
     ByteTrieItm_fast nxt = cur.Ary_find(b);
     if (nxt == null) nxt = cur.Ary_add(b, null);
     if (i == key_end) nxt.Val_set(val);
     cur = nxt;
   }
   return this;
 }
示例#2
0
 public Object Match_bgn_w_byte(byte b, byte[] src, int bgn_pos, int src_len) {
   match_pos = bgn_pos;
   ByteTrieItm_fast nxt = root.Ary_find(b);
   if (nxt == null) return null; // nxt does not have b; return rv;
   Object rv = null;
   int cur_pos = bgn_pos + 1;
   ByteTrieItm_fast cur = root;
   while (true) {
     if (nxt.Ary_is_empty()) {
       match_pos = cur_pos;
       return nxt.Val();
     } // nxt is leaf; return nxt.Val() (which should be non-null)
     Object nxt_val = nxt.Val();
     if (nxt_val != null) {
       match_pos = cur_pos;
       rv = nxt_val;
     } // nxt is node; cache rv (in case of false match)
     if (cur_pos == src_len) return rv; // eos; exit
     b = src[cur_pos];
     cur = nxt;
     nxt = cur.Ary_find(b);
     if (nxt == null) return rv;
     ++cur_pos;
   }
 }
示例#3
0
 public void Del(byte[] key) {
   int key_len = key.length;
   ByteTrieItm_fast cur = root;
   for (int i = 0; i < key_len; i++) {
     byte b = key[i];
     Object itm_obj = cur.Ary_find(b);
     if (itm_obj == null) break; // b not found; no match; exit;
     ByteTrieItm_fast itm = (ByteTrieItm_fast) itm_obj;
     if (i == key_len - 1) { // last char
       if (itm.Val() == null)
         break; // itm does not have val; EX: trie with "abc", and "ab" deleted
       if (itm.Ary_is_empty()) cur.Ary_del(b);
       else itm.Val_set(null);
     } else { // mid char; set itm as cur and continue
       cur = itm;
     }
   }
 }
示例#4
0
 public Btrie_fast_mgr CaseAny_(boolean v) {
   root.CaseAny_(v);
   return this;
 }
示例#5
0
 public boolean CaseAny() {
   return root.CaseAny();
 }
示例#6
0
 public void Clear() {
   root.Clear();
 }