public TreeSet(Comparator comparator) { map = new TreeMap(comparator); }
public Object clone() { TreeMap clone; try { clone = (TreeMap)super.clone(); } catch (CloneNotSupportedException e) { throw new InternalError(); } clone.root = null; clone.size = 0; clone.modCount = 0; if (!isEmpty()) { clone.buildFromSorted(this.entrySet().iterator(), this.size); } return clone; }
public Object ceiling(Object e) { return ceilingKey(e); } public Object higher(Object e) { return higherKey(e); }
public boolean containsValue(Object value) { if (root == null) return false; return (value == null) ? containsNull(root) : containsValue(root, value); }
if (parentOf(x) == leftOf(parentOf(parentOf(x)))) { Entry y = rightOf(parentOf(parentOf(x))); if (colorOf(y) == Entry.RED) { setColor(parentOf(x), Entry.BLACK); setColor(y, Entry.BLACK); setColor(parentOf(parentOf(x)), Entry.RED); x = parentOf(parentOf(x)); if (x == rightOf(parentOf(x))) { x = parentOf(x); rotateLeft(x); setColor(parentOf(x), Entry.BLACK); setColor(parentOf(parentOf(x)), Entry.RED); if (parentOf(parentOf(x)) != null) rotateRight(parentOf(parentOf(x))); Entry y = leftOf(parentOf(parentOf(x))); if (colorOf(y) == Entry.RED) { setColor(parentOf(x), Entry.BLACK); setColor(y, Entry.BLACK); setColor(parentOf(parentOf(x)), Entry.RED); x = parentOf(parentOf(x)); if (x == leftOf(parentOf(x))) { x = parentOf(x); rotateRight(x); setColor(parentOf(x), Entry.BLACK);
public void putAll(Map map) { if (map instanceof SortedMap) { SortedMap smap = (SortedMap)map; if (eq(this.comparator, smap.comparator())) { this.buildFromSorted(smap.entrySet().iterator(), map.size()); return; } } // not a sorted map, or comparator mismatch super.putAll(map); }
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException { in.defaultReadObject(); Comparator comparator = (Comparator)in.readObject(); TreeMap map = new TreeMap(comparator); int size = in.readInt(); try { map.buildFromSorted(new IOIterator(in, size), size); this.map = map; } catch (TreeMap.IteratorIOException e) { throw e.getException(); } catch (TreeMap.IteratorNoClassException e) { throw e.getException(); } } }
private Entry getHigherEntry(Object key) { Entry t = root; if (t == null) return null; for (;;) { int diff = compare(key, t.key, comparator); if (diff < 0) { if (t.left != null) t = t.left; else return t; } else { if (t.right != null) { t = t.right; } else { Entry parent = t.parent; while (parent != null && t == parent.right) { t = parent; parent = parent.parent; } return parent; } } } }
Entry t = root; for (;;) { int diff = compare(key, t.getKey(), comparator); if (diff == 0) return t.setValue(value); else if (diff <= 0) { e.parent = t; t.left = e; fixAfterInsertion(e); return null; e.parent = t; t.right = e; fixAfterInsertion(e); return null;
public TreeMap(SortedMap map) { this.comparator = map.comparator(); this.buildFromSorted(map.entrySet().iterator(), map.size()); }
public void clear() { TreeMap.this.clear(); }
private static boolean containsNull(Entry e) { if (e.element == null) return true; if (e.left != null && containsNull(e.left)) return true; if (e.right != null && containsNull(e.right)) return true; return false; }
private static boolean containsValue(Entry e, Object val) { if (val.equals(e.element)) return true; if (e.left != null && containsValue(e.left, val)) return true; if (e.right != null && containsValue(e.right, val)) return true; return false; }
public boolean containsKey(Object key) { return (inRange(key) && TreeMap.this.containsKey(key)); }
public Comparator comparator() { return TreeMap.this.comparator(); }
if (parentOf(x) == leftOf(parentOf(parentOf(x)))) { Entry y = rightOf(parentOf(parentOf(x))); if (colorOf(y) == Entry.RED) { setColor(parentOf(x), Entry.BLACK); setColor(y, Entry.BLACK); setColor(parentOf(parentOf(x)), Entry.RED); x = parentOf(parentOf(x)); if (x == rightOf(parentOf(x))) { x = parentOf(x); rotateLeft(x); setColor(parentOf(x), Entry.BLACK); setColor(parentOf(parentOf(x)), Entry.RED); if (parentOf(parentOf(x)) != null) rotateRight(parentOf(parentOf(x))); Entry y = leftOf(parentOf(parentOf(x))); if (colorOf(y) == Entry.RED) { setColor(parentOf(x), Entry.BLACK); setColor(y, Entry.BLACK); setColor(parentOf(parentOf(x)), Entry.RED); x = parentOf(parentOf(x)); if (x == leftOf(parentOf(x))) { x = parentOf(x); rotateRight(x); setColor(parentOf(x), Entry.BLACK);
public void putAll(Map map) { if (map instanceof SortedMap) { SortedMap smap = (SortedMap)map; if (eq(this.comparator, smap.comparator())) { this.buildFromSorted(smap.entrySet().iterator(), map.size()); return; } } // not a sorted map, or comparator mismatch super.putAll(map); }
public boolean containsValue(Object value) { if (root == null) return false; return (value == null) ? containsNull(root) : containsValue(root, value); }
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException { in.defaultReadObject(); Comparator comparator = (Comparator)in.readObject(); TreeMap map = new TreeMap(comparator); int size = in.readInt(); try { map.buildFromSorted(new IOIterator(in, size), size); this.map = map; } catch (TreeMap.IteratorIOException e) { throw e.getException(); } catch (TreeMap.IteratorNoClassException e) { throw e.getException(); } } }
private Entry getLowerEntry(Object key) { Entry e = root; if (e == null) return null; for (;;) { int diff = compare(key, e.key, comparator); if (diff > 0) { if (e.right != null) e = e.right; else return e; } else { if (e.left != null) { e = e.left; } else { Entry p = e.parent; while (p != null && e == p.left) { e = p; p = p.parent; } return p; } } } }