T - the type of the items in the listpublic class ZenoChain<T>
extends java.lang.Object
implements java.lang.Iterable<T>
For a list built by appending to the end, the size of sublists goes as follows as the list grows: (1).. (32).. (32,1).. (32,32).. (64,1).. (64,32).. (64,32,1).. (64,32,32).. (64,64,1).. (64,64,32).. (128,32,1).. (128,64,1).. (128,64,32,1).. For a list of 20,000 items we get 10 sublists with sizes (8192, 4096, 4096, 2048, 1024, 256, 128, 64, 64, 32). The exact numbers don't matter, the important thing is that the number of sublists is log(N) with shorter sublists at the end of the sequence where append/prepend operations take place.
When two lists are concatenated, the two master lists are first concatenated, followed by a consolidation to combine short lists now appearing near the middle of the structure, to reduce the number of sublists.
The current implementation is a mutable structure, but it is designed to make creation of a mutable variant easy.
| Constructor and Description |
|---|
ZenoChain()
Create an empty sequence
|
| Modifier and Type | Method and Description |
|---|---|
ZenoChain<T> |
add(T item)
Append an item
|
ZenoChain<T> |
addAll(java.lang.Iterable<? extends T> items)
Append a sequence of items
|
ZenoChain<T> |
concat(ZenoChain<T> other) |
T |
get(int n)
Get the item at position n, zero-based
|
boolean |
isEmpty()
Ask if the list is empty
|
boolean |
isSingleton()
Ask if the list is a singleton
|
java.util.Iterator<T> |
iterator()
Iterate over the items
|
static void |
main(java.lang.String[] args) |
ZenoChain<T> |
prepend(T item)
Prepend an item
|
java.lang.String |
show() |
int |
size()
Get the size of the list
|
ZenoChain<T> |
subList(int start,
int end) |
java.lang.String |
toString() |
public ZenoChain<T> add(T item)
item - the item to be appendedpublic ZenoChain<T> prepend(T item)
item - the item to be prependedpublic ZenoChain<T> addAll(java.lang.Iterable<? extends T> items)
items - the sequence of items to be appendedpublic T get(int n)
n - the requested indexjava.lang.IndexOutOfBoundsException - if n is negative or beyond the end of the listpublic int size()
public boolean isEmpty()
public boolean isSingleton()
public java.util.Iterator<T> iterator()
iterator in interface java.lang.Iterable<T>public java.lang.String toString()
toString in class java.lang.Objectpublic java.lang.String show()
public static void main(java.lang.String[] args)
Copyright (c) 2004-2022 Saxonica Limited. All rights reserved.