public class ConcurrentReaderHashMap extends AbstractMap
Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Modifiers | Name | Description |
---|---|---|
protected static class |
ConcurrentReaderHashMap.BarrierLock |
A Serializable class for barrier lock * |
protected static class |
ConcurrentReaderHashMap.Entry |
ConcurrentReaderHashMap collision list entry. |
protected class |
ConcurrentReaderHashMap.HashIterator |
|
protected class |
ConcurrentReaderHashMap.KeyIterator |
|
protected class |
ConcurrentReaderHashMap.ValueIterator |
Modifiers | Name | Description |
---|---|---|
static int |
DEFAULT_INITIAL_CAPACITY |
The default initial number of table slots for this table (32). |
static float |
DEFAULT_LOAD_FACTOR |
The default load factor for this table (1.0). |
protected ConcurrentReaderHashMap.BarrierLock |
barrierLock |
Lock used only for its memory effects. |
protected int |
count |
The total number of mappings in the hash table. |
protected Set |
entrySet |
|
protected Set |
keySet |
|
protected Object |
lastWrite |
field written to only to guarantee lock ordering. |
protected float |
loadFactor |
The load factor for the hash table. |
protected ConcurrentReaderHashMap.Entry[] |
table |
The hash table data. |
protected int |
threshold |
The table is rehashed when its size exceeds this threshold. |
protected Collection |
values |
Type | Name and description |
---|---|
def |
ConcurrentReaderHashMap(int initialCapacity, float loadFactor) Constructs a new, empty map with the specified initial capacity and the specified load factor. |
def |
ConcurrentReaderHashMap(int initialCapacity) Constructs a new, empty map with the specified initial capacity and default load factor. |
def |
ConcurrentReaderHashMap() Constructs a new, empty map with a default initial capacity and load factor. |
def |
ConcurrentReaderHashMap(Map t) Constructs a new map with the same mappings as the given map. |
int |
capacity() @return the number of slots in this table |
void |
clear() Removes all mappings from this map. |
Object |
clone() Returns a shallow copy of this ConcurrentReaderHashMap instance: the keys and values themselves are not cloned. |
boolean |
contains(Object value) Tests if some key maps into the specified value in this table. |
boolean |
containsKey(Object key) Tests if the specified object is a key in this table. |
boolean |
containsValue(Object value) Returns true if this map maps one or more keys to the specified value. |
Enumeration |
elements() Returns an enumeration of the values in this table. |
Set |
entrySet() Returns a collection view of the mappings contained in this map. |
protected boolean |
eq(Object x, Object y) Check for equality of non-null references x and y. |
protected boolean |
findAndRemoveEntry(Map.Entry entry) Helper method for entrySet.remove |
Object |
get(Object key) Returns the value to which the specified key is mapped in this table. |
protected ConcurrentReaderHashMap.Entry[] |
getTableForReading() Get ref to table; the reference and the cells it accesses will be at least as fresh as from last use of barrierLock |
boolean |
isEmpty() Returns true if this map contains no key-value mappings. |
Set |
keySet() Returns a set view of the keys contained in this map. |
Enumeration |
keys() Returns an enumeration of the keys in this table. |
float |
loadFactor() @return the load factor |
Object |
put(Object key, Object value) Maps the specified key to the specified
value in this table. |
void |
putAll(Map t) Copies all of the mappings from the specified map to this one. |
protected void |
recordModification(Object x) Force a memory synchronization that will cause all readers to see table. |
protected void |
rehash() Rehashes the contents of this map into a new table with a larger capacity. |
Object |
remove(Object key) Removes the key (and its corresponding value) from this table. |
int |
size() Returns the number of key-value mappings in this map. |
protected Object |
sput(Object key, Object value, int hash) Continuation of put(), called only when sync lock is held and interference has been detected. |
protected Object |
sremove(Object key, int hash) Continuation of remove(), called only when sync lock is held and interference has been detected. |
Collection |
values() Returns a collection view of the values contained in this map. |
Methods inherited from class | Name |
---|---|
class AbstractMap |
remove, get, put, equals, toString, values, hashCode, clear, isEmpty, size, entrySet, putAll, keySet, containsKey, containsValue, wait, wait, wait, getClass, notify, notifyAll |
class Object |
wait, wait, wait, equals, toString, hashCode, getClass, notify, notifyAll |
The default initial number of table slots for this table (32). Used when not otherwise specified in constructor.
The default load factor for this table (1.0). Used when not otherwise specified in constructor.
Lock used only for its memory effects.
The total number of mappings in the hash table.
field written to only to guarantee lock ordering.
The load factor for the hash table.
The hash table data.
The table is rehashed when its size exceeds this threshold. (The value of this field is always (int)(capacity * loadFactor).)
Constructs a new, empty map with the specified initial capacity and the specified load factor.
initialCapacity
- the initial capacity
The actual initial capacity is rounded to the nearest power of two.loadFactor
- the load factor of the ConcurrentReaderHashMapConstructs a new, empty map with the specified initial capacity and default load factor.
initialCapacity
- the initial capacity of the
ConcurrentReaderHashMap.Constructs a new, empty map with a default initial capacity and load factor.
Constructs a new map with the same mappings as the given map. The map is created with a capacity of twice the number of mappings in the given map or 16 (whichever is greater), and a default load factor.
Removes all mappings from this map.
Returns a shallow copy of this ConcurrentReaderHashMap instance: the keys and values themselves are not cloned.
Tests if some key maps into the specified value in this table.
This operation is more expensive than the containsKey
method.
Note that this method is identical in functionality to containsValue, (which is part of the Map interface in the collections framework).
null
.value
- a value to search for.true
if and only if some key maps to the
value
argument in this table as
determined by the equals method;
false
otherwise.Tests if the specified object is a key in this table.
null
.key
- possible key.true
if and only if the specified object
is a key in this table, as determined by the
equals method; false
otherwise.Returns true if this map maps one or more keys to the specified value. Note: This method requires a full internal traversal of the hash table, and so is much slower than method containsKey.
null
.value
- value whose presence in this map is to be tested.Returns an enumeration of the values in this table. Use the Enumeration methods on the returned object to fetch the elements sequentially.
Returns a collection view of the mappings contained in this map. Each element in the returned collection is a Map.Entry. The collection is backed by the map, so changes to the map are reflected in the collection, and vice-versa. The collection supports element removal, which removes the corresponding mapping from the map, via the Iterator.remove, Collection.remove, removeAll, retainAll, and clear operations. It does not support the add or addAll operations.
Helper method for entrySet.remove
Returns the value to which the specified key is mapped in this table.
null
.key
- a key in the table.null
if the key is not mapped to any value in
this table.Get ref to table; the reference and the cells it accesses will be at least as fresh as from last use of barrierLock
Returns true if this map contains no key-value mappings.
Returns a set view of the keys contained in this map. The set is backed by the map, so changes to the map are reflected in the set, and vice-versa. The set supports element removal, which removes the corresponding mapping from this map, via the Iterator.remove, Set.remove, removeAll, retainAll, and clear operations. It does not support the add or addAll operations.
Returns an enumeration of the keys in this table.
Maps the specified key
to the specified
value
in this table. Neither the key nor the
value can be null
.
The value can be retrieved by calling the get
method
with a key that is equal to the original key.
null
.key
- the table key.value
- the value.null
if it did not have one.Copies all of the mappings from the specified map to this one. These mappings replace any mappings that this map had for any of the keys currently in the specified Map.
t
- Mappings to be stored in this map.Force a memory synchronization that will cause all readers to see table. Call only when already holding main sync lock.
Rehashes the contents of this map into a new table with a larger capacity. This method is called automatically when the number of keys in this map exceeds its capacity and load factor.
Removes the key (and its corresponding value) from this table. This method does nothing if the key is not in the table.
null
.key
- the key that needs to be removed.null
if the key did not have a mapping.Returns the number of key-value mappings in this map.
Continuation of put(), called only when sync lock is held and interference has been detected.
Continuation of remove(), called only when sync lock is held and interference has been detected.
Returns a collection view of the values contained in this map. The collection is backed by the map, so changes to the map are reflected in the collection, and vice-versa. The collection supports element removal, which removes the corresponding mapping from this map, via the Iterator.remove, Collection.remove, removeAll, retainAll, and clear operations. It does not support the add or addAll operations.