public class FastTable<E> extends FastCollection<E> implements List<E>, Deque<E>, RandomAccess
A high-performance table (fractal-based) with real-time
behavior; smooth capacity increase/decrease and minimal memory footprint.
The fractal-based implementation ensures that add/insertion/deletion operations
worst execution time is always in O(log(size)) (for
comparison ArrayList.add
is in O(size) due to resize).
The capacity of a fast table
is automatically adjusted to best fit its size (e.g. when a table is cleared
its memory footprint is minimal).
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
views. They inherit all the fast collection
views and support the new subList
view over a portion of the table.
FastTable<String> names = new FastTable<String>().addAll("John Deuff", "Otto Graf", "Sim Kamil"); names.sort(Comparators.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.parallel().filtered(str -> str.startsWith("A")).clear(); // Same as above but performed concurrently !
As for any fast collection
, iterations are faster
when performed using closures (and the notation shorter with Java 8).
This is also the preferred mean of iterating over shared
instances since ConcurrentModificationException
cannot occur.
FastTable<Person> persons = new FastTable<Person>().shared(); // Thread-safe view. ... Person findWithName(final String name) { return persons.filtered(new Predicate<Person>() { public boolean test(Person person) { return (person.getName().equals(name)); } }).reduce(Operators.ANY); }
Person findWithName(String name) {
return persons.filtered(person -> person.getName().equals(name)).reduce(Operators.ANY);
}
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 element order.
FastCollection.StandardText
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(EqualityComparator<? 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)
List operations.
|
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.
|
boolean |
addAll(int index,
Collection<? extends E> elements) |
void |
addFirst(E element) |
void |
addLast(E element) |
void |
clear() |
Iterator<E> |
descendingIterator() |
E |
element() |
E |
get(int index) |
E |
getFirst()
Deque operations (atomic when the table is shared).
|
E |
getLast() |
int |
indexOf(Object element) |
boolean |
isEmpty()
Collection operations.
|
Iterator<E> |
iterator() |
int |
lastIndexOf(Object element) |
ListIterator<E> |
listIterator() |
ListIterator<E> |
listIterator(int index) |
boolean |
offer(E e) |
boolean |
offerFirst(E e) |
boolean |
offerLast(E e) |
E |
peek() |
E |
peekFirst() |
E |
peekLast() |
E |
poll() |
E |
pollFirst() |
E |
pollLast() |
E |
pop() |
void |
push(E e) |
E |
remove() |
E |
remove(int index) |
E |
removeFirst() |
boolean |
removeFirstOccurrence(Object obj) |
E |
removeLast() |
boolean |
removeLastOccurrence(Object obj) |
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) |
FastTable<E> |
shared()
Returns a thread-safe view over this collection.
|
int |
size() |
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()
Views.
|
add, addAll, atomic, comparator, comparator, contains, containsAll, distinct, doWhile, equals, filtered, forEach, hashCode, mapped, parallel, reduce, remove, removeAll, removeIf, retainAll, sequential, serviceOf, sorted, toArray, toArray, toImmutable, toString
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
public FastTable()
public FastTable(EqualityComparator<? super E> comparator)
protected FastTable(TableService<E> service)
public FastTable<E> unmodifiable()
unmodifiable
in class FastCollection<E>
public FastTable<E> shared()
FastCollection
immutable
collections to be replaced at each update rather than shared views.shared
in class FastCollection<E>
public FastTable<E> reversed()
FastCollection
reversed
in class FastCollection<E>
public FastTable<E> subTable(int fromIndex, int toIndex)
List.subList(int, int)
).@Realtime(limit=CONSTANT) public boolean isEmpty()
isEmpty
in interface Collection<E>
isEmpty
in interface List<E>
isEmpty
in class FastCollection<E>
@Realtime(limit=CONSTANT) public void clear()
clear
in interface Collection<E>
clear
in interface List<E>
clear
in class FastCollection<E>
@Realtime(limit=N_LOG_N) public boolean addAll(int index, Collection<? extends E> elements)
@Realtime(limit=LINEAR) public int lastIndexOf(Object element)
lastIndexOf
in interface List<E>
public ListIterator<E> listIterator()
listIterator
in interface List<E>
public ListIterator<E> listIterator(int index)
listIterator
in interface List<E>
public E getFirst()
public E removeFirst()
removeFirst
in interface Deque<E>
public E removeLast()
removeLast
in interface Deque<E>
public boolean offerFirst(E e)
offerFirst
in interface Deque<E>
public boolean removeFirstOccurrence(Object obj)
removeFirstOccurrence
in interface Deque<E>
public boolean removeLastOccurrence(Object obj)
removeLastOccurrence
in interface Deque<E>
public boolean offer(E e)
public E remove()
public E poll()
public E element()
public E peek()
public Iterator<E> descendingIterator()
descendingIterator
in interface Deque<E>
public FastTable<E> addAll(E... elements)
FastCollection
addAll
in class FastCollection<E>
elements
- the elements to be added.this
public FastTable<E> addAll(FastCollection<? extends E> that)
FastCollection
addAll
in class FastCollection<E>
@Deprecated public FastTable<E> subList(int fromIndex, int toIndex)
subTable(int, int)
protected TableService<E> service()
FastCollection
service
in class FastCollection<E>
Copyright © 2005-2013 Javolution. All Rights Reserved.