Class ConcurrentHashMapV8.Traverser<K,V>

java.lang.Object
org.glassfish.jersey.internal.util.collection.ConcurrentHashMapV8.Traverser<K,V>
Direct Known Subclasses:
ConcurrentHashMapV8.BaseIterator
Enclosing class:
ConcurrentHashMapV8<K,V>

static class ConcurrentHashMapV8.Traverser<K,V> extends Object
Encapsulates traversal for methods such as containsValue; also serves as a base class for other iterators and spliterators. Method advance visits once each still-valid node that was reachable upon iterator construction. It might miss some that were added to a bin after the bin was visited, which is OK wrt consistency guarantees. Maintaining this property in the face of possible ongoing resizes requires a fair amount of bookkeeping state that is difficult to optimize away amidst volatile accesses. Even so, traversal maintains reasonable throughput. Normally, iteration proceeds bin-by-bin traversing lists. However, if the table has been resized, then all future steps must traverse both the bin at the current index as well as at (index + baseSize); and so on for further resizings. To paranoically cope with potential sharing by users of iterators across threads, iteration terminates if a bounds checks fails for a table read.