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 String toString() { return Maps.toString(map); }
Utility functions for classes implementing {@link IMap}. @author ztellman
toString
java
lacuna/bifurcan
src/io/lacuna/bifurcan/Maps.java
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/Maps.java
MIT
@Override public boolean equals(Object obj) { if (obj instanceof java.util.Map) { java.util.Map<K, V> m = (java.util.Map<K, V>) obj; if (size() != m.size()) { return false; } else if (this == m) { return true; } return m.entrySet().stream().allMatch(e -> { Object val = ((Map) map).get(e.getKey(), DEFAULT_VALUE); return val != DEFAULT_VALUE && Objects.equals(val, e.getValue()); }); } return false; }
Utility functions for classes implementing {@link IMap}. @author ztellman
equals
java
lacuna/bifurcan
src/io/lacuna/bifurcan/Maps.java
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/Maps.java
MIT
@Override public int hashCode() { return (int) Maps.hash(map, e -> Objects.hashCode(e.key()) ^ Objects.hashCode(e.value()), (a, b) -> a + b); }
Utility functions for classes implementing {@link IMap}. @author ztellman
hashCode
java
lacuna/bifurcan
src/io/lacuna/bifurcan/Maps.java
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/Maps.java
MIT
public static <K, V> java.util.Map.Entry<K, V> toEntry(IEntry<K, V> entry) { return new java.util.Map.Entry<K, V>() { @Override public K getKey() { return entry.key(); } @Override public V getValue() { return entry.value(); } @Override public V setValue(V value) { throw new UnsupportedOperationException(); } }; }
Utility functions for classes implementing {@link IMap}. @author ztellman
toEntry
java
lacuna/bifurcan
src/io/lacuna/bifurcan/Maps.java
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/Maps.java
MIT
@Override public K getKey() { return entry.key(); }
Utility functions for classes implementing {@link IMap}. @author ztellman
getKey
java
lacuna/bifurcan
src/io/lacuna/bifurcan/Maps.java
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/Maps.java
MIT
@Override public V getValue() { return entry.value(); }
Utility functions for classes implementing {@link IMap}. @author ztellman
getValue
java
lacuna/bifurcan
src/io/lacuna/bifurcan/Maps.java
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/Maps.java
MIT
@Override public V setValue(V value) { throw new UnsupportedOperationException(); }
Utility functions for classes implementing {@link IMap}. @author ztellman
setValue
java
lacuna/bifurcan
src/io/lacuna/bifurcan/Maps.java
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/Maps.java
MIT
static <K, V> IMap<K, V> difference(IMap<K, V> map, ISet<K> keys) { for (K key : keys) { map = map.remove(key); } return map; }
Utility functions for classes implementing {@link IMap}. @author ztellman
difference
java
lacuna/bifurcan
src/io/lacuna/bifurcan/Maps.java
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/Maps.java
MIT
static <K, V> IMap<K, V> intersection(IMap<K, V> accumulator, IMap<K, V> map, ISet<K> keys) { if (map.size() < keys.size()) { for (IEntry<K, V> entry : map.entries()) { if (keys.contains(entry.key())) { accumulator.put(entry.key(), entry.value()); } } } else { for (K key : keys) { Object value = ((IMap<K, Object>) map).get(key, DEFAULT_VALUE); if (value != DEFAULT_VALUE) { accumulator = accumulator.put(key, (V) value); } } } return accumulator; }
Utility functions for classes implementing {@link IMap}. @author ztellman
intersection
java
lacuna/bifurcan
src/io/lacuna/bifurcan/Maps.java
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/Maps.java
MIT
public static <K> boolean equivEquality(IMap<K, ?> a, IMap<K, ?> b) { return a.keyHash() == b.keyHash() && a.keyEquality() == b.keyEquality(); }
Utility functions for classes implementing {@link IMap}. @author ztellman
equivEquality
java
lacuna/bifurcan
src/io/lacuna/bifurcan/Maps.java
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/Maps.java
MIT
public static <K> boolean equivEquality(IMap<K, ?> a, ISet<K> b) { return a.keyHash() == b.valueHash() && a.keyEquality() == b.valueEquality(); }
Utility functions for classes implementing {@link IMap}. @author ztellman
equivEquality
java
lacuna/bifurcan
src/io/lacuna/bifurcan/Maps.java
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/Maps.java
MIT
static <K, V> IMap<K, V> merge(IMap<K, V> a, IMap<K, V> b, BinaryOperator<V> mergeFn) { for (IEntry<K, V> e : b.entries()) { a = a.put(e.key(), e.value(), mergeFn); } return a; }
Utility functions for classes implementing {@link IMap}. @author ztellman
merge
java
lacuna/bifurcan
src/io/lacuna/bifurcan/Maps.java
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/Maps.java
MIT
public static <T, K, V> Collector<T, LinearMap<K, V>, LinearMap<K, V>> linearCollector( Function<T, K> keyFn, Function<T, V> valFn, int capacity ) { return linearCollector(keyFn, valFn, Maps.MERGE_LAST_WRITE_WINS, capacity); }
Utility functions for classes implementing {@link IMap}. @author ztellman
linearCollector
java
lacuna/bifurcan
src/io/lacuna/bifurcan/Maps.java
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/Maps.java
MIT
public static <T, K, V> Collector<T, LinearMap<K, V>, LinearMap<K, V>> linearCollector( Function<T, K> keyFn, Function<T, V> valFn ) { return linearCollector(keyFn, valFn, Maps.MERGE_LAST_WRITE_WINS, 8); }
Utility functions for classes implementing {@link IMap}. @author ztellman
linearCollector
java
lacuna/bifurcan
src/io/lacuna/bifurcan/Maps.java
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/Maps.java
MIT
public static <T, K, V> Collector<T, LinearMap<K, V>, LinearMap<K, V>> linearCollector( Function<T, K> keyFn, Function<T, V> valFn, BinaryOperator<V> mergeFn, int capacity ) { return new Collector<T, LinearMap<K, V>, LinearMap<K, V>>() { @Override public Supplier<LinearMap<K, V>> supplier() { return () -> new LinearMap<>(capacity); } @Override public BiConsumer<LinearMap<K, V>, T> accumulator() { return (m, e) -> m.put(keyFn.apply(e), valFn.apply(e)); } @Override public BinaryOperator<LinearMap<K, V>> combiner() { return (a, b) -> a.merge(b, mergeFn); } @Override public Function<LinearMap<K, V>, LinearMap<K, V>> finisher() { return x -> x; } @Override public java.util.Set<Characteristics> characteristics() { return EnumSet.of(Characteristics.IDENTITY_FINISH); } }; }
Utility functions for classes implementing {@link IMap}. @author ztellman
linearCollector
java
lacuna/bifurcan
src/io/lacuna/bifurcan/Maps.java
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/Maps.java
MIT
@Override public Supplier<LinearMap<K, V>> supplier() { return () -> new LinearMap<>(capacity); }
Utility functions for classes implementing {@link IMap}. @author ztellman
supplier
java
lacuna/bifurcan
src/io/lacuna/bifurcan/Maps.java
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/Maps.java
MIT
@Override public BiConsumer<LinearMap<K, V>, T> accumulator() { return (m, e) -> m.put(keyFn.apply(e), valFn.apply(e)); }
Utility functions for classes implementing {@link IMap}. @author ztellman
accumulator
java
lacuna/bifurcan
src/io/lacuna/bifurcan/Maps.java
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/Maps.java
MIT
@Override public BinaryOperator<LinearMap<K, V>> combiner() { return (a, b) -> a.merge(b, mergeFn); }
Utility functions for classes implementing {@link IMap}. @author ztellman
combiner
java
lacuna/bifurcan
src/io/lacuna/bifurcan/Maps.java
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/Maps.java
MIT
@Override public Function<LinearMap<K, V>, LinearMap<K, V>> finisher() { return x -> x; }
Utility functions for classes implementing {@link IMap}. @author ztellman
finisher
java
lacuna/bifurcan
src/io/lacuna/bifurcan/Maps.java
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/Maps.java
MIT
@Override public java.util.Set<Characteristics> characteristics() { return EnumSet.of(Characteristics.IDENTITY_FINISH); }
Utility functions for classes implementing {@link IMap}. @author ztellman
characteristics
java
lacuna/bifurcan
src/io/lacuna/bifurcan/Maps.java
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/Maps.java
MIT
public static <T, K, V> Collector<T, Map<K, V>, Map<K, V>> collector(Function<T, K> keyFn, Function<T, V> valFn) { return collector(keyFn, valFn, Maps.MERGE_LAST_WRITE_WINS); }
Utility functions for classes implementing {@link IMap}. @author ztellman
collector
java
lacuna/bifurcan
src/io/lacuna/bifurcan/Maps.java
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/Maps.java
MIT
public static <T, K, V> Collector<T, Map<K, V>, Map<K, V>> collector( Function<T, K> keyFn, Function<T, V> valFn, BinaryOperator<V> mergeFn ) { return new Collector<T, Map<K, V>, Map<K, V>>() { @Override public Supplier<Map<K, V>> supplier() { return () -> new Map<K, V>().linear(); } @Override public BiConsumer<Map<K, V>, T> accumulator() { return (m, e) -> m.put(keyFn.apply(e), valFn.apply(e)); } @Override public BinaryOperator<Map<K, V>> combiner() { return (a, b) -> a.merge(b, mergeFn); } @Override public Function<Map<K, V>, Map<K, V>> finisher() { return Map::forked; } @Override public java.util.Set<Characteristics> characteristics() { return EnumSet.noneOf(Characteristics.class); } }; }
Utility functions for classes implementing {@link IMap}. @author ztellman
collector
java
lacuna/bifurcan
src/io/lacuna/bifurcan/Maps.java
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/Maps.java
MIT
@Override public Supplier<Map<K, V>> supplier() { return () -> new Map<K, V>().linear(); }
Utility functions for classes implementing {@link IMap}. @author ztellman
supplier
java
lacuna/bifurcan
src/io/lacuna/bifurcan/Maps.java
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/Maps.java
MIT
@Override public BiConsumer<Map<K, V>, T> accumulator() { return (m, e) -> m.put(keyFn.apply(e), valFn.apply(e)); }
Utility functions for classes implementing {@link IMap}. @author ztellman
accumulator
java
lacuna/bifurcan
src/io/lacuna/bifurcan/Maps.java
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/Maps.java
MIT
@Override public BinaryOperator<Map<K, V>> combiner() { return (a, b) -> a.merge(b, mergeFn); }
Utility functions for classes implementing {@link IMap}. @author ztellman
combiner
java
lacuna/bifurcan
src/io/lacuna/bifurcan/Maps.java
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/Maps.java
MIT
@Override public Function<Map<K, V>, Map<K, V>> finisher() { return Map::forked; }
Utility functions for classes implementing {@link IMap}. @author ztellman
finisher
java
lacuna/bifurcan
src/io/lacuna/bifurcan/Maps.java
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/Maps.java
MIT
@Override public java.util.Set<Characteristics> characteristics() { return EnumSet.noneOf(Characteristics.class); }
Utility functions for classes implementing {@link IMap}. @author ztellman
characteristics
java
lacuna/bifurcan
src/io/lacuna/bifurcan/Maps.java
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/Maps.java
MIT
public static Rope from(CharSequence cs) { Object editor = new Object(); Node root = new Node(editor, RopeNodes.SHIFT_INCREMENT); if (cs.length() > 0) { Iterator<byte[]> it = chunks(cs); while (it.hasNext()) { root = root.pushLast(it.next(), editor); } } return new Rope(root, false); }
@return a rope corresponding to {@code cs}
from
java
lacuna/bifurcan
src/io/lacuna/bifurcan/Rope.java
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/Rope.java
MIT
public Rope concat(Rope rope) { return new Rope(root.concat(rope.root, new Object()), isLinear()); }
@return a new Rope with {@code rope} concatenated to the end
concat
java
lacuna/bifurcan
src/io/lacuna/bifurcan/Rope.java
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/Rope.java
MIT
public int nth(int idx) { if (idx < 0 || idx >= size()) { throw new IndexOutOfBoundsException(); } return root.nthPoint(idx); }
@return the nth code point within the rope @throws IndexOutOfBoundsException if {@code idx} is not within {@code [0, size)}
nth
java
lacuna/bifurcan
src/io/lacuna/bifurcan/Rope.java
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/Rope.java
MIT
public int size() { return root.numCodePoints(); }
@return the number of code points in the rope
size
java
lacuna/bifurcan
src/io/lacuna/bifurcan/Rope.java
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/Rope.java
MIT
public Rope remove(int start, int end) { Object editor = isLinear() ? this.editor : new Object(); if (end < start || start < 0 || end > size()) { throw new IllegalArgumentException("[" + start + ", " + end + ") is not a valid range"); } else if (end == start) { return this; } // try to update a single leaf Node newRoot = root.update(0, start, editor, (offset, chunk) -> { int len = UnicodeChunk.numCodePoints(chunk); if (end < offset + len) { return UnicodeChunk.concat( UnicodeChunk.slice(chunk, 0, start - offset), UnicodeChunk.slice(chunk, end - offset, len) ); } else { return null; } }); if (newRoot == null) { newRoot = root.slice(0, start, editor).concat(root.slice(end, size(), editor), editor); } if (isLinear()) { root = newRoot; return this; } else { return new Rope(newRoot, false); } }
@return a rope without the code points within {@code [start, end)} @throws IllegalArgumentException if {@code start} or {@code end} are not within {@code [0, size) }
remove
java
lacuna/bifurcan
src/io/lacuna/bifurcan/Rope.java
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/Rope.java
MIT
private Rope insert(final int index, Iterator<byte[]> chunks, int numCodeUnits) { if (index < 0 || index > size()) { throw new IndexOutOfBoundsException(); } Object editor = isLinear() ? this.editor : new Object(); Node newRoot = null; // can we just update a single leaf node? if (numCodeUnits < MAX_CHUNK_CODE_UNITS) { newRoot = root.update(0, index, editor, (offset, chunk) -> { if (numCodeUnits + UnicodeChunk.numCodeUnits(chunk) <= MAX_CHUNK_CODE_UNITS) { byte[] newChunk = UnicodeChunk.slice(chunk, 0, index - offset); while (chunks.hasNext()) { newChunk = UnicodeChunk.concat(newChunk, chunks.next()); } return UnicodeChunk.concat( newChunk, UnicodeChunk.slice(chunk, index - offset, UnicodeChunk.numCodePoints(chunk)) ); } else { return null; } }); } if (newRoot == null) { newRoot = root.slice(0, index, editor); while (chunks.hasNext()) { newRoot = newRoot.pushLast(chunks.next(), editor); } newRoot = newRoot.concat(root.slice(index, size(), editor), editor); } if (isLinear()) { root = newRoot; return this; } else { return new Rope(newRoot, false); } }
@return a rope without the code points within {@code [start, end)} @throws IllegalArgumentException if {@code start} or {@code end} are not within {@code [0, size) }
insert
java
lacuna/bifurcan
src/io/lacuna/bifurcan/Rope.java
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/Rope.java
MIT
public Rope insert(int idx, Rope rope) { if (rope.size() == 0) { return this; } return insert(idx, rope.chunks(), rope.root.numCodeUnits()); }
@return a new rope with {@code rope} inserted after the first {@code idx} code points
insert
java
lacuna/bifurcan
src/io/lacuna/bifurcan/Rope.java
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/Rope.java
MIT
public Rope insert(int index, CharSequence cs) { if (cs.length() == 0) { return this; } return insert(index, chunks(cs), cs.length()); }
@return a new rope with {@code cs} inserted after the first {@code index} code points
insert
java
lacuna/bifurcan
src/io/lacuna/bifurcan/Rope.java
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/Rope.java
MIT
public Rope slice(int start, int end) { if (end < start || start < 0 || end > size()) { throw new IllegalArgumentException("[" + start + ", " + end + ") is not a valid range"); } return new Rope(root.slice(start, end, new Object()), isLinear()); }
@return a new rope representing the code points within {@code [start, end)} @throws IllegalArgumentException if {@code end} &lt; {@code start}, or {@code start} and {@code end} are not within {@code [0, size)}
slice
java
lacuna/bifurcan
src/io/lacuna/bifurcan/Rope.java
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/Rope.java
MIT
public boolean isLinear() { return editor != null; }
@return a new rope representing the code points within {@code [start, end)} @throws IllegalArgumentException if {@code end} &lt; {@code start}, or {@code start} and {@code end} are not within {@code [0, size)}
isLinear
java
lacuna/bifurcan
src/io/lacuna/bifurcan/Rope.java
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/Rope.java
MIT
public Rope forked() { return isLinear() ? new Rope(root, false) : this; }
@return a new rope representing the code points within {@code [start, end)} @throws IllegalArgumentException if {@code end} &lt; {@code start}, or {@code start} and {@code end} are not within {@code [0, size)}
forked
java
lacuna/bifurcan
src/io/lacuna/bifurcan/Rope.java
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/Rope.java
MIT
public Rope linear() { return isLinear() ? this : new Rope(root, true); }
@return a new rope representing the code points within {@code [start, end)} @throws IllegalArgumentException if {@code end} &lt; {@code start}, or {@code start} and {@code end} are not within {@code [0, size)}
linear
java
lacuna/bifurcan
src/io/lacuna/bifurcan/Rope.java
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/Rope.java
MIT
public Iterator<ByteBuffer> bytes() { return Iterators.map(chunks(), ary -> ByteBuffer.wrap(ary, 2, ary.length - 2).slice()); }
@return a sequence of bytes representing the UTF-8 encoding of the rope
bytes
java
lacuna/bifurcan
src/io/lacuna/bifurcan/Rope.java
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/Rope.java
MIT
public PrimitiveIterator.OfInt reverseChars() { return IntIterators.flatMap(reverseChunks(), UnicodeChunk::reverseCodeUnitIterator); }
@return a sequence of integers representing the UTF-16 code units from back to front
reverseChars
java
lacuna/bifurcan
src/io/lacuna/bifurcan/Rope.java
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/Rope.java
MIT
public PrimitiveIterator.OfInt chars() { return IntIterators.flatMap(chunks(), UnicodeChunk::codeUnitIterator); }
@return a sequence of integers representing the UTF-16 code units from front to back
chars
java
lacuna/bifurcan
src/io/lacuna/bifurcan/Rope.java
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/Rope.java
MIT
public PrimitiveIterator.OfInt reverseCodePoints() { return IntIterators.flatMap(reverseChunks(), UnicodeChunk::reverseCodePointIterator); }
@return a sequence of integers representing the code points from back to front
reverseCodePoints
java
lacuna/bifurcan
src/io/lacuna/bifurcan/Rope.java
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/Rope.java
MIT
public PrimitiveIterator.OfInt codePoints() { return IntIterators.flatMap(chunks(), UnicodeChunk::codePointIterator); }
@return a sequence of integers representing the code points from front to back
codePoints
java
lacuna/bifurcan
src/io/lacuna/bifurcan/Rope.java
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/Rope.java
MIT
@Override public String toString() { char[] cs = new char[root.numCodeUnits()]; Iterator<byte[]> it = chunks(); int offset = 0; while (it.hasNext()) { offset += UnicodeChunk.writeCodeUnits(cs, offset, it.next()); } return new String(cs); }
@return a corresponding Java-style {@code String} in {@code O(N)} time
toString
java
lacuna/bifurcan
src/io/lacuna/bifurcan/Rope.java
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/Rope.java
MIT
public CharSequence toCharSequence() { return new CharSequence() { @Override public int length() { return root.numCodeUnits(); } @Override public char charAt(int index) { return root.nthUnit(index); } @Override public CharSequence subSequence(int start, int end) { return CharSequences.subSequence(this, start, end); } @Override public IntStream chars() { return IntIterators.toStream(Rope.this.chars(), root.numCodeUnits()); } @Override public IntStream codePoints() { return IntIterators.toStream(Rope.this.codePoints(), root.numCodePoints()); } }; }
@return a corresponding Java-style {@link CharSequence} in {@code O(1)} time
toCharSequence
java
lacuna/bifurcan
src/io/lacuna/bifurcan/Rope.java
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/Rope.java
MIT
@Override public int length() { return root.numCodeUnits(); }
@return a corresponding Java-style {@link CharSequence} in {@code O(1)} time
length
java
lacuna/bifurcan
src/io/lacuna/bifurcan/Rope.java
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/Rope.java
MIT
@Override public char charAt(int index) { return root.nthUnit(index); }
@return a corresponding Java-style {@link CharSequence} in {@code O(1)} time
charAt
java
lacuna/bifurcan
src/io/lacuna/bifurcan/Rope.java
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/Rope.java
MIT
@Override public CharSequence subSequence(int start, int end) { return CharSequences.subSequence(this, start, end); }
@return a corresponding Java-style {@link CharSequence} in {@code O(1)} time
subSequence
java
lacuna/bifurcan
src/io/lacuna/bifurcan/Rope.java
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/Rope.java
MIT
@Override public IntStream chars() { return IntIterators.toStream(Rope.this.chars(), root.numCodeUnits()); }
@return a corresponding Java-style {@link CharSequence} in {@code O(1)} time
chars
java
lacuna/bifurcan
src/io/lacuna/bifurcan/Rope.java
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/Rope.java
MIT
@Override public IntStream codePoints() { return IntIterators.toStream(Rope.this.codePoints(), root.numCodePoints()); }
@return a corresponding Java-style {@link CharSequence} in {@code O(1)} time
codePoints
java
lacuna/bifurcan
src/io/lacuna/bifurcan/Rope.java
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/Rope.java
MIT
@Override public int hashCode() { if (hash == -1) { hash = PerlHash.hash(0, bytes()); } return hash; }
@return a corresponding Java-style {@link CharSequence} in {@code O(1)} time
hashCode
java
lacuna/bifurcan
src/io/lacuna/bifurcan/Rope.java
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/Rope.java
MIT
@Override public boolean equals(Object obj) { if (this == obj) { return true; } else if (obj instanceof Rope) { return Ropes.equals(this, (Rope) obj); } else { return false; } }
@return a corresponding Java-style {@link CharSequence} in {@code O(1)} time
equals
java
lacuna/bifurcan
src/io/lacuna/bifurcan/Rope.java
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/Rope.java
MIT
@Override public int compareTo(Rope o) { if (this == o) { return 0; } else if (size() != o.size()) { return size() - o.size(); } else if (size() == 0) { return 0; } else { return Ropes.compare(bytes(), o.bytes()); } }
@return a value representing the lexicographic comparison of the code points
compareTo
java
lacuna/bifurcan
src/io/lacuna/bifurcan/Rope.java
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/Rope.java
MIT
private Iterator<byte[]> reverseChunks() { return new Iterator<byte[]>() { int idx = size() - 1; @Override public boolean hasNext() { return idx > 0; } @Override public byte[] next() { byte[] chunk = root.chunkFor(idx); idx -= UnicodeChunk.numCodePoints(chunk); return chunk; } }; }
@return a value representing the lexicographic comparison of the code points
reverseChunks
java
lacuna/bifurcan
src/io/lacuna/bifurcan/Rope.java
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/Rope.java
MIT
@Override public boolean hasNext() { return idx > 0; }
@return a value representing the lexicographic comparison of the code points
hasNext
java
lacuna/bifurcan
src/io/lacuna/bifurcan/Rope.java
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/Rope.java
MIT
@Override public byte[] next() { byte[] chunk = root.chunkFor(idx); idx -= UnicodeChunk.numCodePoints(chunk); return chunk; }
@return a value representing the lexicographic comparison of the code points
next
java
lacuna/bifurcan
src/io/lacuna/bifurcan/Rope.java
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/Rope.java
MIT
private Iterator<byte[]> chunks() { return new Iterator<byte[]>() { int idx = 0; @Override public boolean hasNext() { return idx < size(); } @Override public byte[] next() { byte[] chunk = root.chunkFor(idx); idx += UnicodeChunk.numCodePoints(chunk); return chunk; } }; }
@return a value representing the lexicographic comparison of the code points
chunks
java
lacuna/bifurcan
src/io/lacuna/bifurcan/Rope.java
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/Rope.java
MIT
@Override public boolean hasNext() { return idx < size(); }
@return a value representing the lexicographic comparison of the code points
hasNext
java
lacuna/bifurcan
src/io/lacuna/bifurcan/Rope.java
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/Rope.java
MIT
@Override public byte[] next() { byte[] chunk = root.chunkFor(idx); idx += UnicodeChunk.numCodePoints(chunk); return chunk; }
@return a value representing the lexicographic comparison of the code points
next
java
lacuna/bifurcan
src/io/lacuna/bifurcan/Rope.java
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/Rope.java
MIT
private static Iterator<byte[]> chunks(CharSequence cs) { return new Iterator<byte[]>() { int offset = 0; @Override public boolean hasNext() { return offset < cs.length(); } @Override public byte[] next() { int start = offset; int end = Math.min(cs.length(), start + MAX_CHUNK_CODE_UNITS); if (end < cs.length() && isHighSurrogate(cs.charAt(end - 1))) { end--; } offset = end; return UnicodeChunk.from(cs, start, end); } }; }
@return a value representing the lexicographic comparison of the code points
chunks
java
lacuna/bifurcan
src/io/lacuna/bifurcan/Rope.java
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/Rope.java
MIT
@Override public boolean hasNext() { return offset < cs.length(); }
@return a value representing the lexicographic comparison of the code points
hasNext
java
lacuna/bifurcan
src/io/lacuna/bifurcan/Rope.java
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/Rope.java
MIT
@Override public byte[] next() { int start = offset; int end = Math.min(cs.length(), start + MAX_CHUNK_CODE_UNITS); if (end < cs.length() && isHighSurrogate(cs.charAt(end - 1))) { end--; } offset = end; return UnicodeChunk.from(cs, start, end); }
@return a value representing the lexicographic comparison of the code points
next
java
lacuna/bifurcan
src/io/lacuna/bifurcan/Rope.java
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/Rope.java
MIT
static int compare(Iterator<ByteBuffer> a, Iterator<ByteBuffer> b) { ByteBuffer x = a.next(); ByteBuffer y = b.next(); for (; ; ) { int len = Math.min(x.remaining(), y.remaining()); for (int k = 0; k < len; k++) { byte bx = x.get(); byte by = y.get(); if (bx != by) { return (bx & 0xFF) - (by & 0xFF); } } if (!x.hasRemaining()) { if (!a.hasNext()) { break; } x = a.next(); } if (!y.hasRemaining()) { y = b.next(); } } return 0; }
lexicographically compares two UTF-8 binary streams by code points, assumes both are of equal length
compare
java
lacuna/bifurcan
src/io/lacuna/bifurcan/Ropes.java
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/Ropes.java
MIT
public static int hash(Rope r) { return PerlHash.hash(0, r.bytes()); }
lexicographically compares two UTF-8 binary streams by code points, assumes both are of equal length
hash
java
lacuna/bifurcan
src/io/lacuna/bifurcan/Ropes.java
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/Ropes.java
MIT
public static boolean equals(Rope a, Rope b) { if (a.size() != b.size()) { return false; } if (a.size() == 0) { return true; } return compare(a.bytes(), b.bytes()) == 0; }
lexicographically compares two UTF-8 binary streams by code points, assumes both are of equal length
equals
java
lacuna/bifurcan
src/io/lacuna/bifurcan/Ropes.java
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/Ropes.java
MIT
public static <V> Set<V> from(ISet<V> s) { if (s instanceof Set) { return ((Set<V>) s).forked(); } else { Set<V> result = new Set<V>(s.valueHash(), s.valueEquality()).linear(); s.forEach(result::add); return result.forked(); } }
@param s a set @return an equivalent set, with the same equality semantics
from
java
lacuna/bifurcan
src/io/lacuna/bifurcan/Set.java
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/Set.java
MIT
public static <V> Set<V> from(Iterator<V> iterator) { Set<V> set = new Set<V>().linear(); iterator.forEachRemaining(set::add); return set.forked(); }
@param iterator an iterator @return a set containing the remaining values in the iterator
from
java
lacuna/bifurcan
src/io/lacuna/bifurcan/Set.java
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/Set.java
MIT
public static <V> Set<V> from(Iterable<V> iterable) { return from(iterable.iterator()); }
@param iterable an {@code Iterable} object @return a set containing the values in the iterator
from
java
lacuna/bifurcan
src/io/lacuna/bifurcan/Set.java
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/Set.java
MIT
public static <V> Set<V> of(V... elements) { Set<V> set = new Set<V>().linear(); for (V e : elements) { set.add(e); } return set.forked(); }
@param iterable an {@code Iterable} object @return a set containing the values in the iterator
of
java
lacuna/bifurcan
src/io/lacuna/bifurcan/Set.java
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/Set.java
MIT
public static <V> Set<V> empty() { return (Set<V>) EMPTY; }
@param hashFn the hash function used by the set @param equalsFn the equality semantics used by the set
empty
java
lacuna/bifurcan
src/io/lacuna/bifurcan/Set.java
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/Set.java
MIT
@Override public boolean isLinear() { return map.isLinear(); }
@param hashFn the hash function used by the set @param equalsFn the equality semantics used by the set
isLinear
java
lacuna/bifurcan
src/io/lacuna/bifurcan/Set.java
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/Set.java
MIT
@Override public ToLongFunction<V> valueHash() { return map.keyHash(); }
@param hashFn the hash function used by the set @param equalsFn the equality semantics used by the set
valueHash
java
lacuna/bifurcan
src/io/lacuna/bifurcan/Set.java
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/Set.java
MIT
@Override public BiPredicate<V, V> valueEquality() { return map.keyEquality(); }
@param hashFn the hash function used by the set @param equalsFn the equality semantics used by the set
valueEquality
java
lacuna/bifurcan
src/io/lacuna/bifurcan/Set.java
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/Set.java
MIT
@Override public boolean contains(V value) { return map.contains(value); }
@param hashFn the hash function used by the set @param equalsFn the equality semantics used by the set
contains
java
lacuna/bifurcan
src/io/lacuna/bifurcan/Set.java
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/Set.java
MIT
@Override public long size() { return map.size(); }
@param hashFn the hash function used by the set @param equalsFn the equality semantics used by the set
size
java
lacuna/bifurcan
src/io/lacuna/bifurcan/Set.java
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/Set.java
MIT
@Override public OptionalLong indexOf(V element) { return map.indexOf(element); }
@param hashFn the hash function used by the set @param equalsFn the equality semantics used by the set
indexOf
java
lacuna/bifurcan
src/io/lacuna/bifurcan/Set.java
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/Set.java
MIT
@Override public V nth(long idx) { return map.nth(idx).key(); }
@param hashFn the hash function used by the set @param equalsFn the equality semantics used by the set
nth
java
lacuna/bifurcan
src/io/lacuna/bifurcan/Set.java
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/Set.java
MIT
@Override public Set<V> add(V value) { return add(value, isLinear() ? map.editor : new Object()); }
@param hashFn the hash function used by the set @param equalsFn the equality semantics used by the set
add
java
lacuna/bifurcan
src/io/lacuna/bifurcan/Set.java
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/Set.java
MIT
public Set<V> add(V value, Object editor) { Map<V, Void> mapPrime = map.put(value, null, (BinaryOperator<Void>) Maps.MERGE_LAST_WRITE_WINS, editor); if (map == mapPrime) { hash = -1; return this; } else { return new Set<>(mapPrime); } }
@param hashFn the hash function used by the set @param equalsFn the equality semantics used by the set
add
java
lacuna/bifurcan
src/io/lacuna/bifurcan/Set.java
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/Set.java
MIT
@Override public Set<V> remove(V value) { return remove(value, isLinear() ? map.editor : new Object()); }
@param hashFn the hash function used by the set @param equalsFn the equality semantics used by the set
remove
java
lacuna/bifurcan
src/io/lacuna/bifurcan/Set.java
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/Set.java
MIT
public Set<V> remove(V value, Object editor) { Map<V, Void> mapPrime = map.remove(value, editor); if (map == mapPrime) { hash = -1; return this; } else { return new Set<>(mapPrime); } }
@param hashFn the hash function used by the set @param equalsFn the equality semantics used by the set
remove
java
lacuna/bifurcan
src/io/lacuna/bifurcan/Set.java
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/Set.java
MIT
@Override public List<Set<V>> split(int parts) { return map.split(parts).stream().map(m -> new Set<V>(m)).collect(Lists.collector()); }
@param hashFn the hash function used by the set @param equalsFn the equality semantics used by the set
split
java
lacuna/bifurcan
src/io/lacuna/bifurcan/Set.java
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/Set.java
MIT
@Override public Iterator<V> iterator() { return Iterators.map(map.iterator(), IEntry::key); }
@param hashFn the hash function used by the set @param equalsFn the equality semantics used by the set
iterator
java
lacuna/bifurcan
src/io/lacuna/bifurcan/Set.java
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/Set.java
MIT
@Override public <U> Map<V, U> zip(Function<V, U> f) { return map.mapValues((k, v) -> f.apply(k)).forked(); }
@param hashFn the hash function used by the set @param equalsFn the equality semantics used by the set
zip
java
lacuna/bifurcan
src/io/lacuna/bifurcan/Set.java
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/Set.java
MIT
@Override public Set<V> union(ISet<V> s) { if (s instanceof Set) { return new Set<V>(map.union(((Set<V>) s).map)); } else { return (Set<V>) Sets.union(this, s); } }
@param hashFn the hash function used by the set @param equalsFn the equality semantics used by the set
union
java
lacuna/bifurcan
src/io/lacuna/bifurcan/Set.java
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/Set.java
MIT
@Override public Set<V> difference(ISet<V> s) { if (s instanceof Set) { return new Set<V>(map.difference(((Set<V>) s).map)); } else { return (Set<V>) Sets.difference(this, s); } }
@param hashFn the hash function used by the set @param equalsFn the equality semantics used by the set
difference
java
lacuna/bifurcan
src/io/lacuna/bifurcan/Set.java
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/Set.java
MIT
@Override public Set<V> intersection(ISet<V> s) { if (s instanceof Set) { return new Set<V>(map.intersection(((Set<V>) s).map)); } else { return (Set<V>) Sets.intersection(new Set<V>().linear(), this, s).forked(); } }
@param hashFn the hash function used by the set @param equalsFn the equality semantics used by the set
intersection
java
lacuna/bifurcan
src/io/lacuna/bifurcan/Set.java
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/Set.java
MIT
@Override public Set<V> forked() { return map.isLinear() ? new Set<V>(map.forked()) : this; }
@param hashFn the hash function used by the set @param equalsFn the equality semantics used by the set
forked
java
lacuna/bifurcan
src/io/lacuna/bifurcan/Set.java
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/Set.java
MIT
@Override public Set<V> linear() { return map.isLinear() ? this : new Set<V>(map.linear()); }
@param hashFn the hash function used by the set @param equalsFn the equality semantics used by the set
linear
java
lacuna/bifurcan
src/io/lacuna/bifurcan/Set.java
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/Set.java
MIT
@Override public boolean equals(Object obj) { if (obj instanceof Set) { return ((Map) map).equals(((Set) obj).map, (BiPredicate<Object, Object>) (a, b) -> true); } else if (obj instanceof ISet) { return Sets.equals(this, (ISet<V>) obj); } else { return false; } }
@param hashFn the hash function used by the set @param equalsFn the equality semantics used by the set
equals
java
lacuna/bifurcan
src/io/lacuna/bifurcan/Set.java
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/Set.java
MIT
@Override public Set<V> clone() { return new Set<>(map.clone()); }
@param hashFn the hash function used by the set @param equalsFn the equality semantics used by the set
clone
java
lacuna/bifurcan
src/io/lacuna/bifurcan/Set.java
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/Set.java
MIT
public static <V> long hash(ISet<V> s) { return hash(s, x -> s.valueHash().applyAsLong(x), Long::sum); }
Utility functions for classes implementing {@code ISet}. @author ztellman
hash
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> long hash(ISet<V> set, ToLongFunction<V> hash, LongBinaryOperator combiner) { return set.elements().stream().mapToLong(hash).reduce(combiner).orElse(0); }
Utility functions for classes implementing {@code ISet}. @author ztellman
hash
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> boolean equals(ISet<V> a, ISet<V> b) { if (a.size() != b.size()) { return false; } else if (a == b) { return true; } return a.elements().stream().allMatch(b::contains); }
Utility functions for classes implementing {@code ISet}. @author ztellman
equals
java
lacuna/bifurcan
src/io/lacuna/bifurcan/Sets.java
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/Sets.java
MIT
static <V> ISet<V> difference(ISet<V> a, ISet<V> b) { for (V e : b) { a = a.remove(e); } return a; }
Utility functions for classes implementing {@code ISet}. @author ztellman
difference
java
lacuna/bifurcan
src/io/lacuna/bifurcan/Sets.java
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/Sets.java
MIT
static <V> ISet<V> union(ISet<V> a, ISet<V> b) { for (V e : b) { a = a.add(e); } return a; }
Utility functions for classes implementing {@code ISet}. @author ztellman
union
java
lacuna/bifurcan
src/io/lacuna/bifurcan/Sets.java
https://github.com/lacuna/bifurcan/blob/master/src/io/lacuna/bifurcan/Sets.java
MIT
static <V> ISet<V> intersection(ISet<V> accumulator, ISet<V> a, ISet<V> b) { if (b.size() < a.size()) { return intersection(accumulator, b, a); } for (V e : a) { if (b.contains(e)) { accumulator = accumulator.add(e); } } return accumulator; }
Utility functions for classes implementing {@code ISet}. @author ztellman
intersection
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> java.util.Set<V> toSet(IList<V> elements, Predicate<V> contains) { return new java.util.Set<V>() { @Override public int size() { return (int) elements.size(); } @Override public boolean isEmpty() { return elements.size() == 0; } @Override public boolean contains(Object o) { return contains.test((V) o); } @Override public Iterator<V> iterator() { return elements.iterator(); } @Override public Object[] toArray() { return elements.toArray(); } @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; } @Override public boolean add(V v) { return false; } @Override public boolean remove(Object o) { return false; } @Override public boolean containsAll(Collection<?> c) { return c.stream().allMatch(this::contains); } @Override public boolean addAll(Collection<? extends V> c) { throw new UnsupportedOperationException(); } @Override public boolean retainAll(Collection<?> c) { throw new UnsupportedOperationException(); } @Override public boolean removeAll(Collection<?> c) { throw new UnsupportedOperationException(); } @Override public void clear() { throw new UnsupportedOperationException(); } }; }
Utility functions for classes implementing {@code ISet}. @author ztellman
toSet
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 int size() { return (int) 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