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 boolean isEmpty() { return elements.size() == 0; }
Utility functions for classes implementing {@code ISet}. @author ztellman
isEmpty
java
lacuna/bifurcan
src/io/lacuna/bifurcan/Sets.java
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/Sets.java
MIT
@Override public boolean contains(Object o) { return contains.test((V) o); }
Utility functions for classes implementing {@code ISet}. @author ztellman
contains
java
lacuna/bifurcan
src/io/lacuna/bifurcan/Sets.java
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/Sets.java
MIT
@Override public Iterator<V> iterator() { return elements.iterator(); }
Utility functions for classes implementing {@code ISet}. @author ztellman
iterator
java
lacuna/bifurcan
src/io/lacuna/bifurcan/Sets.java
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/Sets.java
MIT
@Override public Object[] toArray() { return elements.toArray(); }
Utility functions for classes implementing {@code ISet}. @author ztellman
toArray
java
lacuna/bifurcan
src/io/lacuna/bifurcan/Sets.java
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/Sets.java
MIT
@Override 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) elements.nth(i)); return ary; }
Utility functions for classes implementing {@code ISet}. @author ztellman
toArray
java
lacuna/bifurcan
src/io/lacuna/bifurcan/Sets.java
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/Sets.java
MIT
@Override public boolean add(V v) { return false; }
Utility functions for classes implementing {@code ISet}. @author ztellman
add
java
lacuna/bifurcan
src/io/lacuna/bifurcan/Sets.java
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/Sets.java
MIT
@Override public boolean remove(Object o) { return false; }
Utility functions for classes implementing {@code ISet}. @author ztellman
remove
java
lacuna/bifurcan
src/io/lacuna/bifurcan/Sets.java
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/Sets.java
MIT
@Override public boolean containsAll(Collection<?> c) { return c.stream().allMatch(this::contains); }
Utility functions for classes implementing {@code ISet}. @author ztellman
containsAll
java
lacuna/bifurcan
src/io/lacuna/bifurcan/Sets.java
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/Sets.java
MIT
@Override public boolean addAll(Collection<? extends V> c) { throw new UnsupportedOperationException(); }
Utility functions for classes implementing {@code ISet}. @author ztellman
addAll
java
lacuna/bifurcan
src/io/lacuna/bifurcan/Sets.java
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/Sets.java
MIT
@Override public boolean retainAll(Collection<?> c) { throw new UnsupportedOperationException(); }
Utility functions for classes implementing {@code ISet}. @author ztellman
retainAll
java
lacuna/bifurcan
src/io/lacuna/bifurcan/Sets.java
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/Sets.java
MIT
@Override public boolean removeAll(Collection<?> c) { throw new UnsupportedOperationException(); }
Utility functions for classes implementing {@code ISet}. @author ztellman
removeAll
java
lacuna/bifurcan
src/io/lacuna/bifurcan/Sets.java
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/Sets.java
MIT
@Override public void clear() { throw new UnsupportedOperationException(); }
Utility functions for classes implementing {@code ISet}. @author ztellman
clear
java
lacuna/bifurcan
src/io/lacuna/bifurcan/Sets.java
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/Sets.java
MIT
public static <V> ISortedSet<V> from( IList<V> elements, Comparator<V> comparator, Function<V, OptionalLong> inclusiveFloorIndex ) { return new ISortedSet.Mixin<V>() { @Override public Comparator<V> comparator() { return comparator; } @Override public OptionalLong inclusiveFloorIndex(V val) { return inclusiveFloorIndex.apply(val); } @Override public long size() { return elements.size(); } @Override public V nth(long idx) { return elements.nth(idx); } @Override public IList<V> elements() { return elements; } @Override public Iterator<V> iterator(long startIndex) { return elements.iterator(startIndex); } @Override public ISortedSet<V> add(V value) { return new SortedSet<>(comparator).union(this).add(value); } @Override public ISortedSet<V> remove(V value) { return new SortedSet<>(comparator).union(this).remove(value); } @Override public ISortedSet<V> linear() { return new SortedSet<>(comparator).union(this).linear(); } }; }
Utility functions for classes implementing {@code ISet}. @author ztellman
from
java
lacuna/bifurcan
src/io/lacuna/bifurcan/Sets.java
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/Sets.java
MIT
@Override public Comparator<V> comparator() { return comparator; }
Utility functions for classes implementing {@code ISet}. @author ztellman
comparator
java
lacuna/bifurcan
src/io/lacuna/bifurcan/Sets.java
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/Sets.java
MIT
@Override public OptionalLong inclusiveFloorIndex(V val) { return inclusiveFloorIndex.apply(val); }
Utility functions for classes implementing {@code ISet}. @author ztellman
inclusiveFloorIndex
java
lacuna/bifurcan
src/io/lacuna/bifurcan/Sets.java
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/Sets.java
MIT
@Override public long size() { return elements.size(); }
Utility functions for classes implementing {@code ISet}. @author ztellman
size
java
lacuna/bifurcan
src/io/lacuna/bifurcan/Sets.java
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/Sets.java
MIT
@Override public V nth(long idx) { return elements.nth(idx); }
Utility functions for classes implementing {@code ISet}. @author ztellman
nth
java
lacuna/bifurcan
src/io/lacuna/bifurcan/Sets.java
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/Sets.java
MIT
@Override public IList<V> elements() { return elements; }
Utility functions for classes implementing {@code ISet}. @author ztellman
elements
java
lacuna/bifurcan
src/io/lacuna/bifurcan/Sets.java
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/Sets.java
MIT
@Override public Iterator<V> iterator(long startIndex) { return elements.iterator(startIndex); }
Utility functions for classes implementing {@code ISet}. @author ztellman
iterator
java
lacuna/bifurcan
src/io/lacuna/bifurcan/Sets.java
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/Sets.java
MIT
@Override public ISortedSet<V> add(V value) { return new SortedSet<>(comparator).union(this).add(value); }
Utility functions for classes implementing {@code ISet}. @author ztellman
add
java
lacuna/bifurcan
src/io/lacuna/bifurcan/Sets.java
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/Sets.java
MIT
@Override public ISortedSet<V> remove(V value) { return new SortedSet<>(comparator).union(this).remove(value); }
Utility functions for classes implementing {@code ISet}. @author ztellman
remove
java
lacuna/bifurcan
src/io/lacuna/bifurcan/Sets.java
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/Sets.java
MIT
@Override public ISortedSet<V> linear() { return new SortedSet<>(comparator).union(this).linear(); }
Utility functions for classes implementing {@code ISet}. @author ztellman
linear
java
lacuna/bifurcan
src/io/lacuna/bifurcan/Sets.java
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/Sets.java
MIT
public static <V> ISet<V> from(IList<V> elements, Function<V, OptionalLong> indexOf) { return from(elements, indexOf, elements::iterator); }
Utility functions for classes implementing {@code ISet}. @author ztellman
from
java
lacuna/bifurcan
src/io/lacuna/bifurcan/Sets.java
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/Sets.java
MIT
public static <V> ISet<V> from(IList<V> elements, Function<V, OptionalLong> indexOf, Supplier<Iterator<V>> iterator) { return new ISet.Mixin<V>() { @Override public boolean contains(V value) { return indexOf(value).isPresent(); } @Override public long size() { return elements.size(); } @Override public IList<V> elements() { return elements; } @Override public OptionalLong indexOf(V element) { return indexOf.apply(element); } @Override public V nth(long idx) { return elements.nth(idx); } @Override public Iterator<V> iterator() { return iterator.get(); } @Override public ToLongFunction<V> valueHash() { return Maps.DEFAULT_HASH_CODE; } @Override public BiPredicate<V, V> valueEquality() { return Maps.DEFAULT_EQUALS; } @Override public ISet<V> add(V value) { return Set.from(this).add(value); } @Override public ISet<V> remove(V value) { return Set.from(this).remove(value); } @Override public ISet<V> linear() { return Set.from(this).linear(); } }; }
Utility functions for classes implementing {@code ISet}. @author ztellman
from
java
lacuna/bifurcan
src/io/lacuna/bifurcan/Sets.java
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/Sets.java
MIT
@Override public boolean contains(V value) { return indexOf(value).isPresent(); }
Utility functions for classes implementing {@code ISet}. @author ztellman
contains
java
lacuna/bifurcan
src/io/lacuna/bifurcan/Sets.java
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/Sets.java
MIT
@Override public long size() { return elements.size(); }
Utility functions for classes implementing {@code ISet}. @author ztellman
size
java
lacuna/bifurcan
src/io/lacuna/bifurcan/Sets.java
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/Sets.java
MIT
@Override public IList<V> elements() { return elements; }
Utility functions for classes implementing {@code ISet}. @author ztellman
elements
java
lacuna/bifurcan
src/io/lacuna/bifurcan/Sets.java
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/Sets.java
MIT
@Override public OptionalLong indexOf(V element) { return indexOf.apply(element); }
Utility functions for classes implementing {@code ISet}. @author ztellman
indexOf
java
lacuna/bifurcan
src/io/lacuna/bifurcan/Sets.java
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/Sets.java
MIT
@Override public V nth(long idx) { return elements.nth(idx); }
Utility functions for classes implementing {@code ISet}. @author ztellman
nth
java
lacuna/bifurcan
src/io/lacuna/bifurcan/Sets.java
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/Sets.java
MIT
@Override public Iterator<V> iterator() { return iterator.get(); }
Utility functions for classes implementing {@code ISet}. @author ztellman
iterator
java
lacuna/bifurcan
src/io/lacuna/bifurcan/Sets.java
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/Sets.java
MIT
@Override public ToLongFunction<V> valueHash() { return Maps.DEFAULT_HASH_CODE; }
Utility functions for classes implementing {@code ISet}. @author ztellman
valueHash
java
lacuna/bifurcan
src/io/lacuna/bifurcan/Sets.java
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/Sets.java
MIT
@Override public BiPredicate<V, V> valueEquality() { return Maps.DEFAULT_EQUALS; }
Utility functions for classes implementing {@code ISet}. @author ztellman
valueEquality
java
lacuna/bifurcan
src/io/lacuna/bifurcan/Sets.java
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/Sets.java
MIT
@Override public ISet<V> add(V value) { return Set.from(this).add(value); }
Utility functions for classes implementing {@code ISet}. @author ztellman
add
java
lacuna/bifurcan
src/io/lacuna/bifurcan/Sets.java
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/Sets.java
MIT
@Override public ISet<V> remove(V value) { return Set.from(this).remove(value); }
Utility functions for classes implementing {@code ISet}. @author ztellman
remove
java
lacuna/bifurcan
src/io/lacuna/bifurcan/Sets.java
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/Sets.java
MIT
@Override public ISet<V> linear() { return Set.from(this).linear(); }
Utility functions for classes implementing {@code ISet}. @author ztellman
linear
java
lacuna/bifurcan
src/io/lacuna/bifurcan/Sets.java
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/Sets.java
MIT
public static <V> String toString(ISet<V> set) { return toString(set, Objects::toString); }
Utility functions for classes implementing {@code ISet}. @author ztellman
toString
java
lacuna/bifurcan
src/io/lacuna/bifurcan/Sets.java
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/Sets.java
MIT
public static <V> String toString(ISet<V> set, Function<V, String> elementPrinter) { StringBuilder sb = new StringBuilder("{"); Iterator<V> it = set.elements().iterator(); while (it.hasNext()) { sb.append(elementPrinter.apply(it.next())); if (it.hasNext()) { sb.append(", "); } } sb.append("}"); return sb.toString(); }
Utility functions for classes implementing {@code ISet}. @author ztellman
toString
java
lacuna/bifurcan
src/io/lacuna/bifurcan/Sets.java
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/Sets.java
MIT
public static <V> Collector<V, LinearSet<V>, LinearSet<V>> linearCollector() { return linearCollector(8); }
Utility functions for classes implementing {@code ISet}. @author ztellman
linearCollector
java
lacuna/bifurcan
src/io/lacuna/bifurcan/Sets.java
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/Sets.java
MIT
public static <V> Collector<V, LinearSet<V>, LinearSet<V>> linearCollector(int capacity) { return new Collector<V, LinearSet<V>, LinearSet<V>>() { @Override public Supplier<LinearSet<V>> supplier() { return () -> new LinearSet<V>(capacity); } @Override public BiConsumer<LinearSet<V>, V> accumulator() { return LinearSet::add; } @Override public BinaryOperator<LinearSet<V>> combiner() { return LinearSet::union; } @Override public Function<LinearSet<V>, LinearSet<V>> finisher() { return s -> s; } @Override public java.util.Set<Characteristics> characteristics() { return EnumSet.of(Characteristics.IDENTITY_FINISH, Characteristics.UNORDERED); } }; }
Utility functions for classes implementing {@code ISet}. @author ztellman
linearCollector
java
lacuna/bifurcan
src/io/lacuna/bifurcan/Sets.java
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/Sets.java
MIT
@Override public Supplier<LinearSet<V>> supplier() { return () -> new LinearSet<V>(capacity); }
Utility functions for classes implementing {@code ISet}. @author ztellman
supplier
java
lacuna/bifurcan
src/io/lacuna/bifurcan/Sets.java
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/Sets.java
MIT
@Override public BiConsumer<LinearSet<V>, V> accumulator() { return LinearSet::add; }
Utility functions for classes implementing {@code ISet}. @author ztellman
accumulator
java
lacuna/bifurcan
src/io/lacuna/bifurcan/Sets.java
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/Sets.java
MIT
@Override public BinaryOperator<LinearSet<V>> combiner() { return LinearSet::union; }
Utility functions for classes implementing {@code ISet}. @author ztellman
combiner
java
lacuna/bifurcan
src/io/lacuna/bifurcan/Sets.java
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/Sets.java
MIT
@Override public Function<LinearSet<V>, LinearSet<V>> finisher() { return s -> s; }
Utility functions for classes implementing {@code ISet}. @author ztellman
finisher
java
lacuna/bifurcan
src/io/lacuna/bifurcan/Sets.java
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/Sets.java
MIT
@Override public java.util.Set<Characteristics> characteristics() { return EnumSet.of(Characteristics.IDENTITY_FINISH, Characteristics.UNORDERED); }
Utility functions for classes implementing {@code ISet}. @author ztellman
characteristics
java
lacuna/bifurcan
src/io/lacuna/bifurcan/Sets.java
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/Sets.java
MIT
public static <V> Collector<V, Set<V>, Set<V>> collector() { return new Collector<V, Set<V>, Set<V>>() { @Override public Supplier<Set<V>> supplier() { return () -> new Set<V>().linear(); } @Override public BiConsumer<Set<V>, V> accumulator() { return Set::add; } @Override public BinaryOperator<Set<V>> combiner() { return Set::union; } @Override public Function<Set<V>, Set<V>> finisher() { return Set::forked; } @Override public java.util.Set<Characteristics> characteristics() { return EnumSet.of(Characteristics.UNORDERED); } }; }
Utility functions for classes implementing {@code ISet}. @author ztellman
collector
java
lacuna/bifurcan
src/io/lacuna/bifurcan/Sets.java
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/Sets.java
MIT
@Override public Supplier<Set<V>> supplier() { return () -> new Set<V>().linear(); }
Utility functions for classes implementing {@code ISet}. @author ztellman
supplier
java
lacuna/bifurcan
src/io/lacuna/bifurcan/Sets.java
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/Sets.java
MIT
@Override public BiConsumer<Set<V>, V> accumulator() { return Set::add; }
Utility functions for classes implementing {@code ISet}. @author ztellman
accumulator
java
lacuna/bifurcan
src/io/lacuna/bifurcan/Sets.java
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/Sets.java
MIT
@Override public BinaryOperator<Set<V>> combiner() { return Set::union; }
Utility functions for classes implementing {@code ISet}. @author ztellman
combiner
java
lacuna/bifurcan
src/io/lacuna/bifurcan/Sets.java
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/Sets.java
MIT
@Override public Function<Set<V>, Set<V>> finisher() { return Set::forked; }
Utility functions for classes implementing {@code ISet}. @author ztellman
finisher
java
lacuna/bifurcan
src/io/lacuna/bifurcan/Sets.java
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/Sets.java
MIT
@Override public java.util.Set<Characteristics> characteristics() { return EnumSet.of(Characteristics.UNORDERED); }
Utility functions for classes implementing {@code ISet}. @author ztellman
characteristics
java
lacuna/bifurcan
src/io/lacuna/bifurcan/Sets.java
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/Sets.java
MIT
public static <K, V> SortedMap<K, V> from(java.util.Map<K, V> m) { SortedMap<K, V> result = new SortedMap<K, V>().linear(); m.entrySet().forEach(e -> result.put(e.getKey(), e.getValue())); return result.forked(); }
A red-black tree based on <a href="http://matt.might.net/papers/germane2014deletion.pdf">Germane 2014</a>.
from
java
lacuna/bifurcan
src/io/lacuna/bifurcan/SortedMap.java
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/SortedMap.java
MIT
public static <K, V> SortedMap<K, V> empty() { return EMPTY; }
A red-black tree based on <a href="http://matt.might.net/papers/germane2014deletion.pdf">Germane 2014</a>.
empty
java
lacuna/bifurcan
src/io/lacuna/bifurcan/SortedMap.java
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/SortedMap.java
MIT
@Override public Comparator<K> comparator() { return comparator; }
A red-black tree based on <a href="http://matt.might.net/papers/germane2014deletion.pdf">Germane 2014</a>.
comparator
java
lacuna/bifurcan
src/io/lacuna/bifurcan/SortedMap.java
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/SortedMap.java
MIT
@Override public OptionalLong inclusiveFloorIndex(K key) { long idx = root.floorIndex(key, comparator, 0); return idx < 0 ? OptionalLong.empty() : OptionalLong.of(idx); }
A red-black tree based on <a href="http://matt.might.net/papers/germane2014deletion.pdf">Germane 2014</a>.
inclusiveFloorIndex
java
lacuna/bifurcan
src/io/lacuna/bifurcan/SortedMap.java
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/SortedMap.java
MIT
@Override public OptionalLong ceilIndex(K key) { long idx = root.ceilIndex(key, comparator, 0); return idx < 0 ? OptionalLong.empty() : OptionalLong.of(idx); }
A red-black tree based on <a href="http://matt.might.net/papers/germane2014deletion.pdf">Germane 2014</a>.
ceilIndex
java
lacuna/bifurcan
src/io/lacuna/bifurcan/SortedMap.java
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/SortedMap.java
MIT
@Override public SortedMap<K, V> update(K key, UnaryOperator<V> update) { return put(key, update.apply(this.get(key, null))); }
A red-black tree based on <a href="http://matt.might.net/papers/germane2014deletion.pdf">Germane 2014</a>.
update
java
lacuna/bifurcan
src/io/lacuna/bifurcan/SortedMap.java
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/SortedMap.java
MIT
@Override public SortedMap<K, V> put(K key, V value) { return put(key, value, (BinaryOperator<V>) Maps.MERGE_LAST_WRITE_WINS); }
A red-black tree based on <a href="http://matt.might.net/papers/germane2014deletion.pdf">Germane 2014</a>.
put
java
lacuna/bifurcan
src/io/lacuna/bifurcan/SortedMap.java
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/SortedMap.java
MIT
@Override public List<SortedMap<K, V>> split(int parts) { IList<Node<K, V>> acc = new LinearList<>(); root.split(Math.max(1, (int) Math.ceil((double) root.size / parts)), acc); return acc.stream() .map(n -> new SortedMap<>(n, isLinear(), comparator)) .collect(Lists.collector()); }
A red-black tree based on <a href="http://matt.might.net/papers/germane2014deletion.pdf">Germane 2014</a>.
split
java
lacuna/bifurcan
src/io/lacuna/bifurcan/SortedMap.java
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/SortedMap.java
MIT
@Override public SortedMap<K, V> put(K key, V value, BinaryOperator<V> merge) { Node<K, V> rootPrime = root.put(key, value, merge, comparator); //rootPrime.checkInvariant(); if (isLinear()) { super.hash = -1; root = rootPrime; return this; } else { return new SortedMap<>(rootPrime, false, comparator); } }
A red-black tree based on <a href="http://matt.might.net/papers/germane2014deletion.pdf">Germane 2014</a>.
put
java
lacuna/bifurcan
src/io/lacuna/bifurcan/SortedMap.java
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/SortedMap.java
MIT
@Override public SortedMap<K, V> remove(K key) { Node<K, V> rootPrime = root.remove(key, comparator); //rootPrime.checkInvariant(); if (isLinear()) { super.hash = -1; root = rootPrime; return this; } else { return new SortedMap<>(rootPrime, false, comparator); } }
A red-black tree based on <a href="http://matt.might.net/papers/germane2014deletion.pdf">Germane 2014</a>.
remove
java
lacuna/bifurcan
src/io/lacuna/bifurcan/SortedMap.java
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/SortedMap.java
MIT
@Override public V get(K key, V defaultValue) { Node<K, V> n = SortedMapNodes.find(root, key, comparator); return n == null ? defaultValue : n.v; }
A red-black tree based on <a href="http://matt.might.net/papers/germane2014deletion.pdf">Germane 2014</a>.
get
java
lacuna/bifurcan
src/io/lacuna/bifurcan/SortedMap.java
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/SortedMap.java
MIT
@Override public boolean contains(K key) { return SortedMapNodes.find(root, key, comparator) != null; }
A red-black tree based on <a href="http://matt.might.net/papers/germane2014deletion.pdf">Germane 2014</a>.
contains
java
lacuna/bifurcan
src/io/lacuna/bifurcan/SortedMap.java
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/SortedMap.java
MIT
@Override public OptionalLong indexOf(K key) { long idx = SortedMapNodes.indexOf(root, key, comparator); return idx < 0 ? OptionalLong.empty() : OptionalLong.of(idx); }
A red-black tree based on <a href="http://matt.might.net/papers/germane2014deletion.pdf">Germane 2014</a>.
indexOf
java
lacuna/bifurcan
src/io/lacuna/bifurcan/SortedMap.java
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/SortedMap.java
MIT
@Override public <U> SortedMap<K, U> mapValues(BiFunction<K, V, U> f) { return new SortedMap<>(root.mapValues(f), isLinear(), comparator); }
A red-black tree based on <a href="http://matt.might.net/papers/germane2014deletion.pdf">Germane 2014</a>.
mapValues
java
lacuna/bifurcan
src/io/lacuna/bifurcan/SortedMap.java
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/SortedMap.java
MIT
@Override public Iterator<IEntry<K, V>> iterator() { return SortedMapNodes.iterator(root); }
A red-black tree based on <a href="http://matt.might.net/papers/germane2014deletion.pdf">Germane 2014</a>.
iterator
java
lacuna/bifurcan
src/io/lacuna/bifurcan/SortedMap.java
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/SortedMap.java
MIT
@Override public IEntry<K, V> nth(long idx) { if (idx < 0 || idx >= size()) { throw new IndexOutOfBoundsException(String.format("%d must be within [0,%d)", idx, size())); } Node<K, V> n = SortedMapNodes.nth(root, (int) idx); return IEntry.of(n.k, n.v); }
A red-black tree based on <a href="http://matt.might.net/papers/germane2014deletion.pdf">Germane 2014</a>.
nth
java
lacuna/bifurcan
src/io/lacuna/bifurcan/SortedMap.java
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/SortedMap.java
MIT
public long size() { return root.size; }
A red-black tree based on <a href="http://matt.might.net/papers/germane2014deletion.pdf">Germane 2014</a>.
size
java
lacuna/bifurcan
src/io/lacuna/bifurcan/SortedMap.java
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/SortedMap.java
MIT
@Override public SortedMap<K, V> clone() { return isLinear() ? forked().linear() : this; }
A red-black tree based on <a href="http://matt.might.net/papers/germane2014deletion.pdf">Germane 2014</a>.
clone
java
lacuna/bifurcan
src/io/lacuna/bifurcan/SortedMap.java
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/SortedMap.java
MIT
@Override public boolean isLinear() { return editor != null; }
A red-black tree based on <a href="http://matt.might.net/papers/germane2014deletion.pdf">Germane 2014</a>.
isLinear
java
lacuna/bifurcan
src/io/lacuna/bifurcan/SortedMap.java
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/SortedMap.java
MIT
@Override public SortedMap<K, V> forked() { return isLinear() ? new SortedMap<>(root, false, comparator) : this; }
A red-black tree based on <a href="http://matt.might.net/papers/germane2014deletion.pdf">Germane 2014</a>.
forked
java
lacuna/bifurcan
src/io/lacuna/bifurcan/SortedMap.java
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/SortedMap.java
MIT
@Override public SortedMap<K, V> linear() { return isLinear() ? this : new SortedMap<>(root, true, comparator); }
A red-black tree based on <a href="http://matt.might.net/papers/germane2014deletion.pdf">Germane 2014</a>.
linear
java
lacuna/bifurcan
src/io/lacuna/bifurcan/SortedMap.java
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/SortedMap.java
MIT
@Override public ToLongFunction<K> keyHash() { return Maps.DEFAULT_HASH_CODE; }
A red-black tree based on <a href="http://matt.might.net/papers/germane2014deletion.pdf">Germane 2014</a>.
keyHash
java
lacuna/bifurcan
src/io/lacuna/bifurcan/SortedMap.java
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/SortedMap.java
MIT
@Override public BiPredicate<K, K> keyEquality() { return Maps.DEFAULT_EQUALS; }
A red-black tree based on <a href="http://matt.might.net/papers/germane2014deletion.pdf">Germane 2014</a>.
keyEquality
java
lacuna/bifurcan
src/io/lacuna/bifurcan/SortedMap.java
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/SortedMap.java
MIT
@Override public long indexOf(int shift, int hash, K key, BiPredicate<K, K> equals) { int mask = hashMask(hash, shift); if (isEntry(mask)) { int idx = entryIndex(mask); // checking the hash only helps when equality checks are expensive and failed lookups are common // in the normal case, it just leads to cache misses return /*hash == hashes[idx] &&*/ equals.test(key, (K) content[idx << 1]) ? idx : -1; } else if (isNode(mask)) { long idx = node(mask).indexOf(shift + SHIFT_INCREMENT, hash, key, equals); if (idx == -1) { return -1; } else { int nodeIdx = nodeIndex(mask); idx += bitCount(datamap); for (int i = 0; i < nodeIdx; i++) { idx += ((INode<K, V>) content[content.length - (i + 1)]).size(); } return idx; } } else { 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 IEntry<K, V> nth(long idx) { // see if the entry is local to this node int numEntries = bitCount(datamap); if (idx < numEntries) { int contentIdx = (int) (idx << 1); return IEntry.of((K) content[contentIdx], (V) content[contentIdx + 1]); } // see if the entry is local to our children if (idx < size) { idx -= numEntries; for (INode<K, V> node : nodes()) { if (idx < node.size()) { return node.nth(idx); } idx -= node.size(); } } throw new IndexOutOfBoundsException(); }
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 int hash(int idx) { return hashes[idx]; }
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
private boolean mergeEntry( int shift, int mask, int hash, K key, V value, BiPredicate<K, K> equals, BinaryOperator<V> merge ) { int idx = entryIndex(mask); // there's a match boolean collision = hash == hashes[idx]; if (collision && equals.test(key, (K) content[idx << 1])) { idx = (idx << 1) + 1; content[idx] = merge.apply((V) content[idx], value); return false; // collision, put them both in a node together } else { K currKey = (K) content[idx << 1]; V currValue = (V) content[(idx << 1) + 1]; INode<K, V> node; if (collision) { node = new Collision<>(hash, currKey, currValue, key, value); } else { node = new Node<K, V>(editor) .put(shift + SHIFT_INCREMENT, editor, hashes[idx], currKey, currValue, equals, merge) .put(shift + SHIFT_INCREMENT, editor, hash, key, value, equals, merge); } removeEntry(mask).putNode(mask, node); return true; } }
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
mergeEntry
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 Node<K, V> put( int shift, Object editor, int hash, K key, V value, BiPredicate<K, K> equals, BinaryOperator<V> merge ) { if (editor != this.editor) { return clone(editor).put(shift, editor, hash, key, value, equals, merge); } Node<K, V> n = this; int currShift = shift; boolean increment; for (; ; ) { int mask = hashMask(hash, currShift); // overwrite potential collision if (n.isEntry(mask)) { increment = n.mergeEntry(currShift, mask, hash, key, value, equals, merge); break; // we have to go deeper } else if (n.isNode(mask)) { INode<K, V> child = n.node(mask); // since we're not changing anything at this level, just head down if (child instanceof Node && ((Node<K, V>) child).editor == editor) { n = (Node<K, V>) child; currShift += SHIFT_INCREMENT; // we need to maintain the stack, sadly } else { long prevSize = child.size(); INode<K, V> nodePrime = child.put(currShift + SHIFT_INCREMENT, editor, hash, key, value, equals, merge); increment = nodePrime.size() != prevSize; n.setNode(mask, nodePrime, increment ? 1 : 0); break; } // no existing entry } else { n.putEntry(mask, hash, key, value); increment = true; break; } } // we've descended, and need to update the sizes of our parents if (n != this && increment) { Node<K, V> currNode = this; currShift = shift; while (currNode != n) { currNode.size++; currNode = (Node<K, V>) currNode.node(hashMask(hash, currShift)); currShift += SHIFT_INCREMENT; } } return this; }
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) { int mask = hashMask(hash, shift); // there's a potential match if (isEntry(mask)) { int idx = entryIndex(mask); // there is a match if (hashes[idx] == hash && equals.test(key, (K) content[idx << 1])) { return (this.editor == editor ? this : clone(editor)).removeEntry(mask).collapse(shift); // nope } else { return this; } // we must go deeper } else if (isNode(mask)) { INode<K, V> node = node(mask); long prevSize = node.size(); INode<K, V> nodePrime = node.remove(shift + SHIFT_INCREMENT, editor, hash, key, equals); Node<K, V> n = this.editor == editor ? this : clone(editor); switch ((int) nodePrime.size()) { case 0: return n.removeNode(mask, prevSize).collapse(shift); case 1: IEntry<K, V> e = nodePrime.nth(0); return n.removeNode(mask, prevSize).putEntry(mask, nodePrime.hash(0), e.key(), e.value()); default: return n.setNode(mask, nodePrime, nodePrime.size() - prevSize).collapse(shift); } // no such thing } else { return this; } }
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> Node<K, U> mapVals(Object editor, BiFunction<K, V, U> f) { Node n = clone(editor); for (int i = bitCount(n.datamap) - 1; i >= 0; i--) { int idx = i << 1; n.content[idx + 1] = f.apply((K) n.content[idx], (V) n.content[idx + 1]); } for (int i = content.length - bitCount(n.nodemap); i < content.length; i++) { n.content[i] = ((INode<K, V>) n.content[i]).mapVals(editor, f); } return n; }
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 Iterator<IEntry<K, V>> iterator() { return new Iterator<IEntry<K, V>>() { final Node[] stack = new Node[7]; final byte[] cursors = new byte[14]; int depth = 0; { stack[0] = Node.this; cursors[1] = (byte) bitCount(Node.this.nodemap); } Object[] content = Node.this.content; int idx = 0; int limit = bitCount(Node.this.datamap) << 1; private boolean nextNode() { while (depth >= 0) { int pos = depth << 1; int idx = cursors[pos]; int limit = cursors[pos + 1]; if (idx < limit) { Node<K, V> curr = stack[depth]; INode<K, V> next = (INode<K, V>) curr.content[curr.content.length - 1 - idx]; cursors[pos]++; if (next instanceof Node) { Node<K, V> n = (Node<K, V>) next; if (n.nodemap != 0) { stack[++depth] = n; cursors[pos + 2] = 0; cursors[pos + 3] = (byte) bitCount(n.nodemap); } if (n.datamap != 0) { this.content = n.content; this.idx = 0; this.limit = bitCount(n.datamap) << 1; return true; } } else { Collision<K, V> c = (Collision<K, V>) next; this.content = c.entries; this.idx = 0; this.limit = c.entries.length; return true; } } else { depth--; } } return false; } @Override public boolean hasNext() { return idx < limit || nextNode(); } @Override public IEntry<K, V> next() { if (idx >= limit) { if (!nextNode()) { throw new NoSuchElementException(); } } IEntry<K, V> e = IEntry.of((K) content[idx], (V) content[idx + 1]); idx += 2; return e; } }; }
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
iterator
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 boolean nextNode() { while (depth >= 0) { int pos = depth << 1; int idx = cursors[pos]; int limit = cursors[pos + 1]; if (idx < limit) { Node<K, V> curr = stack[depth]; INode<K, V> next = (INode<K, V>) curr.content[curr.content.length - 1 - idx]; cursors[pos]++; if (next instanceof Node) { Node<K, V> n = (Node<K, V>) next; if (n.nodemap != 0) { stack[++depth] = n; cursors[pos + 2] = 0; cursors[pos + 3] = (byte) bitCount(n.nodemap); } if (n.datamap != 0) { this.content = n.content; this.idx = 0; this.limit = bitCount(n.datamap) << 1; return true; } } else { Collision<K, V> c = (Collision<K, V>) next; this.content = c.entries; this.idx = 0; this.limit = c.entries.length; return true; } } else { depth--; } } 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
nextNode
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 hasNext() { return idx < limit || nextNode(); }
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
hasNext
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> next() { if (idx >= limit) { if (!nextNode()) { throw new NoSuchElementException(); } } IEntry<K, V> e = IEntry.of((K) content[idx], (V) content[idx + 1]); idx += 2; return e; }
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
next
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 Iterable<IEntry<K, V>> entries() { return () -> Iterators.range( bitCount(datamap), i -> { int idx = (int) (i << 1); return IEntry.of((K) content[idx], (V) content[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
@Override public long size() { return size; }
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
public boolean equals(INode<K, V> o, BiPredicate<K, K> keyEquals, BiPredicate<V, V> valEquals) { if (this == o) { return true; } if (o instanceof Node) { Node<K, V> n = (Node<K, V>) o; if (n.size == size && n.datamap == datamap && n.nodemap == nodemap) { Iterator<IEntry<K, V>> ea = entries().iterator(); Iterator<IEntry<K, V>> eb = n.entries().iterator(); while (ea.hasNext()) { if (!ea.next().equals(eb.next(), keyEquals, valEquals)) { return false; } } Iterator<INode<K, V>> na = nodes().iterator(); Iterator<INode<K, V>> nb = n.nodes().iterator(); while (na.hasNext()) { if (!na.next().equals(nb.next(), keyEquals, valEquals)) { 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 Node<K, V> clone(Object editor) { Node<K, V> node = new Node<>(); node.datamap = datamap; node.nodemap = nodemap; node.hashes = hashes.clone(); node.content = content.clone(); node.editor = editor; node.size = size; return node; }
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
clone
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 Iterable<INode<K, V>> nodes() { return () -> Iterators.range(0, bitCount(nodemap), i -> (INode<K, V>) content[content.length - 1 - (int) i]); }
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
nodes
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 INode<K, V> collapse(int shift) { return (shift > 0 && datamap == 0 && Bits.isPowerOfTwo(nodemap) && node(nodemap) instanceof Collision) ? node(nodemap) : this; }
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
collapse
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 void grow() { if (content.length == 64) { return; } Object[] c = new Object[content.length << 1]; int[] h = new int[hashes.length << 1]; int numNodes = bitCount(nodemap); int numEntries = bitCount(datamap); arraycopy(content, 0, c, 0, numEntries << 1); arraycopy(content, content.length - numNodes, c, c.length - numNodes, numNodes); arraycopy(hashes, 0, h, 0, numEntries); this.hashes = h; this.content = 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
grow
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
Node<K, V> putEntry(int mask, int hash, K key, V value) { int numEntries = bitCount(datamap); int count = (numEntries << 1) + bitCount(nodemap); if ((count + 2) > content.length) { grow(); } final int idx = entryIndex(mask); final int entryIdx = idx << 1; if (idx != numEntries) { arraycopy(content, entryIdx, content, entryIdx + 2, (numEntries - idx) << 1); arraycopy(hashes, idx, hashes, idx + 1, numEntries - idx); } datamap |= mask; size++; hashes[idx] = hash; content[entryIdx] = key; content[entryIdx + 1] = value; return this; }
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
putEntry
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
Node<K, V> removeEntry(final int mask) { // shrink? final int idx = entryIndex(mask); final int numEntries = bitCount(datamap); if (idx != numEntries - 1) { arraycopy(content, (idx + 1) << 1, content, idx << 1, (numEntries - 1 - idx) << 1); arraycopy(hashes, idx + 1, hashes, idx, numEntries - 1 - idx); } datamap &= ~mask; size--; int entryIdx = (numEntries - 1) << 1; content[entryIdx] = null; content[entryIdx + 1] = null; return this; }
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
removeEntry
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
Node<K, V> setNode(int mask, INode<K, V> node, long sizeDelta) { content[content.length - 1 - nodeIndex(mask)] = node; size += sizeDelta; return this; }
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
setNode
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
Node<K, V> putNode(final int mask, INode<K, V> node) { if (node.size() == 1) { IEntry<K, V> e = node.nth(0); return putEntry(mask, node.hash(0), e.key(), e.value()); } else { int count = (bitCount(datamap) << 1) + bitCount(nodemap); if ((count + 1) > content.length) { grow(); } int idx = nodeIndex(mask); int numNodes = bitCount(nodemap); if (numNodes > 0) { arraycopy(content, content.length - numNodes, content, content.length - 1 - numNodes, numNodes - idx); } nodemap |= mask; size += node.size(); content[content.length - 1 - idx] = node; return this; } }
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
putNode
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
Node<K, V> removeNode(final int mask, long nodeSize) { // shrink? int idx = nodeIndex(mask); int numNodes = bitCount(nodemap); size -= nodeSize; arraycopy(content, content.length - numNodes, content, content.length + 1 - numNodes, numNodes - 1 - idx); nodemap &= ~mask; content[content.length - numNodes] = null; return this; }
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
removeNode
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 entryIndex(int mask) { return compressedIndex(datamap, 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
entryIndex
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 nodeIndex(int mask) { return compressedIndex(nodemap, 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
nodeIndex
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 INode<K, V> node(int mask) { return (INode<K, V>) content[content.length - 1 - nodeIndex(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
node
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 boolean isEntry(int mask) { return (datamap & 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
isEntry
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