public class FastTable<E> extends FastCollection<E> implements List<E>, Deque<E>, RandomAccess
A high-performance table (fractal-based) with real-time
behavior.
The fractal-based implementation ensures that add/insertion/deletion operations
worst execution time is always in less than O(log(size)).
For comparison ArrayList.add is in O(size) due to resize.
Instances of this class can advantageously replace ArrayList,
LinkedList or ArrayDeque
in terms of adaptability, space or performance.
Fast tables can be concurrently iterated / modified through their shared/atomic
views. They inherit all the fast collection views and support the subTable view over a portion of the table.
FastTable<String> names = new FastTable<String>().addAll("John Deuff", "Otto Graf", "Sim Kamil"); names.sort(Equalities.LEXICAL_CASE_INSENSITIVE); // Sorts the names in place (different from sorted() which returns a sorted view). names.subTable(0, names.size() / 2).clear(); // Removes the first half of the table (see java.util.List.subList specification). names.filtered(str -> str.startsWith("A")).clear(); // Removes all the names starting with "A" (Java 8 notation). names.filtered(str -> str.startsWith("A")).parallel().clear(); // Same as above but performed concurrently.
As for any fast collection, iterations can be
performed using closures.
FastTable<Person> persons = ... Person findWithName(final String name) { return persons.filtered(new Predicate<Person>() { public boolean test(Person person) { return (person.getName().equals(name)); } }).any(Person.class); }
The notation is shorter with Java 8.
Person findWithName(String name) {
return persons.filtered(person -> person.getName().equals(name)).any(Person.class);
} FastTable iteration order is the insertion order; specialization may
have a different order, for example the iteration order of FastSortedTable
is based on the table sorting order.
FastCollection.Format| Modifier | Constructor and Description |
|---|---|
|
FastTable()
Creates an empty table whose capacity increments/decrements smoothly
without large resize operations to best fit the table current size.
|
|
FastTable(Equality<? super E> comparator)
Creates an empty table using the specified comparator for element
equality.
|
protected |
FastTable(TableService<E> service)
Creates a fast table backed up by the specified service implementation.
|
| Modifier and Type | Method and Description |
|---|---|
void |
add(int index,
E element)
Inserts the specified element at the specified position in this table.
|
FastTable<E> |
addAll(E... elements)
Returns this collection with the specified element added.
|
FastTable<E> |
addAll(FastCollection<? extends E> that)
Returns this collection with the specified collection's elements added
in sequence.
|
boolean |
addAll(int index,
Collection<? extends E> elements)
Inserts all of the elements in the specified collection into this table
at the specified position.
|
void |
addFirst(E element)
Inserts the specified element at the front of this table.
|
void |
addLast(E element)
Inserts the specified element at the end of this table.
|
FastTable<E> |
atomic()
Returns an atomic view over this collection.
|
void |
clear()
Removes all elements from this collection.
|
Iterator<E> |
descendingIterator()
Returns an iterator over the elements in this table in reverse sequential order.
|
E |
element()
Retrieves, but does not remove, the head of the queue represented by this table.
|
E |
get(int index)
Returns the element at the specified position in this table.
|
E |
getFirst()
Retrieves, but does not remove, the first element of this table.
|
E |
getLast()
Retrieves, but does not remove, the last element of this table.
|
int |
indexOf(Object element)
Returns the index of the first occurrence of the specified element in this table,
or -1 if this table does not contain the element.
|
boolean |
isEmpty()
Indicates if this collection is empty.
|
int |
lastIndexOf(Object element)
Returns the index of the last occurrence of the specified element in this table,
or -1 if this table does not contain the element.
|
ListIterator<E> |
listIterator()
Returns a list iterator over the elements in this table.
|
ListIterator<E> |
listIterator(int index)
Returns a list iterator over the elements in this table, starting
at the specified position in the table.
|
boolean |
offer(E e)
Inserts the specified element into the queue represented by this table.
|
boolean |
offerFirst(E e)
Inserts the specified element at the front of this table.
|
boolean |
offerLast(E e)
Inserts the specified element at the end of this table.
|
E |
peek()
Retrieves, but does not remove, the head of the queue represented by this table.
|
E |
peekFirst()
Retrieves, but does not remove, the first element of this table,
or returns null if this table is empty.
|
E |
peekLast()
Retrieves, but does not remove, the last element of this table,
or returns null if this table is empty.
|
E |
poll()
Retrieves and removes the head of the queue represented by this table.
|
E |
pollFirst()
Retrieves and removes the first element of this table,
or returns null if this table is empty.
|
E |
pollLast()
.
|
E |
pop()
Pops an element from the stack represented by this table.
|
void |
push(E e)
Pushes an element onto the stack represented by this table.
|
E |
remove()
Retrieves and removes the head of the queue represented by this table.
|
E |
remove(int index)
Removes the element at the specified position in this table.
|
E |
removeFirst()
Retrieves and removes the last element of this table,
or returns null if this table is empty.
|
boolean |
removeFirstOccurrence(Object o)
Removes the first occurrence of the specified element from this table.
|
E |
removeLast()
Retrieves and removes the last element of this table.
|
boolean |
removeLastOccurrence(Object o)
Removes the last occurrence of the specified element from this table.
|
FastTable<E> |
reversed()
Returns a view exposing elements in reverse iterative order.
|
protected TableService<E> |
service()
Returns the service implementation of this collection (for sub-classes).
|
E |
set(int index,
E element)
Replaces the element at the specified position in this table with the specified element.
|
FastTable<E> |
shared()
Returns a thread-safe view over this collection.
|
int |
size()
Returns the size of this collection.
|
void |
sort()
Sorts this table in place (quick sort).
|
FastTable<E> |
subList(int fromIndex,
int toIndex)
Deprecated.
|
FastTable<E> |
subTable(int fromIndex,
int toIndex)
Returns a view over a portion of the table (equivalent to
List.subList(int, int)). |
FastTable<E> |
unmodifiable()
Returns an unmodifiable view over this collection.
|
add, addAll, any, comparator, contains, containsAll, distinct, equals, filtered, forEach, hashCode, iterator, mapped, max, min, parallel, perform, reduce, remove, removeAll, removeIf, retainAll, sequential, serviceOf, sorted, sorted, toArray, toArray, toImmutable, toString, updateclone, finalize, getClass, notify, notifyAll, wait, wait, waitpublic FastTable()
public FastTable(Equality<? super E> comparator)
protected FastTable(TableService<E> service)
public FastTable<E> atomic()
FastCollectionConcurrentModificationException possible).atomic in class FastCollection<E>public FastTable<E> reversed()
FastCollectionreversed in class FastCollection<E>public FastTable<E> shared()
FastCollectionConcurrentModificationException possible).shared in class FastCollection<E>public FastTable<E> unmodifiable()
FastCollectionUnsupportedOperationException being raised.unmodifiable in class FastCollection<E>public FastTable<E> subTable(int fromIndex, int toIndex)
List.subList(int, int)).@Realtime(limit=CONSTANT) public boolean isEmpty()
FastCollectionisEmpty in interface Collection<E>isEmpty in interface List<E>isEmpty in class FastCollection<E>@Realtime(limit=CONSTANT) public int size()
FastCollection@Realtime(limit=CONSTANT) public void clear()
FastCollectionclear in interface Collection<E>clear in interface List<E>clear in class FastCollection<E>@Realtime(limit=LOG_N) public void add(int index, E element)
@Realtime(limit=N_LOG_N) public boolean addAll(int index, Collection<? extends E> elements)
@Realtime(limit=LOG_N) public E remove(int index)
@Realtime(limit=CONSTANT) public E get(int index)
@Realtime(limit=CONSTANT) public E set(int index, E element)
@Realtime(limit=LINEAR) public int indexOf(Object element)
@Realtime(limit=LINEAR) public int lastIndexOf(Object element)
lastIndexOf in interface List<E>@Realtime(limit=CONSTANT) public ListIterator<E> listIterator()
listIterator in interface List<E>@Realtime(limit=CONSTANT) public ListIterator<E> listIterator(int index)
listIterator in interface List<E>@Realtime(limit=CONSTANT) public void addFirst(E element)
@Realtime(limit=CONSTANT) public void addLast(E element)
@Realtime(limit=CONSTANT) public E getFirst()
@Realtime(limit=CONSTANT) public E getLast()
@Realtime(limit=CONSTANT) public E peekFirst()
@Realtime(limit=CONSTANT) public E peekLast()
@Realtime(limit=CONSTANT) public E pollFirst()
@Realtime(limit=CONSTANT) public E removeFirst()
removeFirst in interface Deque<E>@Realtime(limit=CONSTANT) public E removeLast()
removeLast in interface Deque<E>@Realtime(limit=CONSTANT) public boolean offerFirst(E e)
offerFirst in interface Deque<E>@Realtime(limit=CONSTANT) public boolean offerLast(E e)
@Realtime(limit=LINEAR) public boolean removeFirstOccurrence(Object o)
removeFirstOccurrence in interface Deque<E>@Realtime(limit=LINEAR) public boolean removeLastOccurrence(Object o)
removeLastOccurrence in interface Deque<E>@Realtime(limit=CONSTANT) public boolean offer(E e)
@Realtime(limit=CONSTANT) public E remove()
@Realtime(limit=CONSTANT) public E poll()
@Realtime(limit=CONSTANT) public E element()
@Realtime(limit=CONSTANT) public E peek()
@Realtime(limit=CONSTANT) public void push(E e)
@Realtime(limit=CONSTANT) public E pop()
@Realtime(limit=CONSTANT) public Iterator<E> descendingIterator()
descendingIterator in interface Deque<E>@Realtime(limit=LINEAR) public FastTable<E> addAll(E... elements)
FastCollectionaddAll in class FastCollection<E>elements - the elements to be added.this@Realtime(limit=LINEAR) public FastTable<E> addAll(FastCollection<? extends E> that)
FastCollectionaddAll in class FastCollection<E>@Deprecated public FastTable<E> subList(int fromIndex, int toIndex)
subTable(int, int). The term "List" for an
interface with random access is disturbing !protected TableService<E> service()
FastCollectionservice in class FastCollection<E>Copyright © 2005-2013 Javolution. All Rights Reserved.