Class SingleWriterHashSet<E>

  • All Implemented Interfaces:
    java.lang.Iterable<E>, java.util.Collection<E>, java.util.Set<E>

    public class SingleWriterHashSet<E>
    extends java.util.AbstractSet<E>
    • Constructor Summary

      Constructors 
      Constructor Description
      SingleWriterHashSet​(int capacity)  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean add​(E newVal)  
      private void addForResize​(E[] buffer, long mask, E newVal)  
      private boolean addSlowPath​(E[] buffer, long mask, E newVal, int hash)  
      private void compactAndRemove​(E[] buffer, long mask, int removeHashIndex)  
      boolean contains​(java.lang.Object needle)  
      private boolean containsImpl​(java.lang.Object needle)  
      private boolean containsSlowPath​(E[] buffer, long mask, int hash, java.lang.Object needle)  
      java.util.Iterator<E> iterator()  
      private E[] lvBuffer()  
      private int rehash​(int h)  
      boolean remove​(java.lang.Object val)  
      private boolean removeSlowPath​(java.lang.Object val, E[] buffer, long mask, int hash)  
      private void resize()  
      int size()  
      private void soBuffer​(E[] buffer)  
      java.lang.String toString()  
      • Methods inherited from class java.util.AbstractSet

        equals, hashCode, removeAll
      • Methods inherited from class java.util.AbstractCollection

        addAll, clear, containsAll, isEmpty, retainAll, toArray, toArray
      • Methods inherited from class java.lang.Object

        clone, finalize, getClass, notify, notifyAll, 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

        addAll, clear, containsAll, isEmpty, retainAll, spliterator, toArray, toArray
    • Field Detail

      • size

        private int size
      • modCount

        private long modCount
      • buffer

        private E[] buffer
      • resizeThreshold

        private int resizeThreshold
      • BUFFER_OFFSET

        private static final long BUFFER_OFFSET
      • SIZE_OFFSET

        private static final long SIZE_OFFSET
      • MC_OFFSET

        private static final long MC_OFFSET
    • Constructor Detail

      • SingleWriterHashSet

        public SingleWriterHashSet​(int capacity)
    • Method Detail

      • size

        public int size()
        Specified by:
        size in interface java.util.Collection<E>
        Specified by:
        size in interface java.util.Set<E>
        Specified by:
        size in class java.util.AbstractCollection<E>
      • add

        public boolean add​(E newVal)
        Specified by:
        add in interface java.util.Collection<E>
        Specified by:
        add in interface java.util.Set<E>
        Overrides:
        add in class java.util.AbstractCollection<E>
      • addForResize

        private void addForResize​(E[] buffer,
                                  long mask,
                                  E newVal)
      • addSlowPath

        private boolean addSlowPath​(E[] buffer,
                                    long mask,
                                    E newVal,
                                    int hash)
      • resize

        private void resize()
      • remove

        public boolean remove​(java.lang.Object val)
        Specified by:
        remove in interface java.util.Collection<E>
        Specified by:
        remove in interface java.util.Set<E>
        Overrides:
        remove in class java.util.AbstractCollection<E>
      • removeSlowPath

        private boolean removeSlowPath​(java.lang.Object val,
                                       E[] buffer,
                                       long mask,
                                       int hash)
      • compactAndRemove

        private void compactAndRemove​(E[] buffer,
                                      long mask,
                                      int removeHashIndex)
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.util.AbstractCollection<E>
      • rehash

        private int rehash​(int h)
      • contains

        public boolean contains​(java.lang.Object needle)
        Specified by:
        contains in interface java.util.Collection<E>
        Specified by:
        contains in interface java.util.Set<E>
        Overrides:
        contains in class java.util.AbstractCollection<E>
      • containsImpl

        private boolean containsImpl​(java.lang.Object needle)
      • containsSlowPath

        private boolean containsSlowPath​(E[] buffer,
                                         long mask,
                                         int hash,
                                         java.lang.Object needle)
      • iterator

        public java.util.Iterator<E> iterator()
        Specified by:
        iterator in interface java.util.Collection<E>
        Specified by:
        iterator in interface java.lang.Iterable<E>
        Specified by:
        iterator in interface java.util.Set<E>
        Specified by:
        iterator in class java.util.AbstractCollection<E>
      • soBuffer

        private void soBuffer​(E[] buffer)
      • lvBuffer

        private E[] lvBuffer()