Class DoubleSortedList<T>
java.lang.Object
java.util.AbstractCollection<T>
java.util.AbstractList<T>
java.util.ArrayList<T>
com.amalgamasimulation.utils.container.SortedList<T>
com.amalgamasimulation.utils.container.DoubleSortedList<T>
- Type Parameters:
T- the type of elements contained in this list
- All Implemented Interfaces:
Serializable,Cloneable,Iterable<T>,Collection<T>,List<T>,RandomAccess,SequencedCollection<T>
Represents a sorted list of elements ordered by double keys. This
implementation enhances performance by leveraging an array of double keys for
fast binary search operations, synchronized with the list of elements.
It is designed for scenarios where frequent search operations based on double key values are required, offering significantly faster search capabilities compared to traditional list searches.
- Author:
- Andrey Malykhanov
- See Also:
-
Field Summary
Fields inherited from class java.util.AbstractList
modCount -
Constructor Summary
ConstructorsConstructorDescriptionDoubleSortedList(Function<T, Double> doubleKeyExtractor) Creates a new DoubleSortedList using the provided key extractor to map elements to their double key values. -
Method Summary
Modifier and TypeMethodDescriptionvoidbooleanbooleanAdds the specified element to this list.booleanaddAll(Collection<? extends T> collection) ceiling(double key) voidclear()copy(UnaryOperator<T> copier) floor(double key) floorWithIndex(double key) intgetInsertionIndex(double key) Gets the index in the list where an element with the given key should be inserted.intgetInsertionIndex(double key, boolean insertBefore) Gets the index in the list where an element with the given key should be inserted.intgetInsertionIndex(T element, boolean insertBefore) Returns an index at which the given element can be inserted to preserve order of the elements in this list.headList(double key, boolean inclusive) remove(int index) booleanbooleanremoveAll(Collection<?> c) booleansubList(double beginKey, boolean inclusiveBegin, double endKey, boolean inclusiveEnd) tailList(double key, boolean inclusive) Methods inherited from class com.amalgamasimulation.utils.container.SortedList
ceiling, first, floor, headList, last, listIteratorAtLastItem, setSortedElements, subList, tailListMethods inherited from class java.util.ArrayList
addAll, addFirst, addLast, clone, contains, ensureCapacity, equals, forEach, get, getFirst, getLast, hashCode, indexOf, isEmpty, iterator, lastIndexOf, listIterator, listIterator, removeFirst, removeLast, removeRange, replaceAll, retainAll, size, sort, spliterator, subList, toArray, toArray, trimToSizeMethods inherited from class java.util.AbstractCollection
containsAll, toStringMethods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface java.util.Collection
parallelStream, stream, toArrayMethods inherited from interface java.util.List
containsAll, reversed
-
Constructor Details
-
DoubleSortedList
Creates a new DoubleSortedList using the provided key extractor to map elements to their double key values.- Parameters:
doubleKeyExtractor- A function that extracts the double key from elements of type T.
-
-
Method Details
-
getInsertionIndex
Description copied from class:SortedListReturns an index at which the given element can be inserted to preserve order of the elements in this list.- Overrides:
getInsertionIndexin classSortedList<T>- Parameters:
element- given elementinsertBefore- if true, the least possible index. If false, returns the greatest possible index- Returns:
- index at which the given element can be inserted to preserve order of the elements in this list
-
getInsertionIndex
public int getInsertionIndex(double key) Gets the index in the list where an element with the given key should be inserted. Assumes that the insertion must occur before the first found occurrence of the key, i.e. in the beginning of a series of the same keys, if any.- Parameters:
key- The key of the element.- Returns:
- The index at which the element should be inserted.
-
getInsertionIndex
public int getInsertionIndex(double key, boolean insertBefore) Gets the index in the list where an element with the given key should be inserted.- Parameters:
key- The key of the element.insertBefore- A flag indicating whether to insert before the first found occurrence (true) or after the last (false).- Returns:
- The index at which the element should be inserted.
-
floor
-
floorWithIndex
-
ceiling
-
headList
-
tailList
-
subList
-
add
- Specified by:
addin interfaceCollection<T>- Specified by:
addin interfaceList<T>- Overrides:
addin classSortedList<T>
-
add
Description copied from class:SortedListAdds the specified element to this list. Allows to specify where this element must be inserted in the case of several other element existing in this list that are equal to the one being inserted.- Overrides:
addin classSortedList<T>- Parameters:
element- the element being insertedinsertBefore- iftruethe element will be inserted before all other elements that are equal to the element being inserted. Otherwise, the element will be inserted after all such elements- Returns:
true(as specified byCollection.add(E))
-
addAll
- Specified by:
addAllin interfaceCollection<T>- Specified by:
addAllin interfaceList<T>- Overrides:
addAllin classSortedList<T>
-
add
-
set
-
remove
-
remove
-
removeAll
-
removeIf
-
clear
public void clear() -
copy
-