@Override public int put(final double k, final int v) { Entry e = add(k); final int oldValue = e.value; e.value = v; return oldValue; } /**
@Override public void clear() { Double2IntAVLTreeMap.this.clear(); } };
/** * Locates the first entry. * * @return the first entry of this submap, or {@code null} if the submap is * empty. */ public Double2IntAVLTreeMap.Entry firstEntry() { if (tree == null) return null; // If this submap goes to -infinity, we return the main map first entry; // otherwise, we locate the start of the map. Double2IntAVLTreeMap.Entry e; if (bottom) e = firstEntry; else { e = locateKey(from); // If we find either the start or something greater we're OK. if (compare(e.key, from) < 0) e = e.next(); } // Finally, if this subset doesn't go to infinity, we check that the resulting // key isn't greater than the end. if (e == null || !top && compare(e.key, to) >= 0) return null; return e; } /**
private void readObject(java.io.ObjectInputStream s) throws java.io.IOException, ClassNotFoundException { s.defaultReadObject(); /* * The storedComparator is now correctly set, but we must restore on-the-fly the * actualComparator. */ setActualComparator(); allocatePaths(); if (count != 0) { tree = readTree(s, count, null, null); Entry e; e = tree; while (e.left() != null) e = e.left(); firstEntry = e; e = tree; while (e.right() != null) e = e.right(); lastEntry = e; } } }
/** * Checks whether a key is in the submap range. * * @param k * a key. * @return true if is the key is in the submap range. */ final boolean in(final double k) { return (bottom || Double2IntAVLTreeMap.this.compare(k, from) >= 0) && (top || Double2IntAVLTreeMap.this.compare(k, to) < 0); } @Override
@Override public int get(final double k) { final Entry e = findKey(k); return e == null ? defRetValue : e.value; } @Override
@Override public boolean remove(final Object o) { if (!(o instanceof Map.Entry)) return false; final Map.Entry<?, ?> e = (Map.Entry<?, ?>) o; if (e.getKey() == null || !(e.getKey() instanceof Double)) return false; if (e.getValue() == null || !(e.getValue() instanceof Integer)) return false; final Entry f = findKey(((Double) (e.getKey())).doubleValue()); if (f == null || !((f.getIntValue()) == (((Integer) (e.getValue())).intValue()))) return false; Double2IntAVLTreeMap.this.remove(f.key); return true; } @Override
@Override public boolean contains(final int k) { return containsValue(k); } @Override
@Override public Comparator<? super Double2IntMap.Entry> comparator() { return Double2IntAVLTreeMap.this.double2IntEntrySet().comparator(); } @Override
@Override public boolean containsKey(final double k) { return in(k) && Double2IntAVLTreeMap.this.containsKey(k); } @Override
@Override public ObjectSortedSet<Double2IntMap.Entry> headSet(Double2IntMap.Entry to) { return headMap(to.getDoubleKey()).double2IntEntrySet(); } @Override
Double2IntSortedMap estIndexMap = new Double2IntAVLTreeMap(); double distance = 0; for (int i = 0; i < rawEstForP.length; i++) {
c.values = null; c.entries = null; c.allocatePaths(); if (count != 0) {
/** * Creates a new submap with given key range. * * @param from * the start of the submap range. * @param bottom * if true, the first parameter is ignored and the range starts from * -∞. * @param to * the end of the submap range. * @param top * if true, the third parameter is ignored and the range goes to * ∞. */ public Submap(final double from, final boolean bottom, final double to, final boolean top) { if (!bottom && !top && Double2IntAVLTreeMap.this.compare(from, to) > 0) throw new IllegalArgumentException("Start key (" + from + ") is larger than end key (" + to + ")"); this.from = from; this.bottom = bottom; this.to = to; this.top = top; this.defRetValue = Double2IntAVLTreeMap.this.defRetValue; } @Override
@Override public boolean containsKey(final double k) { return findKey(k) != null; } @Override
/** * Locates the last entry. * * @return the last entry of this submap, or {@code null} if the submap is * empty. */ public Double2IntAVLTreeMap.Entry lastEntry() { if (tree == null) return null; // If this submap goes to infinity, we return the main map last entry; // otherwise, we locate the end of the map. Double2IntAVLTreeMap.Entry e; if (top) e = lastEntry; else { e = locateKey(to); // If we find something smaller than the end we're OK. if (compare(e.key, to) >= 0) e = e.prev(); } // Finally, if this subset doesn't go to -infinity, we check that the resulting // key isn't smaller than the start. if (e == null || !bottom && compare(e.key, from) < 0) return null; return e; } @Override
@Override void updatePrevious() { prev = prev.prev(); if (!bottom && prev != null && Double2IntAVLTreeMap.this.compare(prev.key, from) < 0) prev = null; } @Override
@Override public int get(final double k) { final Double2IntAVLTreeMap.Entry e; final double kk = k; return in(kk) && (e = findKey(kk)) != null ? e.value : this.defRetValue; } @Override
/** * Adds an increment to value currently associated with a key. * * <p> * Note that this method respects the {@linkplain #defaultReturnValue() default * return value} semantics: when called with a key that does not currently * appears in the map, the key will be associated with the default return value * plus the given increment. * * @param k * the key. * @param incr * the increment. * @return the old value, or the {@linkplain #defaultReturnValue() default * return value} if no value was present for the given key. */ public int addTo(final double k, final int incr) { Entry e = add(k); final int oldValue = e.value; e.value += incr; return oldValue; } @Override