JavaScript is disabled on your browser.
javolution.util

Class FastTable<E>

  • All Implemented Interfaces:
    Serializable, Iterable<E>, Collection<E>, Deque<E>, List<E>, Queue<E>, RandomAccess
    Direct Known Subclasses:
    FastSortedTable


    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.

    Worst Case Execution Time

    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.

    Version:
    6.0, July 21, 2013
    Author:
    Jean-Marie Dautelle
    See Also:
    Serialized Form
    • Constructor Summary

      Constructors
      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.

Copyright © 2005-2013 Javolution. All Rights Reserved.

AltStyle によって変換されたページ (->オリジナル) /