Interface Long2ObjectSyncMap<V>

  • Type Parameters:
    V - the value type
    All Superinterfaces:
    it.unimi.dsi.fastutil.Function<Long,​V>, Function<Long,​V>, it.unimi.dsi.fastutil.longs.Long2ObjectFunction<V>, it.unimi.dsi.fastutil.longs.Long2ObjectMap<V>, LongFunction<V>, Map<Long,​V>

    public interface Long2ObjectSyncMap<V>
    extends it.unimi.dsi.fastutil.longs.Long2ObjectMap<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 a read and a dirty map. 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 interface  Long2ObjectSyncMap.ExpungingEntry<V>
      The expunging value the backing map wraps for its values.
      static interface  Long2ObjectSyncMap.InsertionResult<V>
      The insertion result.
      • Nested classes/interfaces inherited from interface it.unimi.dsi.fastutil.longs.Long2ObjectMap

        it.unimi.dsi.fastutil.longs.Long2ObjectMap.Entry<V extends Object>, it.unimi.dsi.fastutil.longs.Long2ObjectMap.FastEntrySet<V extends Object>
    • Method Summary

      All Methods Static Methods Instance Methods Abstract Methods 
      Modifier and Type Method Description
      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.
      static <V> @NonNull Long2ObjectSyncMap<V> hashmap()
      Returns a new sync map, backed by a Long2ObjectOpenHashMap.
      static <V> @NonNull Long2ObjectSyncMap<V> hashmap​(int initialCapacity)
      Returns a new sync map, backed by a Long2ObjectOpenHashMap with a provided initial capacity.
      static @NonNull it.unimi.dsi.fastutil.longs.LongSet hashset()
      Returns a new mutable set view of a sync map, backed by a Long2ObjectOpenHashMap.
      static @NonNull it.unimi.dsi.fastutil.longs.LongSet hashset​(int initialCapacity)
      Returns a new mutable set view of a sync map, backed by a Long2ObjectOpenHashMap with a provided initial capacity.
      @NonNull it.unimi.dsi.fastutil.objects.ObjectSet<it.unimi.dsi.fastutil.longs.Long2ObjectMap.Entry<V>> long2ObjectEntrySet()
      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 Long2ObjectSyncMap<V> of​(@NonNull IntFunction<it.unimi.dsi.fastutil.longs.Long2ObjectMap<Long2ObjectSyncMap.ExpungingEntry<V>>> function, int initialCapacity)
      Returns a new sync map, backed by the provided Long2ObjectMap implementation with a provided initial capacity.
      static @NonNull it.unimi.dsi.fastutil.longs.LongSet setOf​(@NonNull IntFunction<it.unimi.dsi.fastutil.longs.Long2ObjectMap<Long2ObjectSyncMap.ExpungingEntry<Boolean>>> function, int initialCapacity)
      Returns a new mutable set view of a sync map, backed by the provided Long2ObjectMap implementation with a provided initial capacity.
      int size()
      This implementation is O(n) in nature due to the need to check for any expunged entries.
      • Methods inherited from interface it.unimi.dsi.fastutil.Function

        apply
      • Methods inherited from interface it.unimi.dsi.fastutil.longs.Long2ObjectFunction

        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.longs.Long2ObjectMap

        compute, computeIfAbsent, computeIfAbsent, computeIfAbsentPartial, computeIfPresent, containsKey, containsKey, defaultReturnValue, defaultReturnValue, entrySet, forEach, get, getOrDefault, getOrDefault, keySet, merge, put, putIfAbsent, remove, remove, replace, replace, values
    • Method Detail

      • hashmap

        static <V> @NonNull Long2ObjectSyncMap<V> hashmap()
        Returns a new sync map, backed by a Long2ObjectOpenHashMap.
        Type Parameters:
        V - the value type
        Returns:
        a sync map
        Since:
        0.2.0
      • hashmap

        static <V> @NonNull Long2ObjectSyncMap<V> hashmap​(int initialCapacity)
        Returns a new sync map, backed by a Long2ObjectOpenHashMap with 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.longs.LongSet hashset()
        Returns a new mutable set view of a sync map, backed by a Long2ObjectOpenHashMap.
        Returns:
        a mutable set view of a sync map
        Since:
        0.2.0
      • hashset

        static @NonNull it.unimi.dsi.fastutil.longs.LongSet hashset​(int initialCapacity)
        Returns a new mutable set view of a sync map, backed by a Long2ObjectOpenHashMap with 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 Long2ObjectSyncMap<V> of​(@NonNull IntFunction<it.unimi.dsi.fastutil.longs.Long2ObjectMap<Long2ObjectSyncMap.ExpungingEntry<V>>> function,
                                                     int initialCapacity)
        Returns a new sync map, backed by the provided Long2ObjectMap implementation with a provided initial capacity.
        Type Parameters:
        V - the value type
        Parameters:
        function - the map creation function
        initialCapacity - the map initial capacity
        Returns:
        a sync map
        Since:
        0.2.0
      • setOf

        static @NonNull it.unimi.dsi.fastutil.longs.LongSet setOf​(@NonNull IntFunction<it.unimi.dsi.fastutil.longs.Long2ObjectMap<Long2ObjectSyncMap.ExpungingEntry<Boolean>>> function,
                                                                  int initialCapacity)
        Returns a new mutable set view of a sync map, backed by the provided Long2ObjectMap implementation with a provided initial capacity.
        Parameters:
        function - the map creation function
        initialCapacity - the map initial capacity
        Returns:
        a mutable set view of a sync map
        Since:
        0.2.0
      • long2ObjectEntrySet

        @NonNull it.unimi.dsi.fastutil.objects.ObjectSet<it.unimi.dsi.fastutil.longs.Long2ObjectMap.Entry<V>> long2ObjectEntrySet()
        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:
        long2ObjectEntrySet in interface it.unimi.dsi.fastutil.longs.Long2ObjectMap<V>
      • size

        int size()
        This implementation is O(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.
        Specified by:
        size in interface it.unimi.dsi.fastutil.Function<Long,​V>
        Specified by:
        size in interface it.unimi.dsi.fastutil.longs.Long2ObjectMap<V>
        Specified by:
        size in interface Map<Long,​V>
        Returns:
        the size of all the mappings contained in this map
      • 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.
        Specified by:
        clear in interface it.unimi.dsi.fastutil.Function<Long,​V>
        Specified by:
        clear in interface it.unimi.dsi.fastutil.longs.Long2ObjectMap<V>
        Specified by:
        clear in interface Map<Long,​V>