Class AbstractConcurrentSet<T>

  • All Implemented Interfaces:
    java.lang.Iterable<T>, java.util.Collection<T>, java.util.Set<T>
    Direct Known Subclasses:
    StrongConcurrentSet, WeakConcurrentSet

    public abstract class AbstractConcurrentSet<T>
    extends java.lang.Object
    implements java.util.Set<T>
    This data structure is optimized for non-blocking reads even when write operations occur. Running read iterators will not be affected by add operations since writes always insert at the head of the structure. Remove operations can affect any running iterator such that a removed element that has not yet been reached by the iterator will not appear in that iterator anymore.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private java.util.Map<T,​ISetEntry<T>> entries  
      protected AbstractConcurrentSet.Entry<T> head  
      private static java.util.concurrent.atomic.AtomicLong id  
      private long ID  
      protected java.util.concurrent.locks.ReentrantReadWriteLock lock  
    • Method Summary

      All Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      boolean add​(T element)  
      boolean addAll​(java.util.Collection<? extends T> elements)  
      void clear()  
      boolean contains​(java.lang.Object element)  
      boolean containsAll​(java.util.Collection<?> c)  
      protected abstract AbstractConcurrentSet.Entry<T> createEntry​(T value, AbstractConcurrentSet.Entry<T> next)  
      boolean equals​(java.lang.Object obj)  
      int hashCode()  
      private boolean insert​(T element)
      Inserts a new element at the head of the set.
      boolean isEmpty()  
      boolean remove​(java.lang.Object element)  
      boolean removeAll​(java.util.Collection<?> c)  
      boolean retainAll​(java.util.Collection<?> c)  
      int size()  
      java.lang.Object[] toArray()  
      <T> T[] toArray​(T[] a)  
      • Methods inherited from class java.lang.Object

        clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
      • Methods inherited from interface java.util.Collection

        parallelStream, removeIf, stream, toArray
      • Methods inherited from interface java.lang.Iterable

        forEach
      • Methods inherited from interface java.util.Set

        iterator, spliterator
    • Field Detail

      • id

        private static final java.util.concurrent.atomic.AtomicLong id
      • ID

        private final long ID
      • lock

        protected final java.util.concurrent.locks.ReentrantReadWriteLock lock
      • entries

        private final java.util.Map<T,​ISetEntry<T>> entries
    • Constructor Detail

      • AbstractConcurrentSet

        protected AbstractConcurrentSet​(java.util.Map<T,​ISetEntry<T>> entries)
    • Method Detail

      • add

        public boolean add​(T element)
        Specified by:
        add in interface java.util.Collection<T>
        Specified by:
        add in interface java.util.Set<T>
      • contains

        public boolean contains​(java.lang.Object element)
        Specified by:
        contains in interface java.util.Collection<T>
        Specified by:
        contains in interface java.util.Set<T>
      • insert

        private boolean insert​(T element)
        Inserts a new element at the head of the set. Note: This method is expected to be synchronized by the calling code
      • size

        public int size()
        Specified by:
        size in interface java.util.Collection<T>
        Specified by:
        size in interface java.util.Set<T>
      • isEmpty

        public boolean isEmpty()
        Specified by:
        isEmpty in interface java.util.Collection<T>
        Specified by:
        isEmpty in interface java.util.Set<T>
      • addAll

        public boolean addAll​(java.util.Collection<? extends T> elements)
        Specified by:
        addAll in interface java.util.Collection<T>
        Specified by:
        addAll in interface java.util.Set<T>
      • remove

        public boolean remove​(java.lang.Object element)
        Specified by:
        remove in interface java.util.Collection<T>
        Specified by:
        remove in interface java.util.Set<T>
      • toArray

        public java.lang.Object[] toArray()
        Specified by:
        toArray in interface java.util.Collection<T>
        Specified by:
        toArray in interface java.util.Set<T>
      • toArray

        public <T> T[] toArray​(T[] a)
        Specified by:
        toArray in interface java.util.Collection<T>
        Specified by:
        toArray in interface java.util.Set<T>
      • containsAll

        public boolean containsAll​(java.util.Collection<?> c)
        Specified by:
        containsAll in interface java.util.Collection<T>
        Specified by:
        containsAll in interface java.util.Set<T>
      • removeAll

        public boolean removeAll​(java.util.Collection<?> c)
        Specified by:
        removeAll in interface java.util.Collection<T>
        Specified by:
        removeAll in interface java.util.Set<T>
      • retainAll

        public boolean retainAll​(java.util.Collection<?> c)
        Specified by:
        retainAll in interface java.util.Collection<T>
        Specified by:
        retainAll in interface java.util.Set<T>
      • clear

        public void clear()
        Specified by:
        clear in interface java.util.Collection<T>
        Specified by:
        clear in interface java.util.Set<T>
      • hashCode

        public int hashCode()
        Specified by:
        hashCode in interface java.util.Collection<T>
        Specified by:
        hashCode in interface java.util.Set<T>
        Overrides:
        hashCode in class java.lang.Object
      • equals

        public boolean equals​(java.lang.Object obj)
        Specified by:
        equals in interface java.util.Collection<T>
        Specified by:
        equals in interface java.util.Set<T>
        Overrides:
        equals in class java.lang.Object