Package ca.uqac.lif.cep.tuples
Class CacheMap<T>
java.lang.Object
ca.uqac.lif.cep.tuples.CacheMap<T>
Implementation of an immutable map.
- After its instantiation, the object is immutable: all
its fields are declared
private finaland no method can ever change their value. (As a matter of fact, all its methods are alsofinal.) This entails that methods that normally should be able to modify the contents of a Map (e.g.put()orclear()here have no effect. - Internally, the tuple uses plain arrays (instead of a
HashMap) for storing keys and values. For tuples with, a small number of keys, this should actually provide faster access than a HashMap. In all cases, arrays use up less memory than a HashMap. - Because of this, one can also ask for the index of a key/value pair, and obtain a value based on its index (rather than its key). Assuming that all tuples in a stream have their key/value pairs arranged in the same order, this means one can ask for the index of a key a first time, and from that point on query the remaining tuples by directly providing the index.
- Author:
- Sylvain Hallé
-
Nested Class Summary
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionfinal voidclear()final booleancontainsKey(Object key) final booleancontainsValue(Object value) entrySet()final Tfinal intgetIndexOf(String s) Get the index of a key in the current mapfinal intgetIndexOf(String key, int index, T out) Retrieves a value, possibly using an index.final ObjectgetValue(int index) final booleanisEmpty()keySet()final Tfinal voidfinal voidfinal voidfinal Tfinal intsize()toString()final Collection<T> values()Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface java.util.Map
compute, computeIfAbsent, computeIfPresent, equals, forEach, getOrDefault, hashCode, merge, putIfAbsent, remove, replace, replace, replaceAll
-
Constructor Details
-
CacheMap
-
CacheMap
-
-
Method Details
-
clear
public final void clear() -
containsKey
- Specified by:
containsKeyin interfaceMap<String,T>
-
containsValue
- Specified by:
containsValuein interfaceMap<String,T>
-
entrySet
-
get
-
getValue
-
getIndexOf
Get the index of a key in the current map- Parameters:
s- The key- Returns:
- The index of that key, or -1 if key does not exist
-
getIndexOf
Retrieves a value, possibly using an index. This allows one to both get the direct index of a value in the map, if not known, and to fetch that value.Object o; cached_index = map.getIndexOf("mykey", cached_index, o);This will put the value corresponding tomykeyino, and updatecached_indexto the position in the array where this key was found. Later calls togetIndexOfwill use that value to directly access the element, rather than look for it.- Parameters:
key- The key to get in the mapindex- If negative, the method will look for the key in the map to get the value. If greater than or equal to 0, the method will directly use that value to fetch the object to return.out- After the call, will contain a reference to the value one is looking for- Returns:
- The index value
-
isEmpty
public final boolean isEmpty() -
keySet
-
put
-
putAt
-
putAll
-
putAll
-
remove
-
size
public final int size() -
values
-
toString
-