Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8186181

Enhance JDK with IndexedTreeSet, IndexedTreeMap

XMLWordPrintable

      A DESCRIPTION OF THE REQUEST :
      SortedSet / Map in Java are implemented using TreeSet, TreeMap which are based on red-black tree algorithm.
      I suggest adding IndexedTreeSet, IndexedTreeMap to JDK to allow getting entries of sorted sets by index, also getting indexes of entries.

      https://github.com/geniot/indexed-tree-map/blob/master/src/src/main/java/com/dictiography/collections/IndexedNavigableSet.java

      The implementation can be based on weights:
      https://github.com/geniot/indexed-tree-map/blob/master/src/src/main/java/com/dictiography/collections/IndexedTreeMap.java
      Search for 'weight'.
      The red-black tree updates internal field 'weight' of elements in question when the tree changes its structure.

      JUSTIFICATION :
      The question is frequently raised on StackOverflow:

      https://stackoverflow.com/questions/581677/how-to-get-the-last-25-elements-of-a-sortedset/21382386#21382386
      https://stackoverflow.com/questions/8856815/how-to-return-the-kth-element-in-treeset-in-java/14803240#14803240
      https://stackoverflow.com/questions/8502542/find-element-position-in-a-java-treemap/14782499#14782499
      https://stackoverflow.com/questions/7911621/how-to-find-the-index-of-an-element-in-a-treeset/14782692#14782692

      Choosing between a list and a set on many occasions is a dilemma because you cannot access set elements by index.

      The suggested solutions are based on linear conversion algorithms.
      By using built-in weights enhancement there will be almost no impact on the performance.


            smarks Stuart Marks
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: