Esempio n. 1
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;
   }
 }
Esempio n. 2
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;
     }
   }
 }