Package space.vectrix.flare.fastutil
Interface Double2ObjectSyncMap<V>
-
- Type Parameters:
V- the value type
- All Superinterfaces:
it.unimi.dsi.fastutil.doubles.Double2ObjectFunction<V>,it.unimi.dsi.fastutil.doubles.Double2ObjectMap<V>,DoubleFunction<V>,it.unimi.dsi.fastutil.Function<Double,V>,Function<Double,V>,Map<Double,V>
public interface Double2ObjectSyncMap<V> extends it.unimi.dsi.fastutil.doubles.Double2ObjectMap<V>A concurrent map, internally backed by a non-thread-safe map but carefully managed in a matter such that any changes are thread-safe. Internally, the map is split into areadand adirtymap. The read map only satisfies read requests, while the dirty map satisfies all other requests.The map is optimized for two common use cases:
- The entry for the given map is only written once but read many times, as in a cache that only grows.
- Heavy concurrent modification of entries for a disjoint set of keys.
In both cases, this map significantly reduces lock contention compared to a traditional map paired with a read and write lock, along with maps with an exclusive lock (such as using
Collections.synchronizedMap(Map).Null values are not accepted. Null keys are supported if the backing collection supports them.
Based on: https://golang.org/src/sync/map.go
- Since:
- 0.2.0
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static interfaceDouble2ObjectSyncMap.ExpungingEntry<V>The expunging value the backing map wraps for its values.static interfaceDouble2ObjectSyncMap.InsertionResult<V>The insertion result.
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Modifier and Type Method Description voidclear()This method clears the map by resetting the internal state to a state similar to as if a new map had been created.@NonNull it.unimi.dsi.fastutil.objects.ObjectSet<it.unimi.dsi.fastutil.doubles.Double2ObjectMap.Entry<V>>double2ObjectEntrySet()Iterations over a sync map are thread-safe, and the keys iterated over will not change for a single iteration attempt, however they may not necessarily reflect the state of the map at the time the iterator was created.static <V> @NonNull Double2ObjectSyncMap<V>hashmap()Returns a new sync map, backed by aDouble2ObjectOpenHashMap.static <V> @NonNull Double2ObjectSyncMap<V>hashmap(int initialCapacity)Returns a new sync map, backed by aDouble2ObjectOpenHashMapwith a provided initial capacity.static @NonNull it.unimi.dsi.fastutil.doubles.DoubleSethashset()Returns a new mutable set view of a sync map, backed by aDouble2ObjectOpenHashMap.static @NonNull it.unimi.dsi.fastutil.doubles.DoubleSethashset(int initialCapacity)Returns a new mutable set view of a sync map, backed by aDouble2ObjectOpenHashMapwith a provided initial capacity.static <V> @NonNull Double2ObjectSyncMap<V>of(@NonNull IntFunction<it.unimi.dsi.fastutil.doubles.Double2ObjectMap<Double2ObjectSyncMap.ExpungingEntry<V>>> function, int initialCapacity)Returns a new sync map, backed by the providedDouble2ObjectMapimplementation with a provided initial capacity.static @NonNull it.unimi.dsi.fastutil.doubles.DoubleSetsetOf(@NonNull IntFunction<it.unimi.dsi.fastutil.doubles.Double2ObjectMap<Double2ObjectSyncMap.ExpungingEntry<Boolean>>> function, int initialCapacity)Returns a new mutable set view of a sync map, backed by the providedDouble2ObjectMapimplementation with a provided initial capacity.intsize()This implementation isO(n)in nature due to the need to check for any expunged entries.-
Methods inherited from interface it.unimi.dsi.fastutil.doubles.Double2ObjectFunction
andThenByte, andThenChar, andThenDouble, andThenFloat, andThenInt, andThenLong, andThenObject, andThenReference, andThenShort, apply, compose, composeByte, composeChar, composeDouble, composeFloat, composeInt, composeLong, composeObject, composeReference, composeShort, get, put, remove
-
Methods inherited from interface it.unimi.dsi.fastutil.doubles.Double2ObjectMap
compute, computeIfAbsent, computeIfAbsent, computeIfAbsentPartial, computeIfPresent, containsKey, containsKey, defaultReturnValue, defaultReturnValue, entrySet, forEach, get, getOrDefault, getOrDefault, keySet, merge, put, putIfAbsent, remove, remove, replace, replace, values
-
Methods inherited from interface java.util.Map
compute, computeIfAbsent, computeIfPresent, containsValue, equals, hashCode, isEmpty, merge, putAll, putIfAbsent, remove, replace, replace, replaceAll
-
-
-
-
Method Detail
-
hashmap
static <V> @NonNull Double2ObjectSyncMap<V> hashmap()
Returns a new sync map, backed by aDouble2ObjectOpenHashMap.- Type Parameters:
V- the value type- Returns:
- a sync map
- Since:
- 0.2.0
-
hashmap
static <V> @NonNull Double2ObjectSyncMap<V> hashmap(int initialCapacity)
Returns a new sync map, backed by aDouble2ObjectOpenHashMapwith a provided initial capacity.- Type Parameters:
V- the value type- Parameters:
initialCapacity- the initial capacity of the hash map- Returns:
- a sync map
- Since:
- 0.2.0
-
hashset
static @NonNull it.unimi.dsi.fastutil.doubles.DoubleSet hashset()
Returns a new mutable set view of a sync map, backed by aDouble2ObjectOpenHashMap.- Returns:
- a mutable set view of a sync map
- Since:
- 0.2.0
-
hashset
static @NonNull it.unimi.dsi.fastutil.doubles.DoubleSet hashset(int initialCapacity)
Returns a new mutable set view of a sync map, backed by aDouble2ObjectOpenHashMapwith a provided initial capacity.- Parameters:
initialCapacity- the initial capacity of the hash map- Returns:
- a mutable set view of a sync map
- Since:
- 0.2.0
-
of
static <V> @NonNull Double2ObjectSyncMap<V> of(@NonNull IntFunction<it.unimi.dsi.fastutil.doubles.Double2ObjectMap<Double2ObjectSyncMap.ExpungingEntry<V>>> function, int initialCapacity)
Returns a new sync map, backed by the providedDouble2ObjectMapimplementation with a provided initial capacity.- Type Parameters:
V- the value type- Parameters:
function- the map creation functioninitialCapacity- the map initial capacity- Returns:
- a sync map
- Since:
- 0.2.0
-
setOf
static @NonNull it.unimi.dsi.fastutil.doubles.DoubleSet setOf(@NonNull IntFunction<it.unimi.dsi.fastutil.doubles.Double2ObjectMap<Double2ObjectSyncMap.ExpungingEntry<Boolean>>> function, int initialCapacity)
Returns a new mutable set view of a sync map, backed by the providedDouble2ObjectMapimplementation with a provided initial capacity.- Parameters:
function- the map creation functioninitialCapacity- the map initial capacity- Returns:
- a mutable set view of a sync map
- Since:
- 0.2.0
-
double2ObjectEntrySet
@NonNull it.unimi.dsi.fastutil.objects.ObjectSet<it.unimi.dsi.fastutil.doubles.Double2ObjectMap.Entry<V>> double2ObjectEntrySet()
Iterations over a sync map are thread-safe, and the keys iterated over will not change for a single iteration attempt, however they may not necessarily reflect the state of the map at the time the iterator was created.Performance Note: If entries have been appended to the map, iterating over the entry set will automatically promote them to the read map.
- Specified by:
double2ObjectEntrySetin interfaceit.unimi.dsi.fastutil.doubles.Double2ObjectMap<V>
-
size
int size()
This implementation isO(n)in nature due to the need to check for any expunged entries. Likewise, as with other concurrent collections, the value obtained by this method may be out of date by the time this method returns.
-
clear
void clear()
This method clears the map by resetting the internal state to a state similar to as if a new map had been created. If there are concurrent iterations in progress, they will reflect the state of the map prior to being cleared.
-
-