예제 #1
0
  /**
   * Equivalent to <code>{@link #incrementCount}({o}, count)</code>; only works for a depth 1
   * GeneralizedCounter.
   */
  public void incrementCount1D(K o, double count) {
    if (depth > 1) {
      wrongDepth();
    }

    addToTotal(count);

    if (tempMDouble == null) {
      tempMDouble = new MutableDouble();
    }
    tempMDouble.set(count);
    MutableDouble oldMDouble = (MutableDouble) map.put(o, tempMDouble);

    if (oldMDouble != null) {
      tempMDouble.set(count + oldMDouble.doubleValue());
    }

    tempMDouble = oldMDouble;
  }
예제 #2
0
 /* this is (non-tail) recursive right now, haven't figured out a way
  * to speed it up */
 private Set<Map.Entry<Object, Double>> entrySet(
     Set<Map.Entry<Object, Double>> s, Object[] key, boolean useLists) {
   if (depth == 1) {
     // System.out.println("key is long enough to add to set");
     Set<K> keys = map.keySet();
     for (K finalKey : keys) {
       // array doesn't escape
       K[] newKey = ErasureUtils.<K>mkTArray(Object.class, key.length + 1);
       if (key.length > 0) {
         System.arraycopy(key, 0, newKey, 0, key.length);
       }
       newKey[key.length] = finalKey;
       MutableDouble value = (MutableDouble) map.get(finalKey);
       Double value1 = new Double(value.doubleValue());
       if (useLists) {
         s.add(new Entry<Object, Double>(Arrays.asList(newKey), value1));
       } else {
         s.add(new Entry<Object, Double>(newKey[0], value1));
       }
     }
   } else {
     Set<K> keys = map.keySet();
     // System.out.println("key length " + key.length);
     // System.out.println("keyset level " + depth + " " + keys);
     for (K o : keys) {
       Object[] newKey = new Object[key.length + 1];
       if (key.length > 0) {
         System.arraycopy(key, 0, newKey, 0, key.length);
       }
       newKey[key.length] = o;
       // System.out.println("level " + key.length + " current key " + Arrays.asList(newKey));
       conditionalizeHelper(o).entrySet(s, newKey, true);
     }
   }
   // System.out.println("leaving key length " + key.length);
   return s;
 }