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 |
|---|---|---|---|---|---|---|---|
private boolean isNode(int mask) {
return (nodemap & mask) != 0;
}
|
This is an implementation based on the one described in https://michael.steindorfer.name/publications/oopsla15.pdf.
<p>
It adds in support for transient/linear updates, and allows for empty buffer space between the nodes and nodes
to minimize allocations when a node is repeatedly updated in-place.
@author ztellman
|
isNode
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/nodes/MapNodes.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/nodes/MapNodes.java
|
MIT
|
public boolean contains(int hash, K key, BiPredicate<K, K> equals) {
return get(hash, key, equals, DEFAULT_VALUE) != DEFAULT_VALUE;
}
|
This is an implementation based on the one described in https://michael.steindorfer.name/publications/oopsla15.pdf.
<p>
It adds in support for transient/linear updates, and allows for empty buffer space between the nodes and nodes
to minimize allocations when a node is repeatedly updated in-place.
@author ztellman
|
contains
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/nodes/MapNodes.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/nodes/MapNodes.java
|
MIT
|
public Object get(int hash, K key, BiPredicate<K, K> equals, Object defaultValue) {
if (hash != this.hash) {
return defaultValue;
}
int idx = indexOf(key, equals);
if (idx < 0) {
return defaultValue;
} else {
return entries[idx + 1];
}
}
|
This is an implementation based on the one described in https://michael.steindorfer.name/publications/oopsla15.pdf.
<p>
It adds in support for transient/linear updates, and allows for empty buffer space between the nodes and nodes
to minimize allocations when a node is repeatedly updated in-place.
@author ztellman
|
get
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/nodes/MapNodes.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/nodes/MapNodes.java
|
MIT
|
@Override
public int hash(int idx) {
return hash;
}
|
This is an implementation based on the one described in https://michael.steindorfer.name/publications/oopsla15.pdf.
<p>
It adds in support for transient/linear updates, and allows for empty buffer space between the nodes and nodes
to minimize allocations when a node is repeatedly updated in-place.
@author ztellman
|
hash
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/nodes/MapNodes.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/nodes/MapNodes.java
|
MIT
|
@Override
public IEntry<K, V> nth(long idx) {
int i = (int) idx << 1;
return IEntry.of((K) entries[i], (V) entries[i + 1]);
}
|
This is an implementation based on the one described in https://michael.steindorfer.name/publications/oopsla15.pdf.
<p>
It adds in support for transient/linear updates, and allows for empty buffer space between the nodes and nodes
to minimize allocations when a node is repeatedly updated in-place.
@author ztellman
|
nth
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/nodes/MapNodes.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/nodes/MapNodes.java
|
MIT
|
@Override
public long indexOf(int shift, int hash, K key, BiPredicate<K, K> equals) {
if (this.hash == hash) {
for (int i = 0; i < entries.length; i += 2) {
if (equals.test(key, (K) entries[i])) {
return i >> 1;
}
}
}
return -1;
}
|
This is an implementation based on the one described in https://michael.steindorfer.name/publications/oopsla15.pdf.
<p>
It adds in support for transient/linear updates, and allows for empty buffer space between the nodes and nodes
to minimize allocations when a node is repeatedly updated in-place.
@author ztellman
|
indexOf
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/nodes/MapNodes.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/nodes/MapNodes.java
|
MIT
|
@Override
public INode<K, V> put(
int shift,
Object editor,
int hash,
K key,
V value,
BiPredicate<K, K> equals,
BinaryOperator<V> merge
) {
if (hash != this.hash) {
return new Node<K, V>(editor)
.putNode(hashMask(this.hash, shift), this)
.put(shift, editor, hash, key, value, equals, merge);
} else {
int idx = indexOf(key, equals);
return idx < 0
? new Collision<K, V>(hash, ArrayVector.append(entries, key, value))
: new Collision<K, V>(hash, ArrayVector.set(entries, idx, key, merge.apply((V) entries[idx + 1], value)));
}
}
|
This is an implementation based on the one described in https://michael.steindorfer.name/publications/oopsla15.pdf.
<p>
It adds in support for transient/linear updates, and allows for empty buffer space between the nodes and nodes
to minimize allocations when a node is repeatedly updated in-place.
@author ztellman
|
put
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/nodes/MapNodes.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/nodes/MapNodes.java
|
MIT
|
@Override
public INode<K, V> remove(int shift, Object editor, int hash, K key, BiPredicate<K, K> equals) {
if (hash != this.hash) {
return this;
} else {
int idx = indexOf(key, equals);
return idx < 0 ? this : new Collision<K, V>(hash, ArrayVector.remove(entries, idx, 2));
}
}
|
This is an implementation based on the one described in https://michael.steindorfer.name/publications/oopsla15.pdf.
<p>
It adds in support for transient/linear updates, and allows for empty buffer space between the nodes and nodes
to minimize allocations when a node is repeatedly updated in-place.
@author ztellman
|
remove
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/nodes/MapNodes.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/nodes/MapNodes.java
|
MIT
|
public <U> Collision<K, U> mapVals(Object editor, BiFunction<K, V, U> f) {
Collision c = new Collision(hash, entries.clone());
for (int i = 0; i < entries.length; i += 2) {
c.entries[i + 1] = f.apply((K) c.entries[i], (V) c.entries[i + 1]);
}
return c;
}
|
This is an implementation based on the one described in https://michael.steindorfer.name/publications/oopsla15.pdf.
<p>
It adds in support for transient/linear updates, and allows for empty buffer space between the nodes and nodes
to minimize allocations when a node is repeatedly updated in-place.
@author ztellman
|
mapVals
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/nodes/MapNodes.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/nodes/MapNodes.java
|
MIT
|
public Iterable<IEntry<K, V>> entries() {
return () ->
Iterators.range(
entries.length >> 1,
i -> {
int idx = (int) (i << 1);
return IEntry.of((K) entries[idx], (V) entries[idx + 1]);
}
);
}
|
This is an implementation based on the one described in https://michael.steindorfer.name/publications/oopsla15.pdf.
<p>
It adds in support for transient/linear updates, and allows for empty buffer space between the nodes and nodes
to minimize allocations when a node is repeatedly updated in-place.
@author ztellman
|
entries
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/nodes/MapNodes.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/nodes/MapNodes.java
|
MIT
|
public long size() {
return entries.length >> 1;
}
|
This is an implementation based on the one described in https://michael.steindorfer.name/publications/oopsla15.pdf.
<p>
It adds in support for transient/linear updates, and allows for empty buffer space between the nodes and nodes
to minimize allocations when a node is repeatedly updated in-place.
@author ztellman
|
size
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/nodes/MapNodes.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/nodes/MapNodes.java
|
MIT
|
@Override
public boolean equals(INode<K, V> o, BiPredicate<K, K> keyEquals, BiPredicate<V, V> valEquals) {
if (this == o) {
return true;
}
if (o instanceof Collision) {
Collision<K, V> c = (Collision<K, V>) o;
if (c.size() == size()) {
Iterator<IEntry<K, V>> it = entries().iterator();
while (it.hasNext()) {
IEntry<K, V> e = it.next();
int idx = c.indexOf(e.key(), keyEquals);
if (idx < 0 || !valEquals.test(e.value(), (V) entries[idx + 1])) {
return false;
}
}
return true;
}
}
return false;
}
|
This is an implementation based on the one described in https://michael.steindorfer.name/publications/oopsla15.pdf.
<p>
It adds in support for transient/linear updates, and allows for empty buffer space between the nodes and nodes
to minimize allocations when a node is repeatedly updated in-place.
@author ztellman
|
equals
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/nodes/MapNodes.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/nodes/MapNodes.java
|
MIT
|
private int indexOf(K key, BiPredicate<K, K> equals) {
for (int i = 0; i < entries.length; i += 2) {
if (equals.test(key, (K) entries[i])) {
return i;
}
}
return -1;
}
|
This is an implementation based on the one described in https://michael.steindorfer.name/publications/oopsla15.pdf.
<p>
It adds in support for transient/linear updates, and allows for empty buffer space between the nodes and nodes
to minimize allocations when a node is repeatedly updated in-place.
@author ztellman
|
indexOf
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/nodes/MapNodes.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/nodes/MapNodes.java
|
MIT
|
private static int hashMask(int hash, int shift) {
return 1 << ((hash >>> shift) & 31);
}
|
This is an implementation based on the one described in https://michael.steindorfer.name/publications/oopsla15.pdf.
<p>
It adds in support for transient/linear updates, and allows for empty buffer space between the nodes and nodes
to minimize allocations when a node is repeatedly updated in-place.
@author ztellman
|
hashMask
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/nodes/MapNodes.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/nodes/MapNodes.java
|
MIT
|
public static <K, V> boolean contains(Node<K, V> node, int shift, int hash, K key, BiPredicate<K, K> equals) {
return get(node, shift, hash, key, equals, DEFAULT_VALUE) != DEFAULT_VALUE;
}
|
This is an implementation based on the one described in https://michael.steindorfer.name/publications/oopsla15.pdf.
<p>
It adds in support for transient/linear updates, and allows for empty buffer space between the nodes and nodes
to minimize allocations when a node is repeatedly updated in-place.
@author ztellman
|
contains
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/nodes/MapNodes.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/nodes/MapNodes.java
|
MIT
|
public static <K, V> Object get(
Node<K, V> node,
int shift,
int hash,
K key,
BiPredicate<K, K> equals,
Object defaultValue
) {
Object currNode = node;
while (!(currNode instanceof Collision)) {
Node<K, V> n = (Node<K, V>) currNode;
int mask = hashMask(hash, shift);
// there's a potential matching entry
if (n.isEntry(mask)) {
int idx = n.entryIndex(mask) << 1;
return /*n.hashes[idx] == hash &&*/ equals.test(key, (K) n.content[idx])
? n.content[idx + 1]
: defaultValue;
// we must go deeper
} else if (n.isNode(mask)) {
currNode = n.node(mask);
shift += SHIFT_INCREMENT;
// no such thing
} else {
return defaultValue;
}
}
Collision<K, V> c = (Collision<K, V>) currNode;
return c.get(hash, key, equals, defaultValue);
}
|
This is an implementation based on the one described in https://michael.steindorfer.name/publications/oopsla15.pdf.
<p>
It adds in support for transient/linear updates, and allows for empty buffer space between the nodes and nodes
to minimize allocations when a node is repeatedly updated in-place.
@author ztellman
|
get
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/nodes/MapNodes.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/nodes/MapNodes.java
|
MIT
|
public static <K, V> INode<K, V> mergeNodes(
int shift,
Object editor,
INode<K, V> a,
INode<K, V> b,
BiPredicate<K, K> equals,
BinaryOperator<V> merge
) {
Collision<K, V> ca, cb;
Node<K, V> na, nb;
// Node / Node
if (a instanceof Node && b instanceof Node) {
return merge(shift, editor, (Node<K, V>) a, (Node<K, V>) b, equals, merge);
// Node / Collision
} else if (a instanceof Node && b instanceof Collision) {
na = (Node<K, V>) a;
cb = (Collision<K, V>) b;
for (IEntry<K, V> e : cb.entries()) {
na = na.put(shift, editor, cb.hash, e.key(), e.value(), equals, merge);
}
return na;
// Collision / Node
} else if (a instanceof Collision && b instanceof Node) {
BinaryOperator<V> inverted = (x, y) -> merge.apply(y, x);
ca = (Collision<K, V>) a;
nb = (Node<K, V>) b;
for (IEntry<K, V> e : ca.entries()) {
nb = nb.put(shift, editor, ca.hash, e.key(), e.value(), equals, inverted);
}
return nb;
// Collision / Collision
} else {
cb = (Collision<K, V>) b;
for (IEntry<K, V> e : cb.entries()) {
a = a.put(shift, editor, cb.hash, e.key(), e.value(), equals, merge);
}
return a;
}
}
|
This is an implementation based on the one described in https://michael.steindorfer.name/publications/oopsla15.pdf.
<p>
It adds in support for transient/linear updates, and allows for empty buffer space between the nodes and nodes
to minimize allocations when a node is repeatedly updated in-place.
@author ztellman
|
mergeNodes
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/nodes/MapNodes.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/nodes/MapNodes.java
|
MIT
|
public static <K, V> Node<K, V> merge(
int shift,
Object editor,
Node<K, V> a,
Node<K, V> b,
BiPredicate<K, K> equals,
BinaryOperator<V> merge
) {
Node<K, V> result = new Node<K, V>(editor);
PrimitiveIterator.OfInt masks = Util.masks(a.datamap | a.nodemap | b.datamap | b.nodemap);
while (masks.hasNext()) {
int mask = masks.nextInt();
int state = mergeState(mask, a.nodemap, a.datamap, b.nodemap, b.datamap);
int idx;
switch (state) {
case NODE_NONE:
case NONE_NODE:
result = transferNode(mask, state == NODE_NONE ? a : b, result);
break;
case ENTRY_NONE:
case NONE_ENTRY:
result = transferEntry(mask, state == ENTRY_NONE ? a : b, result);
break;
case ENTRY_ENTRY:
result = transferEntry(mask, a, result);
idx = b.entryIndex(mask);
result = (Node<K, V>) result.put(
shift,
editor,
b.hash(idx),
(K) b.content[idx << 1],
(V) b.content[(idx << 1) + 1],
equals,
merge
);
break;
case NODE_NODE:
result = result.putNode(mask, mergeNodes(shift + 5, editor, a.node(mask), b.node(mask), equals, merge));
break;
case NODE_ENTRY:
idx = b.entryIndex(mask);
result = (Node<K, V>) result
.putNode(mask, a.node(mask))
.put(shift, editor, b.hash(idx), (K) b.content[idx << 1], (V) b.content[(idx << 1) + 1], equals, merge);
break;
case ENTRY_NODE:
idx = a.entryIndex(mask);
result = (Node<K, V>) result
.putNode(mask, b.node(mask))
.put(
shift,
editor,
a.hash(idx),
(K) a.content[idx << 1],
(V) a.content[(idx << 1) + 1],
equals,
(x, y) -> merge.apply(y, x)
);
break;
case NONE_NONE:
break;
}
}
return result;
}
|
This is an implementation based on the one described in https://michael.steindorfer.name/publications/oopsla15.pdf.
<p>
It adds in support for transient/linear updates, and allows for empty buffer space between the nodes and nodes
to minimize allocations when a node is repeatedly updated in-place.
@author ztellman
|
merge
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/nodes/MapNodes.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/nodes/MapNodes.java
|
MIT
|
public static <K, V> INode<K, V> diffNodes(
int shift,
Object editor,
INode<K, V> a,
INode<K, V> b,
BiPredicate<K, K> equals
) {
Collision<K, V> ca, cb;
Node<K, V> na, nb;
// Node / Node
if (a instanceof Node && b instanceof Node) {
return difference(shift, editor, (Node<K, V>) a, (Node<K, V>) b, equals);
// Node / Collision
} else if (a instanceof Node && b instanceof Collision) {
cb = (Collision<K, V>) b;
for (IEntry<K, V> e : cb.entries()) {
a = a.remove(shift, editor, cb.hash, e.key(), equals);
}
return a.size() > 0 ? a : null;
// Collision / Node
} else if (a instanceof Collision && b instanceof Node) {
ca = (Collision<K, V>) a;
nb = (Node<K, V>) b;
for (IEntry<K, V> e : ca.entries()) {
if (get(nb, shift, ca.hash, e.key(), equals, DEFAULT_VALUE) != DEFAULT_VALUE) {
ca = (Collision<K, V>) ca.remove(shift, editor, ca.hash, e.key(), equals);
}
}
return ca.size() > 0 ? ca : null;
// Collision / Collision
} else {
ca = (Collision<K, V>) a;
cb = (Collision<K, V>) b;
if (ca.hash == cb.hash) {
for (IEntry<K, V> e : cb.entries()) {
ca = (Collision<K, V>) ca.remove(shift, editor, ca.hash, e.key(), equals);
}
}
return ca.size() > 0 ? ca : null;
}
}
|
This is an implementation based on the one described in https://michael.steindorfer.name/publications/oopsla15.pdf.
<p>
It adds in support for transient/linear updates, and allows for empty buffer space between the nodes and nodes
to minimize allocations when a node is repeatedly updated in-place.
@author ztellman
|
diffNodes
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/nodes/MapNodes.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/nodes/MapNodes.java
|
MIT
|
public static <K, V> Node<K, V> difference(
int shift,
Object editor,
Node<K, V> a,
Node<K, V> b,
BiPredicate<K, K> equals
) {
Node<K, V> result = new Node<K, V>(editor);
INode<K, V> n;
int idx;
PrimitiveIterator.OfInt masks = Util.masks(a.nodemap | a.datamap);
while (masks.hasNext()) {
int mask = masks.nextInt();
int state = mergeState(mask, a.nodemap, a.datamap, b.nodemap, b.datamap);
switch (state) {
case NODE_NONE:
result = transferNode(mask, a, result);
break;
case ENTRY_NONE:
result = transferEntry(mask, a, result);
break;
case ENTRY_ENTRY:
int ia = a.entryIndex(mask);
int ib = b.entryIndex(mask);
if (b.hashes[ib] != a.hashes[ia] || !equals.test((K) b.content[ib << 1], (K) a.content[ia << 1])) {
result = transferEntry(mask, a, result);
}
break;
case NODE_NODE:
n = diffNodes(shift + 5, editor, a.node(mask), b.node(mask), equals);
if (n != null) {
result = result.putNode(mask, n);
}
break;
case NODE_ENTRY:
idx = b.entryIndex(mask);
n = a.node(mask).remove(shift + 5, editor, b.hashes[idx], (K) b.content[idx << 1], equals);
if (n.size() > 0) {
result = result.putNode(mask, n);
}
break;
case ENTRY_NODE:
idx = a.entryIndex(mask);
if (get(b, shift, a.hashes[idx], (K) a.content[idx << 1], equals, DEFAULT_VALUE) == DEFAULT_VALUE) {
result = transferEntry(mask, a, result);
}
break;
default:
throw new IllegalStateException();
}
}
return result.size() > 0 ? result : null;
}
|
This is an implementation based on the one described in https://michael.steindorfer.name/publications/oopsla15.pdf.
<p>
It adds in support for transient/linear updates, and allows for empty buffer space between the nodes and nodes
to minimize allocations when a node is repeatedly updated in-place.
@author ztellman
|
difference
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/nodes/MapNodes.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/nodes/MapNodes.java
|
MIT
|
public static <K, V> INode<K, V> intersectNodes(
int shift,
Object editor,
INode<K, V> a,
INode<K, V> b,
BiPredicate<K, K> equals
) {
Collision<K, V> ca, cb;
Node<K, V> na, nb;
// Node / Node
if (a instanceof Node && b instanceof Node) {
return intersection(shift, editor, (Node<K, V>) a, (Node<K, V>) b, equals);
// Node / Collision
} else if (a instanceof Node && b instanceof Collision) {
cb = (Collision<K, V>) b;
na = (Node<K, V>) a;
Collision<K, V> result = new Collision<K, V>(cb.hash, new Object[0]);
for (IEntry<K, V> e : b.entries()) {
Object val = get(na, shift, cb.hash, e.key(), equals, DEFAULT_VALUE);
if (val != DEFAULT_VALUE) {
result = (Collision<K, V>) result.put(shift, editor, cb.hash, e.key(), (V) val, equals, null);
}
}
return result.size() > 0 ? result : null;
// Collision / Node
} else if (a instanceof Collision && b instanceof Node) {
ca = (Collision<K, V>) a;
nb = (Node<K, V>) b;
for (IEntry<K, V> e : ca.entries()) {
if (!contains(nb, shift, ca.hash, e.key(), equals)) {
ca = (Collision<K, V>) ca.remove(shift, editor, ca.hash, e.key(), equals);
}
}
return ca.size() > 0 ? ca : null;
// Collision / Collision
} else {
ca = (Collision<K, V>) a;
cb = (Collision<K, V>) b;
if (ca.hash != cb.hash) {
return null;
}
for (IEntry<K, V> e : ca.entries()) {
if (!cb.contains(ca.hash, e.key(), equals)) {
ca = (Collision<K, V>) ca.remove(shift, editor, ca.hash, e.key(), equals);
}
}
return ca.size() > 0 ? ca : null;
}
}
|
This is an implementation based on the one described in https://michael.steindorfer.name/publications/oopsla15.pdf.
<p>
It adds in support for transient/linear updates, and allows for empty buffer space between the nodes and nodes
to minimize allocations when a node is repeatedly updated in-place.
@author ztellman
|
intersectNodes
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/nodes/MapNodes.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/nodes/MapNodes.java
|
MIT
|
public static <K, V> Node<K, V> intersection(
int shift,
Object editor,
Node<K, V> a,
Node<K, V> b,
BiPredicate<K, K> equals
) {
Node<K, V> result = new Node<K, V>(editor);
PrimitiveIterator.OfInt masks = Util.masks((a.nodemap | a.datamap) & (b.nodemap | b.datamap));
while (masks.hasNext()) {
int mask = masks.nextInt();
int state = mergeState(mask, a.nodemap, a.datamap, b.nodemap, b.datamap);
int idx, ia, ib;
switch (state) {
case ENTRY_ENTRY:
ia = a.entryIndex(mask);
ib = b.entryIndex(mask);
if (b.hashes[ib] == a.hashes[ia] && equals.test((K) b.content[ib << 1], (K) a.content[ia << 1])) {
result = transferEntry(mask, a, result);
}
break;
case NODE_NODE:
INode<K, V> n = intersectNodes(shift + 5, editor, a.node(mask), b.node(mask), equals);
if (n != null) {
result = result.putNode(mask, n);
}
break;
case NODE_ENTRY:
idx = b.entryIndex(mask);
int hash = b.hashes[idx];
K key = (K) b.content[idx << 1];
Object val = get(a, shift, hash, key, equals, DEFAULT_VALUE);
if (val != DEFAULT_VALUE) {
result = result.put(shift, editor, hash, key, (V) val, equals, null);
}
break;
case ENTRY_NODE:
idx = a.entryIndex(mask);
if (get(b, shift, a.hashes[idx], (K) a.content[idx << 1], equals, DEFAULT_VALUE) != DEFAULT_VALUE) {
result = transferEntry(mask, a, result);
}
break;
default:
throw new IllegalStateException();
}
}
return result.size() > 0 ? result : null;
}
|
This is an implementation based on the one described in https://michael.steindorfer.name/publications/oopsla15.pdf.
<p>
It adds in support for transient/linear updates, and allows for empty buffer space between the nodes and nodes
to minimize allocations when a node is repeatedly updated in-place.
@author ztellman
|
intersection
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/nodes/MapNodes.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/nodes/MapNodes.java
|
MIT
|
public static <K, V> IList<Node<K, V>> split(Object editor, Node<K, V> node, int targetSize) {
IList<Node<K, V>> result = new LinearList<>();
if ((node.size() >> 1) < targetSize) {
result.addLast(node);
} else {
Node<K, V> acc = new Node<>(editor);
PrimitiveIterator.OfInt masks = Util.masks(node.datamap | node.nodemap);
while (masks.hasNext()) {
int mask = masks.nextInt();
if (acc.size() >= targetSize) {
result.addLast(acc);
acc = new Node<>(editor);
}
if (node.isEntry(mask)) {
acc = transferEntry(mask, node, acc);
} else if (node.isNode(mask)) {
INode<K, V> child = node.node(mask);
if (child instanceof Node && child.size() >= (targetSize << 1)) {
split(editor, (Node<K, V>) child, targetSize).stream()
.map(n -> new Node<K, V>(editor).putNode(mask, n))
.forEach(result::addLast);
} else {
acc = acc.putNode(mask, child);
}
}
}
if (acc.size() > 0) {
result.addLast(acc);
}
}
return result;
}
|
This is an implementation based on the one described in https://michael.steindorfer.name/publications/oopsla15.pdf.
<p>
It adds in support for transient/linear updates, and allows for empty buffer space between the nodes and nodes
to minimize allocations when a node is repeatedly updated in-place.
@author ztellman
|
split
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/nodes/MapNodes.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/nodes/MapNodes.java
|
MIT
|
private static <K, V> Node<K, V> transferNode(int mask, Node<K, V> src, Node<K, V> dst) {
return dst.putNode(mask, src.node(mask));
}
|
This is an implementation based on the one described in https://michael.steindorfer.name/publications/oopsla15.pdf.
<p>
It adds in support for transient/linear updates, and allows for empty buffer space between the nodes and nodes
to minimize allocations when a node is repeatedly updated in-place.
@author ztellman
|
transferNode
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/nodes/MapNodes.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/nodes/MapNodes.java
|
MIT
|
private static <K, V> Node<K, V> transferEntry(int mask, Node<K, V> src, Node<K, V> dst) {
int idx = src.entryIndex(mask);
return dst.putEntry(mask, src.hashes[idx], (K) src.content[idx << 1], (V) src.content[(idx << 1) + 1]);
}
|
This is an implementation based on the one described in https://michael.steindorfer.name/publications/oopsla15.pdf.
<p>
It adds in support for transient/linear updates, and allows for empty buffer space between the nodes and nodes
to minimize allocations when a node is repeatedly updated in-place.
@author ztellman
|
transferEntry
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/nodes/MapNodes.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/nodes/MapNodes.java
|
MIT
|
public static long[] create() {
return BitVector.create(0);
}
|
@return a bit-int set, with an implied size of 0.
|
create
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/utils/BitIntSet.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/utils/BitIntSet.java
|
MIT
|
public static long get(long[] set, int bitsPerElement, int idx) {
return BitVector.get(set, idx * bitsPerElement, bitsPerElement);
}
|
@param set the bit-int set
@param bitsPerElement the bits per element
@param idx the table
@return the rowValue stored at the given table
|
get
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/utils/BitIntSet.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/utils/BitIntSet.java
|
MIT
|
public static int indexOf(long[] set, int bitsPerElement, int size, long val) {
int low = 0;
int high = size - 1;
int mid = 0;
while (low <= high) {
mid = (low + high) >>> 1;
long curr = get(set, bitsPerElement, mid);
if (curr < val) {
low = mid + 1;
} else if (curr > val) {
high = mid - 1;
} else {
return mid;
}
}
return -(low + 1);
}
|
Performs a binary search for the given rowValue.
@param set the bit-int set
@param bitsPerElement the bits per element
@param size the number of elements in the set
@param val the rowValue to search for
@return If idx >= 0, the actual table of the rowValue. Otherwise, the return rowValue represents the table
where the
rowValue would be inserted, where -1 represents the 0th element, -2 represents the 1st element, and so on.
|
indexOf
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/utils/BitIntSet.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/utils/BitIntSet.java
|
MIT
|
public static long[] add(long[] set, int bitsPerElement, int size, long val) {
int idx = indexOf(set, bitsPerElement, size, val);
if (idx < 0) {
idx = -idx - 1;
return BitVector.insert(set, (bitsPerElement * size), val, (bitsPerElement * idx), bitsPerElement);
} else {
return set;
}
}
|
@param set the bit-int set
@param bitsPerElement the bits per element
@param size the number of elements in the set
@param val the rowValue to add
@return an updated long[] array if the rowValue is not already in the set, otherwise 'set' is returned unchanged
|
add
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/utils/BitIntSet.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/utils/BitIntSet.java
|
MIT
|
public static long[] remove(long[] set, int bitsPerElement, int size, long val) {
int idx = indexOf(set, bitsPerElement, size, val);
if (idx < 0) {
return set;
} else {
return BitVector.remove(set, (bitsPerElement * size), (bitsPerElement * idx), bitsPerElement);
}
}
|
@param set the bit-int set
@param bitsPerElement the bits per element
@param size the number of elements in the set
@param val the rowValue to remove
@return an updated long[] array if the rowValue was in the set, otherwise 'set' is returned unchanged
|
remove
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/utils/BitIntSet.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/utils/BitIntSet.java
|
MIT
|
public static int bitOffset(long n) {
return deBruijnIndex[0xFF & (int) ((n * 0x022fdd63cc95386dL) >>> 58)];
}
|
@param n a number, which must be a power of two
@return the offset of the bit
|
bitOffset
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/utils/Bits.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/utils/Bits.java
|
MIT
|
public static long lowestBit(long n) {
return n & -n;
}
|
@param n a number
@return the same number, with all but the lowest bit zeroed out
|
lowestBit
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/utils/Bits.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/utils/Bits.java
|
MIT
|
public static int lowestBit(int n) {
return n & -n;
}
|
@param n a number
@return the same number, with all but the lowest bit zeroed out
|
lowestBit
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/utils/Bits.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/utils/Bits.java
|
MIT
|
public static long highestBit(long n) {
return Long.highestOneBit(n);
}
|
@param n a number
@return the same number, with all but the highest bit zeroed out
|
highestBit
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/utils/Bits.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/utils/Bits.java
|
MIT
|
public static int highestBit(int n) {
return Integer.highestOneBit(n);
}
|
@param n a number
@return the same number, with all but the highest bit zeroed out
|
highestBit
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/utils/Bits.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/utils/Bits.java
|
MIT
|
public static int log2Floor(long n) {
return bitOffset(highestBit(n));
}
|
@param n a number
@return the log2 of that value, rounded down
|
log2Floor
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/utils/Bits.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/utils/Bits.java
|
MIT
|
public static int log2Ceil(long n) {
int log2 = log2Floor(n);
return isPowerOfTwo(n) ? log2 : log2 + 1;
}
|
@param n a number
@return the log2 of the value, rounded up
|
log2Ceil
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/utils/Bits.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/utils/Bits.java
|
MIT
|
public static boolean test(int n, int offset) {
return (n & (1 << offset)) != 0;
}
|
@param n a number
@param offset the offset of the bit being tested
@return true if the bit is 1, false otherwise
|
test
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/utils/Bits.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/utils/Bits.java
|
MIT
|
public static boolean test(long n, int offset) {
return (n & (1L << offset)) != 0;
}
|
@param n a number
@param offset the offset of the bit being tested
@return true if the bit is 1, false otherwise
|
test
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/utils/Bits.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/utils/Bits.java
|
MIT
|
public static long maskBelow(int bits) {
return (1L << bits) - 1;
}
|
@param bits a bit offset
@return a mask, with all bits below that offset set to one
|
maskBelow
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/utils/Bits.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/utils/Bits.java
|
MIT
|
public static long maskAbove(int bits) {
return -1L & ~maskBelow(bits);
}
|
@param bits a bit offset
@return a mask, with all bits above that offset set to one
|
maskAbove
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/utils/Bits.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/utils/Bits.java
|
MIT
|
public static int branchingBit(long a, long b) {
if (a == b) {
return -1;
} else {
return bitOffset(highestBit(a ^ b));
}
}
|
@return the offset of the highest bit which differs between {@code a} and {@code b}
|
branchingBit
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/utils/Bits.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/utils/Bits.java
|
MIT
|
public static boolean isPowerOfTwo(long n) {
return (n & (n - 1)) == 0;
}
|
@param n a number
@return true, if the number is a power of two
|
isPowerOfTwo
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/utils/Bits.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/utils/Bits.java
|
MIT
|
public static long slice(long n, int start, int end) {
return (n >> start) & maskBelow(end - start);
}
|
@param n a number
@return true, if the number is a power of two
|
slice
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/utils/Bits.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/utils/Bits.java
|
MIT
|
public static long[] create(int length) {
return new long[(Math.max(0, length - 1) >> 6) + 1];
}
|
@param length the bit length of the vector
@return a bit vector which can hold the specified number of bits
|
create
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/utils/BitVector.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/utils/BitVector.java
|
MIT
|
public static long[] clone(long[] vector) {
long[] nVector = new long[vector.length];
System.arraycopy(vector, 0, nVector, 0, vector.length);
return nVector;
}
|
@param length the bit length of the vector
@return a bit vector which can hold the specified number of bits
|
clone
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/utils/BitVector.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/utils/BitVector.java
|
MIT
|
public static boolean test(long[] vector, int bitIndex) {
return (vector[bitIndex >> 6] & (1L << (bitIndex & 63))) != 0;
}
|
@param vector the bit vector
@param bitIndex the bit to be tested
@return true if the bit is 1, false otherwise
|
test
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/utils/BitVector.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/utils/BitVector.java
|
MIT
|
public static long[] interleave(int bitLen, long[] vectors) {
long[] interleaved = create(bitLen * vectors.length);
int offset = (interleaved.length << 6) - 1;
for (int i = 0; i < bitLen; i++) {
long mask = 1L << i;
for (int j = vectors.length - 1; j >= 0; j--) {
long val = (vectors[j] & mask) >>> i;
interleaved[offset >> 6] |= val << (63 - (offset & 63));
offset--;
}
}
return interleaved;
}
|
@param bitLen the number of significant bits in each vector
@param vectors a list of bit-vectors
@return the bit-wise interleaving of the values, starting with the topmost bit of the 0th vector, followed by the
topmost bit of the 1st vector, and downward from there
|
interleave
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/utils/BitVector.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/utils/BitVector.java
|
MIT
|
public static int branchingBit(long[] a, long[] b, int aIdx, int bIdx, int bitOffset, int bitLen) {
long mask = maskAbove(bitOffset & 63);
int branch = Bits.branchingBit(a[aIdx] & mask, b[bIdx] & mask);
if (branch >= 0) {
return branch;
}
aIdx++;
bIdx++;
int branchIdx = 64 - bitOffset;
int len = ((bitLen - (bitOffset + 1)) >> 6) + 1;
for (int i = 0; i < len; i++) {
branch = Bits.branchingBit(a[aIdx + i], b[bIdx + 1]);
if (branch >= 0) {
return branchIdx + branch;
} else {
branchIdx += 64;
}
}
return branchIdx > bitLen ? -1 : branchIdx;
}
|
@param bitLen the number of significant bits in each vector
@param vectors a list of bit-vectors
@return the bit-wise interleaving of the values, starting with the topmost bit of the 0th vector, followed by the
topmost bit of the 1st vector, and downward from there
|
branchingBit
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/utils/BitVector.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/utils/BitVector.java
|
MIT
|
public static long get(long[] vector, int offset, int len) {
int idx = offset >> 6;
int bitIdx = offset & 63;
int truncatedLen = Math.min(len, 64 - bitIdx);
long val = (vector[idx] >>> bitIdx) & maskBelow(truncatedLen);
if (len != truncatedLen) {
val |= (vector[idx + 1] & maskBelow(len - truncatedLen)) << truncatedLen;
}
return val;
}
|
Reads a bit range from the vector, which cannot be longer than 64 bits.
@param vector the bit vector
@param offset the bit offset
@param len the bit length
@return a number representing the bit range
|
get
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/utils/BitVector.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/utils/BitVector.java
|
MIT
|
public static void overwrite(long[] vector, long val, int offset, int len) {
int idx = offset >> 6;
int bitIdx = offset & 63;
int truncatedValLen = Math.min(len, 64 - bitIdx);
vector[idx] &= ~(maskBelow(truncatedValLen) << bitIdx);
vector[idx] |= val << bitIdx;
if (len != truncatedValLen) {
long mask = maskBelow(len - truncatedValLen);
vector[idx + 1] &= ~mask;
vector[idx + 1] |= (val >>> truncatedValLen);
}
}
|
Overwrites a bit range within the vector.
@param vector the bit vector
@param val the rowValue to set
@param offset the offset of the write
@param len the bit length of the rowValue
|
overwrite
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/utils/BitVector.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/utils/BitVector.java
|
MIT
|
public static void overwrite(long[] vector, int bitIdx, boolean flag) {
long mask = (1L << (bitIdx & 63));
if (flag) {
vector[bitIdx >> 6] |= mask;
} else {
vector[bitIdx >> 6] &= ~mask;
}
}
|
Overwrites a bit range within the vector.
@param vector the bit vector
@param val the rowValue to set
@param offset the offset of the write
@param len the bit length of the rowValue
|
overwrite
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/utils/BitVector.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/utils/BitVector.java
|
MIT
|
public static void copy(long[] src, int srcOffset, long[] dst, int dstOffset, int len) {
int srcLimit = srcOffset + len;
while (srcOffset < srcLimit) {
int srcIdx = srcOffset & 63;
int dstIdx = dstOffset & 63;
int srcRemainder = 64 - srcIdx;
int dstRemainder = 64 - dstIdx;
int chunkLen = Math.min(srcRemainder, dstRemainder);
long mask = maskBelow(chunkLen) << srcIdx;
dst[dstOffset >> 6] |= ((src[srcOffset >> 6] & mask) >>> srcIdx) << dstOffset;
srcOffset += chunkLen;
dstOffset += chunkLen;
}
}
|
Copies a bit range from one vector to another.
@param src the source vector
@param srcOffset the bit offset within src
@param dst the destination vector
@param dstOffset the bit offset within dst
@param len the length of the bit range
|
copy
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/utils/BitVector.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/utils/BitVector.java
|
MIT
|
public static long[] interpose(long[] vector, int vectorLen, int offset, int len) {
long[] updated = create(vectorLen + len);
int idx = offset >> 6;
System.arraycopy(vector, 0, updated, 0, idx);
if (idx < vector.length) {
int delta = offset & 63;
updated[idx] |= vector[idx] & maskBelow(delta);
}
copy(vector, offset, updated, offset + len, vectorLen - offset);
return updated;
}
|
Returns a copy of the vector, with an empty bit range inserted at the specified location.
@param vector the bit vector
@param vectorLen the length of the bit vector
@param offset the offset within the bit vector
@param len the length of the empty bit range
@return an updated copy of the vector
|
interpose
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/utils/BitVector.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/utils/BitVector.java
|
MIT
|
public static long[] insert(long[] vector, int vectorLen, long val, int offset, int len) {
long[] updated = interpose(vector, vectorLen, offset, len);
overwrite(updated, val, offset, len);
return updated;
}
|
@param vector the bit vector
@param vectorLen the length of the bit vector
@param val the rowValue to be inserted
@param offset the offset within the bit vector
@param len the bit length of the rowValue
@return an updated copy of the vector
|
insert
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/utils/BitVector.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/utils/BitVector.java
|
MIT
|
public static long[] remove(long[] vector, int vectorLen, int offset, int len) {
long[] updated = create(vectorLen - len);
int idx = offset >> 6;
System.arraycopy(vector, 0, updated, 0, idx);
if (idx < updated.length) {
int delta = offset & 63;
updated[idx] |= vector[idx] & maskBelow(delta);
}
copy(vector, offset + len, updated, offset, vectorLen - (offset + len));
return updated;
}
|
Returns a copy of the vector, with a bit range excised from the specified location.
@param vector the bit vector
@param vectorLen the length of the bit vector
@param offset the offset within the bit vector
@param len the length of the excised bit range
@return an updated copy of the vector
|
remove
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/utils/BitVector.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/utils/BitVector.java
|
MIT
|
public static long doubleToLong(double value) {
long v = Double.doubleToRawLongBits(value);
if (v == NEGATIVE_ZERO) {
return 0;
}
if (value < -0.0) {
v ^= Long.MAX_VALUE;
}
return v;
}
|
Converts a double into a corresponding long that shares the same ordering semantics.
|
doubleToLong
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/utils/Encodings.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/utils/Encodings.java
|
MIT
|
public static double longToDouble(long value) {
if (value < -0.0) {
value ^= Long.MAX_VALUE;
}
return Double.longBitsToDouble(value);
}
|
The inverse operation for {@link #doubleToLong(double)}.
|
longToDouble
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/utils/Encodings.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/utils/Encodings.java
|
MIT
|
public static OfInt filter(OfInt it, IntPredicate f) {
return new OfInt() {
private int next = 0;
private boolean primed = false;
private boolean done = false;
private void prime() {
if (!primed && !done) {
while (it.hasNext()) {
next = it.nextInt();
if (f.test(next)) {
primed = true;
return;
}
}
done = true;
}
}
@Override
public boolean hasNext() {
prime();
return !done;
}
@Override
public int nextInt() {
prime();
if (!primed) {
throw new NoSuchElementException();
}
primed = false;
return next;
}
};
}
|
@param it an iterator
@param f a predicate
@return an iterator which only yields values that satisfy the predicate
|
filter
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/utils/IntIterators.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/utils/IntIterators.java
|
MIT
|
private void prime() {
if (!primed && !done) {
while (it.hasNext()) {
next = it.nextInt();
if (f.test(next)) {
primed = true;
return;
}
}
done = true;
}
}
|
@param it an iterator
@param f a predicate
@return an iterator which only yields values that satisfy the predicate
|
prime
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/utils/IntIterators.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/utils/IntIterators.java
|
MIT
|
@Override
public boolean hasNext() {
prime();
return !done;
}
|
@param it an iterator
@param f a predicate
@return an iterator which only yields values that satisfy the predicate
|
hasNext
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/utils/IntIterators.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/utils/IntIterators.java
|
MIT
|
@Override
public int nextInt() {
prime();
if (!primed) {
throw new NoSuchElementException();
}
primed = false;
return next;
}
|
@param it an iterator
@param f a predicate
@return an iterator which only yields values that satisfy the predicate
|
nextInt
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/utils/IntIterators.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/utils/IntIterators.java
|
MIT
|
public static OfInt map(OfInt it, IntUnaryOperator f) {
return new OfInt() {
@Override
public boolean hasNext() {
return it.hasNext();
}
@Override
public int nextInt() {
return f.applyAsInt(it.nextInt());
}
};
}
|
@param it an iterator
@param f a function which transforms values
@return an iterator which yields the transformed values
|
map
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/utils/IntIterators.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/utils/IntIterators.java
|
MIT
|
@Override
public boolean hasNext() {
return it.hasNext();
}
|
@param it an iterator
@param f a function which transforms values
@return an iterator which yields the transformed values
|
hasNext
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/utils/IntIterators.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/utils/IntIterators.java
|
MIT
|
@Override
public int nextInt() {
return f.applyAsInt(it.nextInt());
}
|
@param it an iterator
@param f a function which transforms values
@return an iterator which yields the transformed values
|
nextInt
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/utils/IntIterators.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/utils/IntIterators.java
|
MIT
|
public static <U> OfInt flatMap(Iterator<U> it, Function<U, OfInt> f) {
return new OfInt() {
OfInt curr = EMPTY;
private void prime() {
while (!curr.hasNext() && it.hasNext()) {
curr = f.apply(it.next());
}
}
@Override
public boolean hasNext() {
prime();
return curr.hasNext();
}
@Override
public int nextInt() {
prime();
return curr.nextInt();
}
};
}
|
@param it an iterator
@param f a function which transforms values into iterators
@return an iterator which yields the concatenation of the iterators
|
flatMap
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/utils/IntIterators.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/utils/IntIterators.java
|
MIT
|
private void prime() {
while (!curr.hasNext() && it.hasNext()) {
curr = f.apply(it.next());
}
}
|
@param it an iterator
@param f a function which transforms values into iterators
@return an iterator which yields the concatenation of the iterators
|
prime
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/utils/IntIterators.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/utils/IntIterators.java
|
MIT
|
@Override
public boolean hasNext() {
prime();
return curr.hasNext();
}
|
@param it an iterator
@param f a function which transforms values into iterators
@return an iterator which yields the concatenation of the iterators
|
hasNext
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/utils/IntIterators.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/utils/IntIterators.java
|
MIT
|
@Override
public int nextInt() {
prime();
return curr.nextInt();
}
|
@param it an iterator
@param f a function which transforms values into iterators
@return an iterator which yields the concatenation of the iterators
|
nextInt
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/utils/IntIterators.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/utils/IntIterators.java
|
MIT
|
public static OfInt range(long min, long max, LongToIntFunction f) {
return new OfInt() {
long i = min;
@Override
public boolean hasNext() {
return i < max;
}
@Override
public int nextInt() {
if (hasNext()) {
return f.applyAsInt(i++);
} else {
throw new NoSuchElementException();
}
}
};
}
|
@param min an inclusive start of the range
@param max an exclusive end of the range
@param f a function which transforms a number in the range into a value
@return an iterator which yields the values returned by {@code f}
|
range
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/utils/IntIterators.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/utils/IntIterators.java
|
MIT
|
@Override
public boolean hasNext() {
return i < max;
}
|
@param min an inclusive start of the range
@param max an exclusive end of the range
@param f a function which transforms a number in the range into a value
@return an iterator which yields the values returned by {@code f}
|
hasNext
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/utils/IntIterators.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/utils/IntIterators.java
|
MIT
|
@Override
public int nextInt() {
if (hasNext()) {
return f.applyAsInt(i++);
} else {
throw new NoSuchElementException();
}
}
|
@param min an inclusive start of the range
@param max an exclusive end of the range
@param f a function which transforms a number in the range into a value
@return an iterator which yields the values returned by {@code f}
|
nextInt
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/utils/IntIterators.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/utils/IntIterators.java
|
MIT
|
public static OfInt range(long max, LongToIntFunction f) {
return range(0, max, f);
}
|
Represents a range implicitly starting at 0.
@param max an exclusive end of the range.
@param f a function which transforms a number in the range into a value.
@return an iterator which yields the values returned by {@code f}
|
range
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/utils/IntIterators.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/utils/IntIterators.java
|
MIT
|
public static IntStream toStream(OfInt it, long estimatedSize) {
return StreamSupport.intStream(Spliterators.spliterator(it, estimatedSize, Spliterator.ORDERED), false);
}
|
Represents a range implicitly starting at 0.
@param max an exclusive end of the range.
@param f a function which transforms a number in the range into a value.
@return an iterator which yields the values returned by {@code f}
|
toStream
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/utils/IntIterators.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/utils/IntIterators.java
|
MIT
|
private void primeIterator() {
while (iterators.size() > 0 && !iterators.first().hasNext()) {
iterators.removeFirst();
}
}
|
A utility class for dynamically appending and prepending iterators to a collection, which itself can be iterated
over.
|
primeIterator
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/utils/Iterators.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/utils/Iterators.java
|
MIT
|
@Override
public boolean hasNext() {
primeIterator();
return iterators.size() > 0 && iterators.first().hasNext();
}
|
A utility class for dynamically appending and prepending iterators to a collection, which itself can be iterated
over.
|
hasNext
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/utils/Iterators.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/utils/Iterators.java
|
MIT
|
@Override
public V next() {
primeIterator();
if (iterators.size() == 0) {
throw new NoSuchElementException();
}
return iterators.first().next();
}
|
A utility class for dynamically appending and prepending iterators to a collection, which itself can be iterated
over.
|
next
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/utils/Iterators.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/utils/Iterators.java
|
MIT
|
public static <V> boolean equals(Iterator<V> a, Iterator<V> b, BiPredicate<V, V> equals) {
while (a.hasNext()) {
if (!b.hasNext()) {
return false;
}
if (!equals.test(a.next(), b.next())) {
return false;
}
}
return !b.hasNext();
}
|
A utility class for dynamically appending and prepending iterators to a collection, which itself can be iterated
over.
|
equals
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/utils/Iterators.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/utils/Iterators.java
|
MIT
|
public static <V> Iterator<V> from(BooleanSupplier hasNext, Supplier<V> next) {
return new Iterator<V>() {
@Override
public boolean hasNext() {
return hasNext.getAsBoolean();
}
@Override
public V next() {
return next.get();
}
};
}
|
A utility class for dynamically appending and prepending iterators to a collection, which itself can be iterated
over.
|
from
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/utils/Iterators.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/utils/Iterators.java
|
MIT
|
@Override
public boolean hasNext() {
return hasNext.getAsBoolean();
}
|
A utility class for dynamically appending and prepending iterators to a collection, which itself can be iterated
over.
|
hasNext
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/utils/Iterators.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/utils/Iterators.java
|
MIT
|
@Override
public V next() {
return next.get();
}
|
A utility class for dynamically appending and prepending iterators to a collection, which itself can be iterated
over.
|
next
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/utils/Iterators.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/utils/Iterators.java
|
MIT
|
public static <V> Iterator<V> onExhaustion(Iterator<V> it, Runnable f) {
return new Iterator<V>() {
@Override
public boolean hasNext() {
return it.hasNext();
}
@Override
public V next() {
V result = it.next();
if (!it.hasNext()) {
f.run();
}
return result;
}
};
}
|
A utility class for dynamically appending and prepending iterators to a collection, which itself can be iterated
over.
|
onExhaustion
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/utils/Iterators.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/utils/Iterators.java
|
MIT
|
@Override
public boolean hasNext() {
return it.hasNext();
}
|
A utility class for dynamically appending and prepending iterators to a collection, which itself can be iterated
over.
|
hasNext
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/utils/Iterators.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/utils/Iterators.java
|
MIT
|
@Override
public V next() {
V result = it.next();
if (!it.hasNext()) {
f.run();
}
return result;
}
|
A utility class for dynamically appending and prepending iterators to a collection, which itself can be iterated
over.
|
next
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/utils/Iterators.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/utils/Iterators.java
|
MIT
|
public static <V> Iterator<V> singleton(V val) {
return new Iterator<V>() {
boolean consumed = false;
@Override
public boolean hasNext() {
return !consumed;
}
@Override
public V next() {
if (!consumed) {
consumed = true;
return val;
} else {
throw new NoSuchElementException();
}
}
};
}
|
A utility class for dynamically appending and prepending iterators to a collection, which itself can be iterated
over.
|
singleton
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/utils/Iterators.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/utils/Iterators.java
|
MIT
|
@Override
public boolean hasNext() {
return !consumed;
}
|
A utility class for dynamically appending and prepending iterators to a collection, which itself can be iterated
over.
|
hasNext
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/utils/Iterators.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/utils/Iterators.java
|
MIT
|
@Override
public V next() {
if (!consumed) {
consumed = true;
return val;
} else {
throw new NoSuchElementException();
}
}
|
A utility class for dynamically appending and prepending iterators to a collection, which itself can be iterated
over.
|
next
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/utils/Iterators.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/utils/Iterators.java
|
MIT
|
public static <V> Iterator<V> filter(Iterator<V> it, Predicate<V> f) {
return new Iterator<V>() {
private Object next = NONE;
private boolean done = false;
private void prime() {
if (next == NONE && !done) {
while (it.hasNext()) {
next = it.next();
if (f.test((V) next)) {
return;
}
}
done = true;
}
}
@Override
public boolean hasNext() {
prime();
return !done;
}
@Override
public V next() {
prime();
if (next == NONE) {
throw new NoSuchElementException();
}
V val = (V) next;
next = NONE;
return val;
}
};
}
|
@param it an iterator
@param f a predicate
@return an iterator which only yields values that satisfy the predicate
|
filter
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/utils/Iterators.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/utils/Iterators.java
|
MIT
|
private void prime() {
if (next == NONE && !done) {
while (it.hasNext()) {
next = it.next();
if (f.test((V) next)) {
return;
}
}
done = true;
}
}
|
@param it an iterator
@param f a predicate
@return an iterator which only yields values that satisfy the predicate
|
prime
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/utils/Iterators.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/utils/Iterators.java
|
MIT
|
@Override
public boolean hasNext() {
prime();
return !done;
}
|
@param it an iterator
@param f a predicate
@return an iterator which only yields values that satisfy the predicate
|
hasNext
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/utils/Iterators.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/utils/Iterators.java
|
MIT
|
@Override
public V next() {
prime();
if (next == NONE) {
throw new NoSuchElementException();
}
V val = (V) next;
next = NONE;
return val;
}
|
@param it an iterator
@param f a predicate
@return an iterator which only yields values that satisfy the predicate
|
next
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/utils/Iterators.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/utils/Iterators.java
|
MIT
|
public static <U, V> Iterator<V> map(Iterator<U> it, Function<U, V> f) {
return from(it::hasNext, () -> f.apply(it.next()));
}
|
@param it an iterator
@param f a function which transforms values
@return an iterator which yields the transformed values
|
map
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/utils/Iterators.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/utils/Iterators.java
|
MIT
|
public static <U, V> Iterator<V> flatMap(Iterator<U> it, Function<U, Iterator<V>> f) {
return new Iterator<V>() {
Iterator<V> curr = EMPTY;
private void prime() {
while (!curr.hasNext() && it.hasNext()) {
curr = f.apply(it.next());
}
}
@Override
public boolean hasNext() {
prime();
return curr.hasNext();
}
@Override
public V next() {
prime();
return curr.next();
}
};
}
|
@param it an iterator
@param f a function which transforms values into iterators
@return an iterator which yields the concatenation of the iterators
|
flatMap
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/utils/Iterators.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/utils/Iterators.java
|
MIT
|
private void prime() {
while (!curr.hasNext() && it.hasNext()) {
curr = f.apply(it.next());
}
}
|
@param it an iterator
@param f a function which transforms values into iterators
@return an iterator which yields the concatenation of the iterators
|
prime
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/utils/Iterators.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/utils/Iterators.java
|
MIT
|
@Override
public boolean hasNext() {
prime();
return curr.hasNext();
}
|
@param it an iterator
@param f a function which transforms values into iterators
@return an iterator which yields the concatenation of the iterators
|
hasNext
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/utils/Iterators.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/utils/Iterators.java
|
MIT
|
@Override
public V next() {
prime();
return curr.next();
}
|
@param it an iterator
@param f a function which transforms values into iterators
@return an iterator which yields the concatenation of the iterators
|
next
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/utils/Iterators.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/utils/Iterators.java
|
MIT
|
public static <V> Iterator<V> range(long min, long max, LongFunction<V> f) {
return new Iterator<V>() {
long i = min;
@Override
public boolean hasNext() {
return i < max;
}
@Override
public V next() {
if (hasNext()) {
return f.apply(i++);
} else {
throw new NoSuchElementException();
}
}
};
}
|
@param min an inclusive start of the range
@param max an exclusive end of the range
@param f a function which transforms a number in the range into a value
@return an iterator which yields the values returned by {@code f}
|
range
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/utils/Iterators.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/utils/Iterators.java
|
MIT
|
@Override
public boolean hasNext() {
return i < max;
}
|
@param min an inclusive start of the range
@param max an exclusive end of the range
@param f a function which transforms a number in the range into a value
@return an iterator which yields the values returned by {@code f}
|
hasNext
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/utils/Iterators.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/utils/Iterators.java
|
MIT
|
@Override
public V next() {
if (hasNext()) {
return f.apply(i++);
} else {
throw new NoSuchElementException();
}
}
|
@param min an inclusive start of the range
@param max an exclusive end of the range
@param f a function which transforms a number in the range into a value
@return an iterator which yields the values returned by {@code f}
|
next
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/utils/Iterators.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/utils/Iterators.java
|
MIT
|
public static <V> Iterator<V> range(long max, LongFunction<V> f) {
return range(0, max, f);
}
|
Represents a range implicitly starting at 0.
@param max an exclusive end of the range.
@param f a function which transforms a number in the range into a value.
@return an iterator which yields the values returned by {@code f}
|
range
|
java
|
lacuna/bifurcan
|
src/io/lacuna/bifurcan/utils/Iterators.java
|
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/utils/Iterators.java
|
MIT
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.