コード例 #1
0
ファイル: TrieKeep.java プロジェクト: Woopra/woopra-j2ee-sdk
 public int registerOne(Kim kim, int from, int thru) {
   if (this.length < this.capacity) {
     Node node = this.root;
     for (int at = from; at < thru; at += 1) {
       node = node.vet(kim.get(at));
     }
     if (node.integer == none) {
       int integer = this.length;
       node.integer = integer;
       this.uses[integer] = 1;
       this.kims[integer] = kim;
       this.froms[integer] = from;
       this.thrus[integer] = thru;
       if (JSONzip.probe) {
         try {
           JSONzip.log("<<" + integer + " " + new Kim(kim, from, thru) + ">> ");
         } catch (Throwable ignore) {
         }
       }
       this.length += 1;
       return integer;
     }
   }
   return none;
 }
コード例 #2
0
ファイル: TrieKeep.java プロジェクト: Woopra/woopra-j2ee-sdk
 /**
  * Find the integer value associated with this key, or nothing if this key is not in the keep.
  *
  * @param key An object.
  * @return An integer
  */
 public int match(Kim kim, int from, int thru) {
   Node node = this.root;
   int best = none;
   for (int at = from; at < thru; at += 1) {
     node = node.get(kim.get(at));
     if (node == null) {
       break;
     }
     if (node.integer != none) {
       best = node.integer;
     }
     from += 1;
   }
   return best;
 }
コード例 #3
0
ファイル: TrieKeep.java プロジェクト: Woopra/woopra-j2ee-sdk
  /**
   * Reserve space in the keep, compacting if necessary. A keep may contain at most -capacity-
   * elements. The keep contents can be reduced by deleting all elements with low use counts,
   * rebuilding the trie with the survivors.
   */
  public void reserve() {
    if (this.capacity - this.length < JSONzip.substringLimit) {
      int from = 0;
      int to = 0;
      this.root = new Node();
      while (from < this.capacity) {
        if (this.uses[from] > 1) {
          Kim kim = this.kims[from];
          int thru = this.thrus[from];
          Node node = this.root;
          for (int at = this.froms[from]; at < thru; at += 1) {
            Node next = node.vet(kim.get(at));
            node = next;
          }
          node.integer = to;
          this.uses[to] = age(this.uses[from]);
          this.froms[to] = this.froms[from];
          this.thrus[to] = thru;
          this.kims[to] = kim;
          to += 1;
        }
        from += 1;
      }

      // It is possible, but highly unlikely, that too many items survive.
      // If that happens, clear the keep.

      if (this.capacity - to < JSONzip.substringLimit) {
        this.power = 0;
        this.root = new Node();
        to = 0;
      }
      this.length = to;
      while (to < this.capacity) {
        this.uses[to] = 0;
        this.kims[to] = null;
        this.froms[to] = 0;
        this.thrus[to] = 0;
        to += 1;
      }
    }
  }
コード例 #4
0
ファイル: TrieKeep.java プロジェクト: Woopra/woopra-j2ee-sdk
 public void registerMany(Kim kim) {
   int length = kim.length;
   int limit = this.capacity - this.length;
   if (limit > JSONzip.substringLimit) {
     limit = JSONzip.substringLimit;
   }
   int until = length - (JSONzip.minSubstringLength - 1);
   for (int from = 0; from < until; from += 1) {
     int len = length - from;
     if (len > JSONzip.maxSubstringLength) {
       len = JSONzip.maxSubstringLength;
     }
     len += from;
     Node node = this.root;
     for (int at = from; at < len; at += 1) {
       Node next = node.vet(kim.get(at));
       if (next.integer == none && at - from >= (JSONzip.minSubstringLength - 1)) {
         next.integer = this.length;
         this.uses[this.length] = 1;
         this.kims[this.length] = kim;
         this.froms[this.length] = from;
         this.thrus[this.length] = at + 1;
         if (JSONzip.probe) {
           try {
             JSONzip.log("<<" + this.length + " " + new Kim(kim, from, at + 1) + ">> ");
           } catch (Throwable ignore) {
           }
         }
         this.length += 1;
         limit -= 1;
         if (limit <= 0) {
           return;
         }
       }
       node = next;
     }
   }
 }