Version 18 (modified by wouter, 3 years ago) ( diff )

--

ImmutableList

Part of utilities.

ImmutableList is similar to the common java.util.List: it contains a list of elements. However, the big differences are

  • ImmutableList allows virtually unlimited sizes.
  • ImmutableList does lazy evaluation: it is generating elements on request only, and does not keep the elements.
  • ImmutableList is immutable, so it can not be modified

As a simple comparison, suppose you need a list of all integers between 100000 and 200000. You could write a loop to fill 1000 elements of an ArrayList. This takes you about a megabyte of memory plus the time of filling the array. Alternatively, you can use Range(100000,200000, 1). This takes almost no memory (storing 3 BigDecimals plus some overhead), and no additinal time.

This mechanism is especially useful when the list elements have to be generated on an as-needed basis. For example when large lists are used, when the list elements are expensive to create, or when you already know that the user of the list will only pick a few items from the list, or even just wants to know the size of the list.

The main classes here are

class function
ImmutableList interface, providing get(BigInteger) and size() and being Iterable
AbstractImmutableList abstract superclass with default iterator() implementation, toString and get(long)
JoinedList Joins multiple ImmutableLists into one.
MapList Maps a function over the input list.
MapThreadList Maps a 2-arg function over 2 lists.
RandomIntegersA list of pseudo-random numbers. List size is restricted to powers of 2.
Outer Maps an input list into a list containing all possible combinations with one element from each of the provided lists.
AbstractPermutations Abstract superclass of all classes that map some input list into a list of all permutations of the input list.
PermutationsOrderedWithoutReturn Maps input list into list of all permutations of the input list, when drawing N without return.
PermutationsWithoutReturn Maps input list into list of all permutations of the input list, when drawn all without return.
PermutationsWithReturnMaps the input list into list of all permutations of the input list, when drawn all with return.
RangeA list of all values from low to high with given step size
RangeIntAs Range, but with BigInteger values.
ShuffleA list of all values of the input list, but shuffled to random order
TuplesMaps two input lists into a list of tuples.
SubListA sublist of a given list. The selected elements are indicated with a binary code, with 1 indicating a selected element.
SubListsA list of all sublists of size k of the given list.
PartitioningsThe set of all possible partitionings - all possible ways to split the set into non-empty groups.
Note: See TracWiki for help on using the wiki.