/** * Creates a new tree set copying the elements of an array. * * @param a * an array to be copied into the new tree set. */ public FloatAVLTreeSet(final float[] a) { this(); int i = a.length; while (i-- != 0) add(a[i]); } /**
/** * Creates a new tree set copying a given set. * * @param c * a collection to be copied into the new tree set. */ public FloatAVLTreeSet(final Collection<? extends Float> c) { this(); addAll(c); } /**
/** * Locates the first entry. * * @return the first entry of this subset, or {@code null} if the subset is * empty. */ public FloatAVLTreeSet.Entry firstEntry() { if (tree == null) return null; // If this subset goes to -infinity, we return the main set first entry; // otherwise, we locate the start of the set. FloatAVLTreeSet.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; } } }
@Override public boolean remove(final float k) { if (!in(k)) return false; return FloatAVLTreeSet.this.remove(k); } @Override
@Override public boolean contains(final float k) { return findKey(k) != null; } @Override
@Override public boolean contains(final float k) { return in(k) && FloatAVLTreeSet.this.contains(k); } @Override
throw new InternalError(); c.allocatePaths(); if (count != 0) {
/** * Creates a new subset with given key range. * * @param from * the start of the subset range. * @param bottom * if true, the first parameter is ignored and the range starts from * -∞. * @param to * the end of the subset range. * @param top * if true, the third parameter is ignored and the range goes to * ∞. */ public Subset(final float from, final boolean bottom, final float to, final boolean top) { if (!bottom && !top && FloatAVLTreeSet.this.compare(from, to) > 0) throw new IllegalArgumentException( "Start element (" + from + ") is larger than end element (" + to + ")"); this.from = from; this.bottom = bottom; this.to = to; this.top = top; } @Override
@Override public void remove() { if (curr == null) throw new IllegalStateException(); /* * If the last operation was a next(), we are removing an entry that preceeds * the current index, and thus we must decrement it. */ if (curr == prev) index--; next = prev = curr; updatePrevious(); updateNext(); FloatAVLTreeSet.this.remove(curr.key); curr = null; } }
@Override void updatePrevious() { prev = prev.prev(); if (!bottom && prev != null && FloatAVLTreeSet.this.compare(prev.key, from) < 0) prev = null; } @Override
/** * Creates a new tree set copying a given type-specific collection. * * @param c * a type-specific collection to be copied into the new tree set. */ public FloatAVLTreeSet(final FloatCollection c) { this(); addAll(c); } /**
/** * Creates a new tree set copying the elements of an array using a given * {@link Comparator}. * * @param a * an array to be copied into the new tree set. * @param c * a {@link Comparator} (even better, a type-specific comparator). */ public FloatAVLTreeSet(final float[] a, final Comparator<? super Float> c) { this(c); int i = a.length; while (i-- != 0) add(a[i]); } /*
/** * Locates the last entry. * * @return the last entry of this subset, or {@code null} if the subset is * empty. */ public FloatAVLTreeSet.Entry lastEntry() { if (tree == null) return null; // If this subset goes to infinity, we return the main set last entry; // otherwise, we locate the end of the set. FloatAVLTreeSet.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 updateNext() { next = next.next(); if (!top && next != null && FloatAVLTreeSet.this.compare(next.key, to) >= 0) next = null; } }