protected TreeBuilder newObject(Handle handle) { return new TreeBuilder(handle); } };
/** * Returns a new BTree with the provided collection inserting/replacing as necessary any equal items * * @param btree the tree to update * @param comparator the comparator that defines the ordering over the items in the tree * @param updateWith the items to either insert / update. MUST BE IN STRICTLY ASCENDING ORDER. * @param updateWithLength then number of elements in updateWith * @param updateF the update function to apply to any pairs we are swapping, and maybe abort early * @param <V> * @return */ public static <C, K extends C, V extends C> Object[] update(Object[] btree, Comparator<C> comparator, Iterable<K> updateWith, int updateWithLength, UpdateFunction<K, V> updateF) { if (isEmpty(btree)) return build(updateWith, updateWithLength, updateF); TreeBuilder builder = TreeBuilder.newInstance(); btree = builder.update(btree, comparator, updateWith, updateF); return btree; }
/** * As build(), except: * @param size < 0 if size is unknown */ private static <C, K extends C, V extends C> Object[] buildInternal(Iterable<K> source, int size, UpdateFunction<K, V> updateF) { if ((size >= 0) & (size < FAN_FACTOR)) { if (size == 0) return EMPTY_LEAF; // pad to odd length to match contract that all leaf nodes are odd V[] values = (V[]) new Object[size | 1]; { int i = 0; for (K k : source) values[i++] = updateF.apply(k); } if (updateF != UpdateFunction.noOp()) updateF.allocated(ObjectSizes.sizeOfArray(values)); return values; } TreeBuilder builder = TreeBuilder.newInstance(); Object[] btree = builder.build(source, updateF, size); return btree; }
/** * Returns a new BTree with the provided collection inserting/replacing as necessary any equal items * * @param btree the tree to update * @param comparator the comparator that defines the ordering over the items in the tree * @param updateWith the items to either insert / update. MUST BE IN STRICTLY ASCENDING ORDER. * @param updateWithLength then number of elements in updateWith * @param updateF the update function to apply to any pairs we are swapping, and maybe abort early * @param <V> * @return */ public static <C, K extends C, V extends C> Object[] update(Object[] btree, Comparator<C> comparator, Iterable<K> updateWith, int updateWithLength, UpdateFunction<K, V> updateF) { if (isEmpty(btree)) return build(updateWith, updateWithLength, updateF); TreeBuilder builder = TreeBuilder.newInstance(); btree = builder.update(btree, comparator, updateWith, updateF); return btree; }
/** * As build(), except: * @param size < 0 if size is unknown */ private static <C, K extends C, V extends C> Object[] buildInternal(Iterable<K> source, int size, UpdateFunction<K, V> updateF) { if ((size >= 0) & (size < FAN_FACTOR)) { if (size == 0) return EMPTY_LEAF; // pad to odd length to match contract that all leaf nodes are odd V[] values = (V[]) new Object[size | 1]; { int i = 0; for (K k : source) values[i++] = updateF.apply(k); } if (updateF != UpdateFunction.noOp()) updateF.allocated(ObjectSizes.sizeOfArray(values)); return values; } TreeBuilder builder = TreeBuilder.newInstance(); Object[] btree = builder.build(source, updateF, size); return btree; }
/** * Returns a new BTree with the provided collection inserting/replacing as necessary any equal items * * @param btree the tree to update * @param comparator the comparator that defines the ordering over the items in the tree * @param updateWith the items to either insert / update. MUST BE IN STRICTLY ASCENDING ORDER. * @param updateWithLength then number of elements in updateWith * @param updateF the update function to apply to any pairs we are swapping, and maybe abort early * @param <V> * @return */ public static <C, K extends C, V extends C> Object[] update(Object[] btree, Comparator<C> comparator, Iterable<K> updateWith, int updateWithLength, UpdateFunction<K, V> updateF) { if (isEmpty(btree)) return build(updateWith, updateWithLength, updateF); TreeBuilder builder = TreeBuilder.newInstance(); btree = builder.update(btree, comparator, updateWith, updateF); return btree; }
/** * As build(), except: * @param size < 0 if size is unknown */ private static <C, K extends C, V extends C> Object[] buildInternal(Iterable<K> source, int size, UpdateFunction<K, V> updateF) { if ((size >= 0) & (size < FAN_FACTOR)) { if (size == 0) return EMPTY_LEAF; // pad to odd length to match contract that all leaf nodes are odd V[] values = (V[]) new Object[size | 1]; { int i = 0; for (K k : source) values[i++] = updateF.apply(k); } if (updateF != UpdateFunction.noOp()) updateF.allocated(ObjectSizes.sizeOfArray(values)); return values; } TreeBuilder builder = TreeBuilder.newInstance(); Object[] btree = builder.build(source, updateF, size); return btree; }
protected TreeBuilder newObject(Handle handle) { return new TreeBuilder(handle); } };
/** * Returns a new BTree with the provided collection inserting/replacing as necessary any equal items * * @param btree the tree to update * @param comparator the comparator that defines the ordering over the items in the tree * @param updateWith the items to either insert / update. MUST BE IN STRICTLY ASCENDING ORDER. * @param updateWithLength then number of elements in updateWith * @param updateF the update function to apply to any pairs we are swapping, and maybe abort early * @param <V> * @return */ public static <C, K extends C, V extends C> Object[] update(Object[] btree, Comparator<C> comparator, Iterable<K> updateWith, int updateWithLength, UpdateFunction<K, V> updateF) { if (isEmpty(btree)) return build(updateWith, updateWithLength, updateF); TreeBuilder builder = TreeBuilder.newInstance(); btree = builder.update(btree, comparator, updateWith, updateF); return btree; }
/** * As build(), except: * @param size < 0 if size is unknown */ private static <C, K extends C, V extends C> Object[] buildInternal(Iterable<K> source, int size, UpdateFunction<K, V> updateF) { if ((size >= 0) & (size < FAN_FACTOR)) { if (size == 0) return EMPTY_LEAF; // pad to odd length to match contract that all leaf nodes are odd V[] values = (V[]) new Object[size | 1]; { int i = 0; for (K k : source) values[i++] = updateF.apply(k); } if (updateF != UpdateFunction.noOp()) updateF.allocated(ObjectSizes.sizeOfArray(values)); return values; } TreeBuilder builder = TreeBuilder.newInstance(); Object[] btree = builder.build(source, updateF, size); return btree; }
protected TreeBuilder newObject(Handle handle) { return new TreeBuilder(handle); } };
protected TreeBuilder newObject(Handle handle) { return new TreeBuilder(handle); } };