My question is about what are the fundamental/concrete data structure (like array) used in implementing abstract data structure implementations like variations maps/trees?
I’m looking for what’s used really in java collection, not theoretical answers.
Based on quick code review of Sun/Oracle JDK. You can easily find the details yourself.
Lists/queues
ArrayListGrowing
Object[] elementDatafield. Can hold 10 elements by default, grows by around 50% when cannot hold more objects, copying the old array to a bigger new one. Does not shrink when removing items.LinkedListReference to
Entrywhich in turns hold reference to actual element, previous and next element (if any).ArrayDequeSimilar to
ArrayListbut also holding two pointers to internalE[] elementsarray –headandtail. Both adding and removing elements on either side is just a matter of moving these pointers. The array grows by 200% when is too small.Maps
HashMapGrowing
Entry[] tablefield holding so called buckets. Each bucket contains linked list of entries having the same hash of the key module table size.TreeMapEntry<K,V> rootreference holding the root of the red-black balanced tree.ConcurrentHashMapSimilar to
HashMapbut access to each bucket (called segment) is synchronized by an independent lock.Sets
TreeSetUses
TreeMapunderneath (!)HashSetUses
HashMapunderneath (!)BitSetUses
long[] wordsfield to be as memory efficient as possible. Up to 64 bits can be stored in one element.