Changes between Version 11 and Version 12 of immutablelist


Ignore:
Timestamp:
07/03/21 11:39:14 (4 years ago)
Author:
wouter
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • immutablelist

    v11 v12  
    66ImmutableList is similar to the common java.util.List: it contains a list of elements.
    77However, the big differences are
     8 * ImmutableList allows almost-unlimited sizes.
     9 * ImmutableList does lazy evaluation: it is generating elements on request only, and does not keep the elements.
    810 * ImmutableList is immutable, so it can not be modified
    9  * ImmutableList is generating elements on request only, and does not keep the elements.
    1011
    11 As a simple comparison, suppose you need a list of all integers between 1000 and 2000. You could write a loop to fill 1000 elements of an ArrayList. Alternatively, you can create an ImmutableList instance where get(n) creates and returns the expected element on request.
    12 
    13 ImmutableList uses BigInteger for indexing to support unlimited list sizes.
     12As 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.
    1413
    1514This 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.