-
Enhancement
-
Resolution: Duplicate
-
P4
-
None
-
9
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.
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.
- duplicates
-
JDK-4348240 (coll) request for: Object TreeSet.get(int index)
-
- Open
-
- relates to
-
JDK-4348240 (coll) request for: Object TreeSet.get(int index)
-
- Open
-