/** * Get a scope level * * @param scopeLevel the scope level * @return the scope or null if there is no such level * @throws IllegalArgumentException if parameter key is null */ public Scope getScopeLevel(ScopeLevel scopeLevel) { if (scopeLevel == null) throw new IllegalArgumentException("Null scope level"); return scopes.get(scopeLevel); }
public V put(K key, V value) { checkKey(key); return m.put(key, value); }
public boolean remove(Object key, Object value) { K k = (K)key; return inHalfOpenRange(k) && m.remove(k, value); }
/** * Constructs a new map containing the same mappings as the given * <tt>SortedMap</tt>, sorted according to the same ordering. * @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 is * <tt>null</tt>. */ public ConcurrentSkipListMap(SortedMap<K, ? extends V> m) { this.comparator = m.comparator(); initialize(); buildFromSorted(m); }
Comparable<K> key = comparable(okey); K bound = null; Index<K,V> q = head; return (v != null)? (V)v : getUsingFindNode(key); if (c == 0) { Object v = n.value; return (v != null)? (V)v : getUsingFindNode(key);
Comparable<K> key = comparable(okey); for (;;) { Node<K,V> b = findPredecessor(key); Node<K,V> 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<K> key = comparable(kkey); for (;;) { Node<K,V> b = findPredecessor(key); Node<K,V> 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;
/** * Remove a scope level * * @param scopeLevel the scope level * @return the scope or null if there is no such level */ public Scope removeScopeLevel(ScopeLevel scopeLevel) { if (scopeLevel == null) throw new IllegalArgumentException("Null scope level"); if (frozen) throw new IllegalStateException("The scope key is frozen"); if (scopes == EMPTY_SCOPES) return null; Scope result = scopes.remove(scopeLevel); if (scopeLevel.equals(maxScopeLevel)) { maxScopeLevel = null; for (ScopeLevel level : scopes.keySet()) maxScopeLevel = level; } return result; }
/** * Add a scope * * @param scope the scope * @return the previous value or null if there wasn't one * @throws IllegalArgumentException if scope is null. * @throws IllegalStateException if frozen */ public Scope addScope(Scope scope) { if (scope == null) throw new IllegalArgumentException("Null scope"); if (frozen) throw new IllegalStateException("The scope key is frozen"); if (scopes == EMPTY_SCOPES) { synchronized (this) { if (scopes == EMPTY_SCOPES) scopes = new ConcurrentSkipListMap<ScopeLevel, Scope>(); } } ScopeLevel level = scope.getScopeLevel(); Scope result = scopes.put(level, scope); if (maxScopeLevel == null || level.compareTo(maxScopeLevel) >= 0) maxScopeLevel = level; return result; }
/** * Replace entry for key only if currently mapped to some value. * Acts as * <pre> * if ((map.containsKey(key)) { * return map.put(key, value); * } else return null; * </pre> * except that the action is performed atomically. * @param key key with which the specified value is associated. * @param value value to be associated with the specified key. * @return previous value associated with specified key, or <tt>null</tt> * if there was no mapping for key. * @throws ClassCastException if the key cannot be compared with the keys * currently in the map. * @throws NullPointerException if the key or value are <tt>null</tt>. */ public V replace(K key, V value) { if (value == null) throw new NullPointerException(); Comparable<K> k = comparable(key); for (;;) { Node<K,V> n = findNode(k); if (n == null) return null; Object v = n.value; if (v != null && n.casValue(v, value)) return (V)v; } }
Comparable<K> key = comparable(kkey); for (;;) { Node<K,V> b = findPredecessor(key); Node<K,V> n = b.next; for (;;) {
/** * Remove first entry; return either its key or a snapshot. * @param keyOnly if true return key, else return SnapshotEntry * (This is a little ugly, but avoids code duplication.) * @return null if empty, first key if keyOnly true, else key,value entry */ Object doRemoveFirst(boolean keyOnly) { for (;;) { Node<K,V> b = head.node; Node<K,V> n = b.next; if (n == null) return null; Node<K,V> 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(); K key = n.key; return (keyOnly)? key : new SnapshotEntry<K,V>(key, (V)v); } }
public Comparator<? super K> comparator() { return m.comparator(); }
/** * Clone a ScopeKey instance. * * @return an unfrozen instance (even if the current instance is frozen). */ public ScopeKey clone() { try { ScopeKey result = (ScopeKey) super.clone(); result.scopes = new ConcurrentSkipListMap<ScopeLevel, Scope>(scopes); result.frozen = false; return result; } catch (CloneNotSupportedException e) { throw new Error(e); } }
Node<K,V> b = findPredecessorOfLast(); Node<K,V> n = b.next; if (n == null) { break; K key = n.key; Comparable<K> ck = comparable(key); if (!n.appendMarker(f) || !b.casNext(n, f)) findNode(ck); // Retry via findNode else { findPredecessor(ck); // Clean index if (head.right == null) tryReduceLevel();
if (oldValue == null || newValue == null) throw new NullPointerException(); Comparable<K> k = comparable(key); for (;;) { Node<K,V> n = findNode(k); if (n == null) return false;
/** * Returns a shallow copy of this <tt>Map</tt> instance. (The keys and * values themselves are not cloned.) * * @return a shallow copy of this Map. */ public Object clone() { ConcurrentSkipListMap<K,V> clone = null; try { clone = (ConcurrentSkipListMap<K,V>) super.clone(); } catch (CloneNotSupportedException e) { throw new InternalError(); } clone.initialize(); clone.buildFromSorted(this); return clone; }
public V remove(Object key) { K k = (K)key; return (!inHalfOpenRange(k))? null : m.remove(k); }