ariba.util.core
Class MemoryOptimizedMap<K,V>
java.lang.Object
ariba.util.core.MemoryOptimizedMap<K,V>
- All Implemented Interfaces:
- Serializable, Cloneable, Map<K,V>
public abstract class MemoryOptimizedMap<K,V>
- extends Object
- implements Map<K,V>, Cloneable, Serializable
This is a map implementation that is very memory efficient for very small maps. It is based on the observation that for very small maps,
the general overhead can accumulate, especially if you have a lot of them. For example, this is the memory usage for
some ways to store 2 pointers:
Object w/ 2 members: 16 bytes
Object[2] : 24 bytes
Object w member which is an Object[2]: 40 bytes
This map implementation uses a very simple linear search, which should not be an issue for the sizes in this map. The map
switches over to a HashMap if it becomes too large. It behaves exactly like a regular map.
Note that 2 methods in the EntrySet are not implemented, however those should be rarely used.
Generally one needs to be very aware of how these maps are being used, so this class needs to be very carefully applied.
Normally if you feel like you should use this class, you probably did something overall wrong, and should redesign your
algorithms ...
- See Also:
- Serialized Form
MemoryOptimizedMap
public MemoryOptimizedMap()
getOptimizedMap
public static <K,V> Map<K,V> getOptimizedMap(int size)
size
public int size()
- Specified by:
size in interface Map<K,V>
isEmpty
public boolean isEmpty()
- Specified by:
isEmpty in interface Map<K,V>
containsKey
public boolean containsKey(Object key)
- Specified by:
containsKey in interface Map<K,V>
containsValue
public boolean containsValue(Object value)
- Specified by:
containsValue in interface Map<K,V>
get
public V get(Object key)
- Specified by:
get in interface Map<K,V>
put
public V put(K key,
V value)
- Specified by:
put in interface Map<K,V>
remove
public V remove(Object key)
- Specified by:
remove in interface Map<K,V>
putAll
public void putAll(Map<? extends K,? extends V> t)
- Specified by:
putAll in interface Map<K,V>
clear
public void clear()
- Specified by:
clear in interface Map<K,V>
optimize
public static <K,V> Map<K,V> optimize(Map<K,V> tab)
optimize
public static <K,V> Map<K,V> optimize(Map<K,V> tab,
boolean growOnly)
deepOptimize
public static Map deepOptimize(Map tab)
optimizeInPlace
public static void optimizeInPlace(Map s)
keySet
public Set<K> keySet()
- 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.
- Specified by:
keySet in interface Map<K,V>
- Returns:
- a set view of the keys contained in this map.
values
public Collection<V> values()
- 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.
- Specified by:
values in interface Map<K,V>
- Returns:
- a collection view of the values contained in this map.
entrySet
public Set<Map.Entry<K,V>> entrySet()
- 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.
- Specified by:
entrySet in interface Map<K,V>
- Returns:
- a collection view of the mappings contained in this map.
- See Also:
Map.Entry
clone
public Object clone()
- Overrides:
clone in class Object
AribaWeb User Interface Development Framework
Copyright © 2000-2009 Ariba, Inc. All Rights Reserved.