/** * Constructs a new, empty set that orders its elements according to * their {@linkplain Comparable natural ordering}. */ public ConcurrentSkipListSet() { m = new ConcurrentSkipListMap(); }
/** * Constructs a new map containing the same mappings and using the * same ordering as the specified sorted map. * * @param m the sorted map whose mappings are to be placed in this * map, and whose comparator is to be used to sort this map * @throws NullPointerException if the specified sorted map or any of * its keys or values are null */ public ConcurrentSkipListMap(SortedMap m) { this.comparator = m.comparator(); initialize(); buildFromSorted(m); }
Comparable key = comparable(okey); for (;;) { Node b = findPredecessor(key); Node n = b.next; for (;;) { break; if (!n.appendMarker(f) || !b.casNext(n, f)) findNode(key); // Retry via findNode else { findPredecessor(key); // Clean index if (head.right == null) tryReduceLevel();
Comparable key = comparable(kkey); for (;;) { Node b = findPredecessor(key); Node n = b.next; for (;;) { if (!b.casNext(n, z)) break; // restart if lost race to append to b int level = randomLevel(); if (level > 0) insertIndex(z, level); return null;
/** * {@inheritDoc} * * @return the previous value associated with the specified key, * or <tt>null</tt> if there was no mapping for the key * @throws ClassCastException if the specified key cannot be compared * with the keys currently in the map * @throws NullPointerException if the specified key or value is null */ public Object replace(Object key, Object value) { if (value == null) throw new NullPointerException(); Comparable k = comparable(key); for (;;) { Node n = findNode(k); if (n == null) return null; Object v = n.value; if (v != null && n.casValue(v, value)) return v; } }
private boolean tooLow(Object key) { if (lo != null) { int c = m.compare(key, lo); if (c < 0 || (c == 0 && !loInclusive)) return true; } return false; }
/** * Removes first entry; returns its snapshot. * @return null if empty, else snapshot of first entry */ Map.Entry doRemoveFirstEntry() { for (;;) { Node b = head.node; Node n = b.next; if (n == null) return null; Node f = n.next; if (n != b.next) continue; Object v = n.value; if (v == null) { n.helpDelete(b, f); continue; } if (!n.casValue(v, null)) continue; if (!n.appendMarker(f) || !b.casNext(n, f)) findFirst(); // retry clearIndexToFirst(); return new AbstractMap.SimpleImmutableEntry(n.key, v); } }
Comparable key = comparable(kkey); for (;;) { Node b = findPredecessor(key); Node n = b.next; for (;;) {
Comparable key = comparable(okey); Node bound = null; Index q = head; } else if (c == 0) { Object v = n.value; return (v != null)? v : getUsingFindNode(key); } else bound = n; if ((c = key.compareTo(k)) == 0) { Object v = n.value; return (v != null)? v : getUsingFindNode(key); } else if (c < 0) break;
public boolean containsKey(Object key) { if (key == null) throw new NullPointerException(); Object k = key; return inBounds(k) && m.containsKey(k); }
public Comparator comparator() { Comparator cmp = m.comparator(); if (isDescending) return Collections.reverseOrder(cmp); else return cmp; }
public NavigableSet descendingKeySet() { return descendingMap().navigableKeySet(); }
Comparable key = comparable(okey); for (;;) { Node b = findPredecessor(key); Node n = b.next; for (;;) { break; if (!n.appendMarker(f) || !b.casNext(n, f)) findNode(key); // Retry via findNode else { findPredecessor(key); // Clean index if (head.right == null) tryReduceLevel();
Comparable key = comparable(kkey); for (;;) { Node b = findPredecessor(key); Node n = b.next; for (;;) { if (!b.casNext(n, z)) break; // restart if lost race to append to b int level = randomLevel(); if (level > 0) insertIndex(z, level); return null;
/** * {@inheritDoc} * * @return the previous value associated with the specified key, * or <tt>null</tt> if there was no mapping for the key * @throws ClassCastException if the specified key cannot be compared * with the keys currently in the map * @throws NullPointerException if the specified key or value is null */ public Object replace(Object key, Object value) { if (value == null) throw new NullPointerException(); Comparable k = comparable(key); for (;;) { Node n = findNode(k); if (n == null) return null; Object v = n.value; if (v != null && n.casValue(v, value)) return v; } }
private boolean tooHigh(Object key) { if (hi != null) { int c = m.compare(key, hi); if (c > 0 || (c == 0 && !hiInclusive)) return true; } return false; }
/** * Removes first entry; returns its snapshot. * @return null if empty, else snapshot of first entry */ Map.Entry doRemoveFirstEntry() { for (;;) { Node b = head.node; Node n = b.next; if (n == null) return null; Node f = n.next; if (n != b.next) continue; Object v = n.value; if (v == null) { n.helpDelete(b, f); continue; } if (!n.casValue(v, null)) continue; if (!n.appendMarker(f) || !b.casNext(n, f)) findFirst(); // retry clearIndexToFirst(); return new AbstractMap.SimpleImmutableEntry(n.key, v); } }
Comparable key = comparable(kkey); for (;;) { Node b = findPredecessor(key); Node n = b.next; for (;;) {