code
stringlengths 23
201k
| docstring
stringlengths 17
96.2k
| func_name
stringlengths 0
235
| language
stringclasses 1
value | repo
stringlengths 8
72
| path
stringlengths 11
317
| url
stringlengths 57
377
| license
stringclasses 7
values |
|---|---|---|---|---|---|---|---|
@Override
public LinearSet<V> union(ISet<V> s) {
if (s instanceof LinearSet) {
return new LinearSet<V>(map.union(((LinearSet<V>) s).map));
} else {
LinearMap<V, Void> m = map.clone();
s.forEach(e -> m.put(e, null));
return new LinearSet<V>(m);
}
}
|
@param hashFn the hash function used by the set
@param equalsFn the equality semantics used by the set
|
union
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/LinearSet.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/LinearSet.java
|
MIT
|
@Override
public LinearSet<V> difference(ISet<V> s) {
if (s instanceof LinearSet) {
return new LinearSet<V>(map.difference(((LinearSet<V>) s).map));
} else {
LinearMap<V, Void> m = map.clone();
s.forEach(m::remove);
return new LinearSet<V>(m);
}
}
|
@param hashFn the hash function used by the set
@param equalsFn the equality semantics used by the set
|
difference
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/LinearSet.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/LinearSet.java
|
MIT
|
@Override
public LinearSet<V> intersection(ISet<V> s) {
if (s instanceof LinearSet) {
return new LinearSet<V>(map.intersection(((LinearSet<V>) s).map));
} else {
LinearMap<V, Void> m = map.clone();
for (V e : this) {
if (!s.contains(e)) {
m.remove(e);
}
}
return new LinearSet<V>(m);
}
}
|
@param hashFn the hash function used by the set
@param equalsFn the equality semantics used by the set
|
intersection
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/LinearSet.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/LinearSet.java
|
MIT
|
@Override
public ISet<V> forked() {
return Set.from(this);
}
|
@param hashFn the hash function used by the set
@param equalsFn the equality semantics used by the set
|
forked
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/LinearSet.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/LinearSet.java
|
MIT
|
@Override
public LinearSet<V> linear() {
return this;
}
|
@param hashFn the hash function used by the set
@param equalsFn the equality semantics used by the set
|
linear
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/LinearSet.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/LinearSet.java
|
MIT
|
@Override
public List<LinearSet<V>> split(int parts) {
return map.split(parts).stream().map(m -> new LinearSet<>(m)).collect(Lists.collector());
}
|
@param hashFn the hash function used by the set
@param equalsFn the equality semantics used by the set
|
split
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/LinearSet.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/LinearSet.java
|
MIT
|
@Override
public int hashCode() {
if (hash == -1) {
hash = 0;
for (long row : map.table) {
if (LinearMap.Row.populated(row)) {
hash += LinearMap.Row.hash(row);
}
}
}
return hash;
}
|
@param hashFn the hash function used by the set
@param equalsFn the equality semantics used by the set
|
hashCode
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/LinearSet.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/LinearSet.java
|
MIT
|
@Override
public LinearSet<V> clone() {
return new LinearSet<>(map.clone());
}
|
@param hashFn the hash function used by the set
@param equalsFn the equality semantics used by the set
|
clone
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/LinearSet.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/LinearSet.java
|
MIT
|
public static <V> List<V> of(V... elements) {
List<V> list = new List<V>().linear();
for (V e : elements) {
list.addLast(e);
}
return list.forked();
}
|
An implementation of an immutable list which allows for elements to be added and removed from both ends of the
collection, as well as random-access reads and writes. Due to its
<a href=https://infoscience.epfl.ch/record/169879/files/RMTrees.pdf>relaxed radix structure</a>, {@code slice()},
{@code concat()}, and {@code split()} are near-constant time.
@author ztellman
|
of
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/List.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/List.java
|
MIT
|
public static <V> List<V> from(IList<V> list) {
if (list instanceof List) {
return ((List<V>) list).forked();
} else {
return from(list.iterator());
}
}
|
An implementation of an immutable list which allows for elements to be added and removed from both ends of the
collection, as well as random-access reads and writes. Due to its
<a href=https://infoscience.epfl.ch/record/169879/files/RMTrees.pdf>relaxed radix structure</a>, {@code slice()},
{@code concat()}, and {@code split()} are near-constant time.
@author ztellman
|
from
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/List.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/List.java
|
MIT
|
public static <V> List<V> from(Iterable<V> iterable) {
return from(iterable.iterator());
}
|
An implementation of an immutable list which allows for elements to be added and removed from both ends of the
collection, as well as random-access reads and writes. Due to its
<a href=https://infoscience.epfl.ch/record/169879/files/RMTrees.pdf>relaxed radix structure</a>, {@code slice()},
{@code concat()}, and {@code split()} are near-constant time.
@author ztellman
|
from
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/List.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/List.java
|
MIT
|
public static <V> List<V> from(Iterator<V> iterator) {
List<V> list = new List<V>().linear();
iterator.forEachRemaining(list::addLast);
return list.forked();
}
|
An implementation of an immutable list which allows for elements to be added and removed from both ends of the
collection, as well as random-access reads and writes. Due to its
<a href=https://infoscience.epfl.ch/record/169879/files/RMTrees.pdf>relaxed radix structure</a>, {@code slice()},
{@code concat()}, and {@code split()} are near-constant time.
@author ztellman
|
from
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/List.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/List.java
|
MIT
|
public static <V> List<V> empty() {
return (List<V>) EMPTY;
}
|
An implementation of an immutable list which allows for elements to be added and removed from both ends of the
collection, as well as random-access reads and writes. Due to its
<a href=https://infoscience.epfl.ch/record/169879/files/RMTrees.pdf>relaxed radix structure</a>, {@code slice()},
{@code concat()}, and {@code split()} are near-constant time.
@author ztellman
|
empty
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/List.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/List.java
|
MIT
|
@Override
public V nth(long idx) {
long rootSize = root.size();
if (idx < 0 || idx >= (rootSize + prefixLen + suffixLen)) {
throw new IndexOutOfBoundsException(idx + " must be within [0," + size() + ")");
}
// look in the prefix
if (idx < prefixLen) {
return (V) prefix[(int) (prefix.length + idx - prefixLen)];
// look in the tree
} else if (idx - prefixLen < rootSize) {
return (V) root.nth(idx - prefixLen, false);
// look in the suffix
} else {
return (V) suffix[(int) (idx - (rootSize + prefixLen))];
}
}
|
An implementation of an immutable list which allows for elements to be added and removed from both ends of the
collection, as well as random-access reads and writes. Due to its
<a href=https://infoscience.epfl.ch/record/169879/files/RMTrees.pdf>relaxed radix structure</a>, {@code slice()},
{@code concat()}, and {@code split()} are near-constant time.
@author ztellman
|
nth
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/List.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/List.java
|
MIT
|
@Override
public long size() {
return root.size() + prefixLen + suffixLen;
}
|
An implementation of an immutable list which allows for elements to be added and removed from both ends of the
collection, as well as random-access reads and writes. Due to its
<a href=https://infoscience.epfl.ch/record/169879/files/RMTrees.pdf>relaxed radix structure</a>, {@code slice()},
{@code concat()}, and {@code split()} are near-constant time.
@author ztellman
|
size
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/List.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/List.java
|
MIT
|
@Override
public boolean isLinear() {
return editor != null;
}
|
An implementation of an immutable list which allows for elements to be added and removed from both ends of the
collection, as well as random-access reads and writes. Due to its
<a href=https://infoscience.epfl.ch/record/169879/files/RMTrees.pdf>relaxed radix structure</a>, {@code slice()},
{@code concat()}, and {@code split()} are near-constant time.
@author ztellman
|
isLinear
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/List.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/List.java
|
MIT
|
@Override
public List<V> addLast(V value) {
return (isLinear() ? this : clone()).pushLast(value);
}
|
An implementation of an immutable list which allows for elements to be added and removed from both ends of the
collection, as well as random-access reads and writes. Due to its
<a href=https://infoscience.epfl.ch/record/169879/files/RMTrees.pdf>relaxed radix structure</a>, {@code slice()},
{@code concat()}, and {@code split()} are near-constant time.
@author ztellman
|
addLast
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/List.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/List.java
|
MIT
|
@Override
public List<V> addFirst(V value) {
return (isLinear() ? this : clone()).pushFirst(value);
}
|
An implementation of an immutable list which allows for elements to be added and removed from both ends of the
collection, as well as random-access reads and writes. Due to its
<a href=https://infoscience.epfl.ch/record/169879/files/RMTrees.pdf>relaxed radix structure</a>, {@code slice()},
{@code concat()}, and {@code split()} are near-constant time.
@author ztellman
|
addFirst
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/List.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/List.java
|
MIT
|
@Override
public List<V> removeLast() {
return (isLinear() ? this : clone()).popLast();
}
|
An implementation of an immutable list which allows for elements to be added and removed from both ends of the
collection, as well as random-access reads and writes. Due to its
<a href=https://infoscience.epfl.ch/record/169879/files/RMTrees.pdf>relaxed radix structure</a>, {@code slice()},
{@code concat()}, and {@code split()} are near-constant time.
@author ztellman
|
removeLast
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/List.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/List.java
|
MIT
|
@Override
public List<V> removeFirst() {
return (isLinear() ? this : clone()).popFirst();
}
|
An implementation of an immutable list which allows for elements to be added and removed from both ends of the
collection, as well as random-access reads and writes. Due to its
<a href=https://infoscience.epfl.ch/record/169879/files/RMTrees.pdf>relaxed radix structure</a>, {@code slice()},
{@code concat()}, and {@code split()} are near-constant time.
@author ztellman
|
removeFirst
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/List.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/List.java
|
MIT
|
@Override
public List<V> set(long idx, V value) {
int size = (int) size();
if (idx < 0 || idx > size) {
throw new IndexOutOfBoundsException();
}
if (idx == size) {
return addLast(value);
} else {
return (isLinear() ? this : clone()).overwrite((int) idx, value);
}
}
|
An implementation of an immutable list which allows for elements to be added and removed from both ends of the
collection, as well as random-access reads and writes. Due to its
<a href=https://infoscience.epfl.ch/record/169879/files/RMTrees.pdf>relaxed radix structure</a>, {@code slice()},
{@code concat()}, and {@code split()} are near-constant time.
@author ztellman
|
set
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/List.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/List.java
|
MIT
|
@Override
public Iterator<V> iterator() {
final Object[] initChunk;
final int initOffset, initLimit;
final long size = size();
final long rootSize = root.size();
if (prefixLen > 0) {
initChunk = prefix;
initOffset = pIdx(0);
initLimit = prefix.length;
} else if (rootSize > 0) {
initChunk = (Object[]) root.nth(0, true);
initOffset = 0;
initLimit = initChunk.length;
} else {
initChunk = suffix;
initOffset = 0;
initLimit = suffixLen;
}
return new Iterator<V>() {
long idx = 0;
Object[] chunk = initChunk;
int offset = initOffset;
int limit = initLimit;
int chunkSize = limit - offset;
@Override
public boolean hasNext() {
return idx < size;
}
@Override
public V next() {
V val = (V) chunk[offset++];
if (offset == limit) {
idx += chunkSize;
if (idx < size) {
if (idx == prefixLen + rootSize) {
chunk = suffix;
limit = suffixLen;
} else {
chunk = (Object[]) root.nth(idx - prefixLen, true);
limit = chunk.length;
}
offset = 0;
chunkSize = limit;
}
}
return val;
}
};
}
|
An implementation of an immutable list which allows for elements to be added and removed from both ends of the
collection, as well as random-access reads and writes. Due to its
<a href=https://infoscience.epfl.ch/record/169879/files/RMTrees.pdf>relaxed radix structure</a>, {@code slice()},
{@code concat()}, and {@code split()} are near-constant time.
@author ztellman
|
iterator
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/List.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/List.java
|
MIT
|
@Override
public boolean hasNext() {
return idx < size;
}
|
An implementation of an immutable list which allows for elements to be added and removed from both ends of the
collection, as well as random-access reads and writes. Due to its
<a href=https://infoscience.epfl.ch/record/169879/files/RMTrees.pdf>relaxed radix structure</a>, {@code slice()},
{@code concat()}, and {@code split()} are near-constant time.
@author ztellman
|
hasNext
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/List.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/List.java
|
MIT
|
@Override
public V next() {
V val = (V) chunk[offset++];
if (offset == limit) {
idx += chunkSize;
if (idx < size) {
if (idx == prefixLen + rootSize) {
chunk = suffix;
limit = suffixLen;
} else {
chunk = (Object[]) root.nth(idx - prefixLen, true);
limit = chunk.length;
}
offset = 0;
chunkSize = limit;
}
}
return val;
}
|
An implementation of an immutable list which allows for elements to be added and removed from both ends of the
collection, as well as random-access reads and writes. Due to its
<a href=https://infoscience.epfl.ch/record/169879/files/RMTrees.pdf>relaxed radix structure</a>, {@code slice()},
{@code concat()}, and {@code split()} are near-constant time.
@author ztellman
|
next
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/List.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/List.java
|
MIT
|
@Override
public List<V> slice(long start, long end) {
if (start < 0 || end > size()) {
throw new IndexOutOfBoundsException("[" + start + "," + end + ") isn't a subset of [0,"+ size() + ")");
} else if (end <= start) {
return new List<>();
}
int pStart = (int) min(prefixLen, start);
int pEnd = (int) min(prefixLen, end);
int pLen = pEnd - pStart;
Object[] pre = null;
if (pLen > 0) {
pre = new Object[1 << log2Ceil(pLen)];
arraycopy(prefix, pIdx(pStart), pre, pre.length - pLen, pLen);
}
int sStart = (int) Math.max(0, start - (prefixLen + root.size()));
int sEnd = (int) Math.max(0, end - (prefixLen + root.size()));
int sLen = sEnd - sStart;
Object[] suf = null;
if (sLen > 0) {
suf = new Object[1 << log2Ceil(sLen)];
arraycopy(suffix, sStart, suf, 0, sLen);
}
return new List<V>(
isLinear(),
root.slice(
Math.max(0, min(root.size(), start - prefixLen)),
Math.max(0, min(root.size(), end - prefixLen)),
new Object()
),
pLen, pre, sLen, suf
);
}
|
An implementation of an immutable list which allows for elements to be added and removed from both ends of the
collection, as well as random-access reads and writes. Due to its
<a href=https://infoscience.epfl.ch/record/169879/files/RMTrees.pdf>relaxed radix structure</a>, {@code slice()},
{@code concat()}, and {@code split()} are near-constant time.
@author ztellman
|
slice
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/List.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/List.java
|
MIT
|
@Override
public IList<V> concat(IList<V> l) {
if (l instanceof List) {
List<V> b = (List<V>) l;
Node r = root;
Object editor = new Object();
// append our own suffix
if (suffixLen > 0) {
r = r.pushLast(suffixArray(), editor);
}
// append their prefix
if (b.prefixLen > 0) {
r = r.pushLast(b.prefixArray(), editor);
}
if (b.root.size() > 0) {
r = r.concat(b.root, editor);
}
return new List<V>(
isLinear(), r,
prefixLen, prefixLen > 0 ? prefix.clone() : null,
b.suffixLen, b.suffixLen > 0 ? b.suffix.clone() : null
);
} else {
return Lists.concat(this, l);
}
}
|
An implementation of an immutable list which allows for elements to be added and removed from both ends of the
collection, as well as random-access reads and writes. Due to its
<a href=https://infoscience.epfl.ch/record/169879/files/RMTrees.pdf>relaxed radix structure</a>, {@code slice()},
{@code concat()}, and {@code split()} are near-constant time.
@author ztellman
|
concat
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/List.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/List.java
|
MIT
|
@Override
public List<V> forked() {
return isLinear() ? new List(false, root, prefixLen, prefix, suffixLen, suffix).clone() : this;
}
|
An implementation of an immutable list which allows for elements to be added and removed from both ends of the
collection, as well as random-access reads and writes. Due to its
<a href=https://infoscience.epfl.ch/record/169879/files/RMTrees.pdf>relaxed radix structure</a>, {@code slice()},
{@code concat()}, and {@code split()} are near-constant time.
@author ztellman
|
forked
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/List.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/List.java
|
MIT
|
@Override
public List<V> linear() {
return isLinear() ? this : new List(true, root, prefixLen, prefix, suffixLen, suffix).clone();
}
|
An implementation of an immutable list which allows for elements to be added and removed from both ends of the
collection, as well as random-access reads and writes. Due to its
<a href=https://infoscience.epfl.ch/record/169879/files/RMTrees.pdf>relaxed radix structure</a>, {@code slice()},
{@code concat()}, and {@code split()} are near-constant time.
@author ztellman
|
linear
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/List.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/List.java
|
MIT
|
@Override
public List<V> clone() {
return new List<V>(
isLinear(), root,
prefixLen, prefix == null ? null : prefix.clone(),
suffixLen, suffix == null ? null : suffix.clone()
);
}
|
An implementation of an immutable list which allows for elements to be added and removed from both ends of the
collection, as well as random-access reads and writes. Due to its
<a href=https://infoscience.epfl.ch/record/169879/files/RMTrees.pdf>relaxed radix structure</a>, {@code slice()},
{@code concat()}, and {@code split()} are near-constant time.
@author ztellman
|
clone
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/List.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/List.java
|
MIT
|
private Object[] suffixArray() {
Object[] suf = new Object[suffixLen];
arraycopy(suffix, 0, suf, 0, suf.length);
return suf;
}
|
An implementation of an immutable list which allows for elements to be added and removed from both ends of the
collection, as well as random-access reads and writes. Due to its
<a href=https://infoscience.epfl.ch/record/169879/files/RMTrees.pdf>relaxed radix structure</a>, {@code slice()},
{@code concat()}, and {@code split()} are near-constant time.
@author ztellman
|
suffixArray
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/List.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/List.java
|
MIT
|
private Object[] prefixArray() {
Object[] pre = new Object[prefixLen];
arraycopy(prefix, pIdx(0), pre, 0, pre.length);
return pre;
}
|
An implementation of an immutable list which allows for elements to be added and removed from both ends of the
collection, as well as random-access reads and writes. Due to its
<a href=https://infoscience.epfl.ch/record/169879/files/RMTrees.pdf>relaxed radix structure</a>, {@code slice()},
{@code concat()}, and {@code split()} are near-constant time.
@author ztellman
|
prefixArray
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/List.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/List.java
|
MIT
|
private int pIdx(int idx) {
return prefix.length - prefixLen + idx;
}
|
An implementation of an immutable list which allows for elements to be added and removed from both ends of the
collection, as well as random-access reads and writes. Due to its
<a href=https://infoscience.epfl.ch/record/169879/files/RMTrees.pdf>relaxed radix structure</a>, {@code slice()},
{@code concat()}, and {@code split()} are near-constant time.
@author ztellman
|
pIdx
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/List.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/List.java
|
MIT
|
List<V> overwrite(int idx, V value) {
long rootSize = root.size();
// overwrite prefix
if (idx < prefixLen) {
prefix[prefix.length - prefixLen + idx] = value;
// overwrite tree
} else if (idx < (prefixLen + rootSize)) {
root = root.set(editor, idx - prefixLen, value);
// overwrite suffix
} else {
suffix[(int) (idx - (prefixLen + rootSize))] = value;
}
return this;
}
|
An implementation of an immutable list which allows for elements to be added and removed from both ends of the
collection, as well as random-access reads and writes. Due to its
<a href=https://infoscience.epfl.ch/record/169879/files/RMTrees.pdf>relaxed radix structure</a>, {@code slice()},
{@code concat()}, and {@code split()} are near-constant time.
@author ztellman
|
overwrite
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/List.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/List.java
|
MIT
|
List<V> pushFirst(V value) {
if (prefix == null) {
prefix = new Object[2];
} else if (prefixLen == prefix.length) {
Object[] newPrefix = new Object[min(MAX_CHUNK_SIZE, prefix.length << 1)];
arraycopy(prefix, 0, newPrefix, newPrefix.length - prefixLen, prefixLen);
prefix = newPrefix;
}
prefix[pIdx(-1)] = value;
prefixLen++;
if (prefixLen == MAX_CHUNK_SIZE) {
Object editor = isLinear() ? this.editor : new Object();
root = root.pushFirst(prefix, editor);
prefix = null;
prefixLen = 0;
}
return this;
}
|
An implementation of an immutable list which allows for elements to be added and removed from both ends of the
collection, as well as random-access reads and writes. Due to its
<a href=https://infoscience.epfl.ch/record/169879/files/RMTrees.pdf>relaxed radix structure</a>, {@code slice()},
{@code concat()}, and {@code split()} are near-constant time.
@author ztellman
|
pushFirst
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/List.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/List.java
|
MIT
|
List<V> pushLast(V value) {
if (suffix == null) {
suffix = new Object[2];
} else if (suffixLen == suffix.length) {
Object[] newSuffix = new Object[min(MAX_CHUNK_SIZE, suffix.length << 1)];
arraycopy(suffix, 0, newSuffix, 0, suffix.length);
suffix = newSuffix;
}
suffix[suffixLen++] = value;
if (suffixLen == MAX_CHUNK_SIZE) {
Object editor = isLinear() ? this.editor : new Object();
root = root.pushLast(suffix, editor);
suffix = null;
suffixLen = 0;
}
return this;
}
|
An implementation of an immutable list which allows for elements to be added and removed from both ends of the
collection, as well as random-access reads and writes. Due to its
<a href=https://infoscience.epfl.ch/record/169879/files/RMTrees.pdf>relaxed radix structure</a>, {@code slice()},
{@code concat()}, and {@code split()} are near-constant time.
@author ztellman
|
pushLast
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/List.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/List.java
|
MIT
|
List<V> popFirst() {
if (prefixLen == 0) {
if (root.size() > 0) {
Object[] chunk = root.first();
if (chunk != null) {
Object editor = isLinear() ? this.editor : new Object();
prefix = chunk.clone();
prefixLen = (byte) prefix.length;
root = root.popFirst(editor);
}
} else if (suffixLen > 0) {
arraycopy(suffix, 1, suffix, 0, --suffixLen);
suffix[suffixLen] = null;
}
}
if (prefixLen > 0) {
prefixLen--;
prefix[pIdx(-1)] = null;
}
return this;
}
|
An implementation of an immutable list which allows for elements to be added and removed from both ends of the
collection, as well as random-access reads and writes. Due to its
<a href=https://infoscience.epfl.ch/record/169879/files/RMTrees.pdf>relaxed radix structure</a>, {@code slice()},
{@code concat()}, and {@code split()} are near-constant time.
@author ztellman
|
popFirst
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/List.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/List.java
|
MIT
|
List<V> popLast() {
if (suffixLen == 0) {
if (root.size() > 0) {
Object[] chunk = root.last();
if (chunk != null) {
Object editor = isLinear() ? this.editor : new Object();
suffix = chunk.clone();
suffixLen = (byte) suffix.length;
root = root.popLast(editor);
}
} else if (prefixLen > 0) {
prefixLen--;
arraycopy(prefix, pIdx(-1), prefix, pIdx(0), prefixLen);
prefix[pIdx(-1)] = null;
}
}
if (suffixLen > 0) {
suffix[--suffixLen] = null;
}
return this;
}
|
An implementation of an immutable list which allows for elements to be added and removed from both ends of the
collection, as well as random-access reads and writes. Due to its
<a href=https://infoscience.epfl.ch/record/169879/files/RMTrees.pdf>relaxed radix structure</a>, {@code slice()},
{@code concat()}, and {@code split()} are near-constant time.
@author ztellman
|
popLast
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/List.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/List.java
|
MIT
|
@Override
public int size() {
return (int) list.size();
}
|
Utility functions for classes implementing {@link IList}.
@author ztellman
|
size
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/Lists.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/Lists.java
|
MIT
|
@Override
public boolean isEmpty() {
return list.size() == 0;
}
|
Utility functions for classes implementing {@link IList}.
@author ztellman
|
isEmpty
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/Lists.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/Lists.java
|
MIT
|
@Override
public boolean contains(Object o) {
return list.stream().anyMatch(e -> Objects.equals(o, e));
}
|
Utility functions for classes implementing {@link IList}.
@author ztellman
|
contains
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/Lists.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/Lists.java
|
MIT
|
@Override
public Iterator<V> iterator() {
return list.iterator();
}
|
Utility functions for classes implementing {@link IList}.
@author ztellman
|
iterator
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/Lists.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/Lists.java
|
MIT
|
@Override
public Object[] toArray() {
return list.toArray();
}
|
Utility functions for classes implementing {@link IList}.
@author ztellman
|
toArray
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/Lists.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/Lists.java
|
MIT
|
@Override
@SuppressWarnings("unchecked")
public <T> T[] toArray(T[] a) {
T[] ary = a.length < size() ? (T[]) Array.newInstance(a.getClass().getComponentType(), size()) : a;
IntStream.range(0, size()).forEach(i -> ary[i] = (T) get(i));
return ary;
}
|
Utility functions for classes implementing {@link IList}.
@author ztellman
|
toArray
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/Lists.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/Lists.java
|
MIT
|
@Override
public boolean add(V v) {
throw new UnsupportedOperationException();
}
|
Utility functions for classes implementing {@link IList}.
@author ztellman
|
add
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/Lists.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/Lists.java
|
MIT
|
@Override
public boolean remove(Object o) {
throw new UnsupportedOperationException();
}
|
Utility functions for classes implementing {@link IList}.
@author ztellman
|
remove
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/Lists.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/Lists.java
|
MIT
|
@Override
public boolean containsAll(Collection<?> c) {
return c.stream().allMatch(e -> contains(e));
}
|
Utility functions for classes implementing {@link IList}.
@author ztellman
|
containsAll
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/Lists.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/Lists.java
|
MIT
|
@Override
public boolean addAll(Collection<? extends V> c) {
throw new UnsupportedOperationException();
}
|
Utility functions for classes implementing {@link IList}.
@author ztellman
|
addAll
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/Lists.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/Lists.java
|
MIT
|
@Override
public boolean addAll(int index, Collection<? extends V> c) {
throw new UnsupportedOperationException();
}
|
Utility functions for classes implementing {@link IList}.
@author ztellman
|
addAll
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/Lists.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/Lists.java
|
MIT
|
@Override
public boolean removeAll(Collection<?> c) {
throw new UnsupportedOperationException();
}
|
Utility functions for classes implementing {@link IList}.
@author ztellman
|
removeAll
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/Lists.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/Lists.java
|
MIT
|
@Override
public boolean retainAll(Collection<?> c) {
throw new UnsupportedOperationException();
}
|
Utility functions for classes implementing {@link IList}.
@author ztellman
|
retainAll
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/Lists.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/Lists.java
|
MIT
|
@Override
public void clear() {
throw new UnsupportedOperationException();
}
|
Utility functions for classes implementing {@link IList}.
@author ztellman
|
clear
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/Lists.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/Lists.java
|
MIT
|
@Override
public V get(int index) {
return list.nth(index);
}
|
Utility functions for classes implementing {@link IList}.
@author ztellman
|
get
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/Lists.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/Lists.java
|
MIT
|
@Override
public V set(int index, V element) {
throw new UnsupportedOperationException();
}
|
Utility functions for classes implementing {@link IList}.
@author ztellman
|
set
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/Lists.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/Lists.java
|
MIT
|
@Override
public void add(int index, V element) {
throw new UnsupportedOperationException();
}
|
Utility functions for classes implementing {@link IList}.
@author ztellman
|
add
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/Lists.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/Lists.java
|
MIT
|
@Override
public V remove(int index) {
throw new UnsupportedOperationException();
}
|
Utility functions for classes implementing {@link IList}.
@author ztellman
|
remove
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/Lists.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/Lists.java
|
MIT
|
@Override
public int indexOf(Object o) {
return IntStream.range(0, size())
.filter(idx -> Objects.equals(get(idx), o))
.findFirst()
.orElse(-1);
}
|
Utility functions for classes implementing {@link IList}.
@author ztellman
|
indexOf
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/Lists.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/Lists.java
|
MIT
|
@Override
public int lastIndexOf(Object o) {
return size() -
IntStream.range(0, size())
.filter(idx -> Objects.equals(get(size() - (idx + 1)), o))
.findFirst()
.orElse(size() + 1);
}
|
Utility functions for classes implementing {@link IList}.
@author ztellman
|
lastIndexOf
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/Lists.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/Lists.java
|
MIT
|
@Override
public ListIterator<V> listIterator() {
return listIterator(0);
}
|
Utility functions for classes implementing {@link IList}.
@author ztellman
|
listIterator
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/Lists.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/Lists.java
|
MIT
|
@Override
public ListIterator<V> listIterator(int index) {
return new ListIterator<V>() {
int idx = index;
@Override
public boolean hasNext() {
return idx < size();
}
@Override
public V next() {
return get(idx++);
}
@Override
public boolean hasPrevious() {
return idx > 0;
}
@Override
public V previous() {
return get(--idx);
}
@Override
public int nextIndex() {
return idx;
}
@Override
public int previousIndex() {
return idx - 1;
}
@Override
public void remove() {
throw new UnsupportedOperationException();
}
@Override
public void set(V v) {
throw new UnsupportedOperationException();
}
@Override
public void add(V v) {
throw new UnsupportedOperationException();
}
};
}
|
Utility functions for classes implementing {@link IList}.
@author ztellman
|
listIterator
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/Lists.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/Lists.java
|
MIT
|
@Override
public boolean hasNext() {
return idx < size();
}
|
Utility functions for classes implementing {@link IList}.
@author ztellman
|
hasNext
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/Lists.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/Lists.java
|
MIT
|
@Override
public V next() {
return get(idx++);
}
|
Utility functions for classes implementing {@link IList}.
@author ztellman
|
next
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/Lists.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/Lists.java
|
MIT
|
@Override
public boolean hasPrevious() {
return idx > 0;
}
|
Utility functions for classes implementing {@link IList}.
@author ztellman
|
hasPrevious
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/Lists.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/Lists.java
|
MIT
|
@Override
public V previous() {
return get(--idx);
}
|
Utility functions for classes implementing {@link IList}.
@author ztellman
|
previous
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/Lists.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/Lists.java
|
MIT
|
@Override
public int nextIndex() {
return idx;
}
|
Utility functions for classes implementing {@link IList}.
@author ztellman
|
nextIndex
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/Lists.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/Lists.java
|
MIT
|
@Override
public int previousIndex() {
return idx - 1;
}
|
Utility functions for classes implementing {@link IList}.
@author ztellman
|
previousIndex
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/Lists.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/Lists.java
|
MIT
|
@Override
public void remove() {
throw new UnsupportedOperationException();
}
|
Utility functions for classes implementing {@link IList}.
@author ztellman
|
remove
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/Lists.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/Lists.java
|
MIT
|
@Override
public void set(V v) {
throw new UnsupportedOperationException();
}
|
Utility functions for classes implementing {@link IList}.
@author ztellman
|
set
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/Lists.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/Lists.java
|
MIT
|
@Override
public void add(V v) {
throw new UnsupportedOperationException();
}
|
Utility functions for classes implementing {@link IList}.
@author ztellman
|
add
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/Lists.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/Lists.java
|
MIT
|
@Override
public java.util.List<V> subList(int fromIndex, int toIndex) {
return Lists.toList(list.slice(fromIndex, toIndex));
}
|
Utility functions for classes implementing {@link IList}.
@author ztellman
|
subList
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/Lists.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/Lists.java
|
MIT
|
@Override
public int hashCode() {
return (int) Lists.hash(list, Objects::hashCode, (a, b) -> (a * 31) + b);
}
|
Utility functions for classes implementing {@link IList}.
@author ztellman
|
hashCode
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/Lists.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/Lists.java
|
MIT
|
@Override
public boolean equals(Object obj) {
if (obj instanceof java.util.List) {
return Lists.equals(list, Lists.from((java.util.List) obj));
}
return false;
}
|
Utility functions for classes implementing {@link IList}.
@author ztellman
|
equals
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/Lists.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/Lists.java
|
MIT
|
@Override
public String toString() {
return Lists.toString(list);
}
|
Utility functions for classes implementing {@link IList}.
@author ztellman
|
toString
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/Lists.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/Lists.java
|
MIT
|
public static <V, U> IList<U> lazyMap(IList<V> l, Function<V, U> f) {
return Lists.from(
l.size(),
i -> f.apply(l.nth(i)),
idx -> Iterators.map(l.iterator(idx), f)
);
}
|
Returns a list which will lazily, and repeatedly, transform each element of the input list on lookup.
@param l a list
@param f a transform function for the elements of the list
@param <V> the element type for the input list
@param <U> the element type for the result list
@return the result list
|
lazyMap
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/Lists.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/Lists.java
|
MIT
|
public static <V> boolean equals(IList<V> a, IList<V> b) {
return equals(a, b, Objects::equals);
}
|
@return true if the two lists are equal, otherwise false
|
equals
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/Lists.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/Lists.java
|
MIT
|
public static <V> boolean equals(IList<V> a, IList<V> b, BiPredicate<V, V> equals) {
if (a == b) {
return true;
} else if (a.size() != b.size()) {
return false;
}
return Iterators.equals(a.iterator(), b.iterator(), equals);
}
|
@param equals a comparison predicate for the lists of the element
@return true if the two lists are equal, otherwise false
|
equals
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/Lists.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/Lists.java
|
MIT
|
public static <V> long hash(IList<V> l) {
return hash(l, Objects::hashCode, (a, b) -> (a * 31) + b);
}
|
@return a hash for the list, which mimics the standard Java hash calculation
|
hash
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/Lists.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/Lists.java
|
MIT
|
public static <V> long hash(IList<V> l, ToLongFunction<V> hash, LongBinaryOperator combiner) {
return l.stream().mapToLong(hash).reduce(combiner).orElse(0);
}
|
@param hash a function which provides a hash for each element
@param combiner a function which combines the accumulated hash and element hash
@return a hash for the list
|
hash
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/Lists.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/Lists.java
|
MIT
|
public static <V> String toString(IList<V> l) {
return toString(l, Objects::toString);
}
|
@return a string representation of the list, using toString() to represent each element
|
toString
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/Lists.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/Lists.java
|
MIT
|
public static <V> String toString(IList<V> l, Function<V, String> printer) {
StringBuilder sb = new StringBuilder("[");
Iterator<V> it = l.iterator();
while (it.hasNext()) {
sb.append(printer.apply(it.next()));
if (it.hasNext()) {
sb.append(", ");
}
}
sb.append("]");
return sb.toString();
}
|
@param printer a function which returns a string representation of an element
@return a string representation fo the list
|
toString
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/Lists.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/Lists.java
|
MIT
|
public static <V> java.util.List<V> toList(IList<V> list) {
return new JavaList(list);
}
|
@return a shim around the input list, presenting it as a standard Java List object
|
toList
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/Lists.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/Lists.java
|
MIT
|
public static <V> IList<V> slice(IList<V> list, long start, long end) {
IList<V> result;
if (end <= start) {
result = List.EMPTY;
} else if (start < 0 || end > list.size()) {
throw new IndexOutOfBoundsException("[" + start + "," + end + ") isn't a subset of [0,"+ list.size() + ")");
} else if (end - start == list.size()) {
result = list;
} else {
result = Lists.from(end - start, i -> list.nth(i + start));
}
return list.isLinear() ? result.linear() : result;
}
|
@param start the inclusive start index of the slice
@param end the exclusive end index of the slice
@return a subset view of the list, which holds onto a reference to the original
|
slice
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/Lists.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/Lists.java
|
MIT
|
public static <V> IList<V> from(V[] array) {
return Lists.from(array.length, idx -> array[(int) idx]);
}
|
@return a view of the array as an IList
|
from
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/Lists.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/Lists.java
|
MIT
|
public static <V> IList<V> from(java.util.List<V> list) {
LongFunction<V> nth = idx -> list.get((int) idx);
return Lists.from(
list.size(),
nth,
idx -> idx == 0 ? list.iterator() : Iterators.range(idx, list.size(), nth)
);
}
|
@return a view of the Java list as an IList
|
from
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/Lists.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/Lists.java
|
MIT
|
public static <V> IList<V> from(long size, LongFunction<V> elementFn) {
return from(size, elementFn, idx -> Iterators.range(idx, size, elementFn));
}
|
Creates a list which repeatedly uses the element function for each lookup.
@param size the size of the list
@param elementFn a function which returns the list for the given element
@return a list
|
from
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/Lists.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/Lists.java
|
MIT
|
public static <V> IList<V> from(long size, LongFunction<V> elementFn, LongFunction<Iterator<V>> iteratorFn) {
return new IList.Mixin<V>() {
@Override
public V nth(long idx) {
if (idx < 0 || size <= idx) {
throw new IndexOutOfBoundsException(idx + " must be within [0," + size + ")");
}
return elementFn.apply(idx);
}
@Override
public IList<V> set(long idx, V value) {
return List.from(this).set(idx, value);
}
@Override
public IList<V> removeFirst() {
return Lists.slice(this, 1, size());
}
@Override
public IList<V> removeLast() {
return Lists.slice(this, 0, size() - 1);
}
@Override
public IList<V> addFirst(V value) {
return Lists.concat(List.of(value), this);
}
@Override
public IList<V> addLast(V value) {
return Lists.concat(this, List.of(value));
}
@Override
public IList<V> linear() {
return List.from(this).linear();
}
@Override
public Iterator<V> iterator(long startIndex) {
return iteratorFn.apply(startIndex);
}
@Override
public long size() {
return size;
}
};
}
|
Creates a list which repeatedly uses the element function for each lookup.
@param size the size of the list
@param elementFn a function which returns the list for the given element
@param iteratorFn a function which generates an iterator for the list
@return a list
|
from
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/Lists.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/Lists.java
|
MIT
|
@Override
public V nth(long idx) {
if (idx < 0 || size <= idx) {
throw new IndexOutOfBoundsException(idx + " must be within [0," + size + ")");
}
return elementFn.apply(idx);
}
|
Creates a list which repeatedly uses the element function for each lookup.
@param size the size of the list
@param elementFn a function which returns the list for the given element
@param iteratorFn a function which generates an iterator for the list
@return a list
|
nth
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/Lists.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/Lists.java
|
MIT
|
@Override
public IList<V> set(long idx, V value) {
return List.from(this).set(idx, value);
}
|
Creates a list which repeatedly uses the element function for each lookup.
@param size the size of the list
@param elementFn a function which returns the list for the given element
@param iteratorFn a function which generates an iterator for the list
@return a list
|
set
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/Lists.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/Lists.java
|
MIT
|
@Override
public IList<V> removeFirst() {
return Lists.slice(this, 1, size());
}
|
Creates a list which repeatedly uses the element function for each lookup.
@param size the size of the list
@param elementFn a function which returns the list for the given element
@param iteratorFn a function which generates an iterator for the list
@return a list
|
removeFirst
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/Lists.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/Lists.java
|
MIT
|
@Override
public IList<V> removeLast() {
return Lists.slice(this, 0, size() - 1);
}
|
Creates a list which repeatedly uses the element function for each lookup.
@param size the size of the list
@param elementFn a function which returns the list for the given element
@param iteratorFn a function which generates an iterator for the list
@return a list
|
removeLast
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/Lists.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/Lists.java
|
MIT
|
@Override
public IList<V> addFirst(V value) {
return Lists.concat(List.of(value), this);
}
|
Creates a list which repeatedly uses the element function for each lookup.
@param size the size of the list
@param elementFn a function which returns the list for the given element
@param iteratorFn a function which generates an iterator for the list
@return a list
|
addFirst
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/Lists.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/Lists.java
|
MIT
|
@Override
public IList<V> addLast(V value) {
return Lists.concat(this, List.of(value));
}
|
Creates a list which repeatedly uses the element function for each lookup.
@param size the size of the list
@param elementFn a function which returns the list for the given element
@param iteratorFn a function which generates an iterator for the list
@return a list
|
addLast
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/Lists.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/Lists.java
|
MIT
|
@Override
public IList<V> linear() {
return List.from(this).linear();
}
|
Creates a list which repeatedly uses the element function for each lookup.
@param size the size of the list
@param elementFn a function which returns the list for the given element
@param iteratorFn a function which generates an iterator for the list
@return a list
|
linear
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/Lists.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/Lists.java
|
MIT
|
@Override
public Iterator<V> iterator(long startIndex) {
return iteratorFn.apply(startIndex);
}
|
Creates a list which repeatedly uses the element function for each lookup.
@param size the size of the list
@param elementFn a function which returns the list for the given element
@param iteratorFn a function which generates an iterator for the list
@return a list
|
iterator
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/Lists.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/Lists.java
|
MIT
|
@Override
public long size() {
return size;
}
|
Creates a list which repeatedly uses the element function for each lookup.
@param size the size of the list
@param elementFn a function which returns the list for the given element
@param iteratorFn a function which generates an iterator for the list
@return a list
|
size
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/Lists.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/Lists.java
|
MIT
|
public static <V> Collector<V, LinearList<V>, LinearList<V>> linearCollector() {
return linearCollector(8);
}
|
@return a Java stream collector which can be used to construct a LinearList
|
linearCollector
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/Lists.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/Lists.java
|
MIT
|
public static <V> Collector<V, LinearList<V>, LinearList<V>> linearCollector(int capacity) {
return new Collector<V, LinearList<V>, LinearList<V>>() {
@Override
public Supplier<LinearList<V>> supplier() {
return () -> new LinearList(capacity);
}
@Override
public BiConsumer<LinearList<V>, V> accumulator() {
return LinearList::addLast;
}
@Override
public BinaryOperator<LinearList<V>> combiner() {
return LinearList::linearConcat;
}
@Override
public Function<LinearList<V>, LinearList<V>> finisher() {
return x -> x;
}
@Override
public Set<Characteristics> characteristics() {
return EnumSet.of(Characteristics.IDENTITY_FINISH);
}
};
}
|
@param capacity the initial capacity of the list which collects values.
@return a Java stream collector which can be used to construct a LinearList
|
linearCollector
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/Lists.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/Lists.java
|
MIT
|
@Override
public Supplier<LinearList<V>> supplier() {
return () -> new LinearList(capacity);
}
|
@param capacity the initial capacity of the list which collects values.
@return a Java stream collector which can be used to construct a LinearList
|
supplier
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/Lists.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/Lists.java
|
MIT
|
@Override
public BiConsumer<LinearList<V>, V> accumulator() {
return LinearList::addLast;
}
|
@param capacity the initial capacity of the list which collects values.
@return a Java stream collector which can be used to construct a LinearList
|
accumulator
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/Lists.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/Lists.java
|
MIT
|
@Override
public BinaryOperator<LinearList<V>> combiner() {
return LinearList::linearConcat;
}
|
@param capacity the initial capacity of the list which collects values.
@return a Java stream collector which can be used to construct a LinearList
|
combiner
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/Lists.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/Lists.java
|
MIT
|
@Override
public Function<LinearList<V>, LinearList<V>> finisher() {
return x -> x;
}
|
@param capacity the initial capacity of the list which collects values.
@return a Java stream collector which can be used to construct a LinearList
|
finisher
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/Lists.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/Lists.java
|
MIT
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.