Skip to content

Commit

Permalink
Replace calls to RevTree.buckets() by RevTree.getBuckets()
Browse files Browse the repository at this point in the history
Replace calls to RevTree.buckets():ImmutableSortedMap<Integer, Bucket>
(now deprecated and scheduled to be removed soon)
by RevTree.getBuckets():Iterable<Buckets>

Signed-off-by: Gabriel Roldan <gabriel.roldan@gmail.com>
  • Loading branch information
groldan committed Dec 4, 2018
1 parent 990d22e commit 43d6dce
Show file tree
Hide file tree
Showing 40 changed files with 256 additions and 218 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
* a pointer to the {@link RevTree}s it's parent tree is split into when the builder's imposed split
* threshold is surpassed.
*
* @see RevTree#buckets()
* @see RevTree#getBuckets()
* @since 1.0
*/
public abstract class Bucket implements Bounded, Comparable<Bucket> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
Expand Down Expand Up @@ -100,21 +101,37 @@ public static void feature(PrimitiveSink into, List<Object> values) {
* @param buckets the tree's {@link RevTree#trees() contained bucket pointers}
*/
public static void tree(PrimitiveSink into, List<Node> trees, List<Node> features,
SortedMap<Integer, Bucket> buckets) {
Iterable<Bucket> buckets) {
checkNotNull(into);
checkNotNull(trees);
checkNotNull(features);
checkNotNull(buckets);
TreeFunnel.INSTANCE.funnel(into, trees, features, buckets);
}

@Deprecated
public static ObjectId hashTree(@Nullable List<Node> trees, @Nullable List<Node> features,
@Nullable SortedMap<Integer, Bucket> buckets) {

final Hasher hasher = ObjectId.HASH_FUNCTION.newHasher();
trees = trees == null ? ImmutableList.of() : trees;
features = features == null ? ImmutableList.of() : features;
buckets = buckets == null ? ImmutableSortedMap.of() : buckets;
HashObjectFunnels.tree(hasher, trees, features, buckets.values());

final byte[] rawKey = hasher.hash().asBytes();
final ObjectId id = ObjectId.create(rawKey);

return id;
}

public static ObjectId hashTree(@Nullable List<Node> trees, @Nullable List<Node> features,
@Nullable Iterable<Bucket> buckets) {

final Hasher hasher = ObjectId.HASH_FUNCTION.newHasher();
trees = trees == null ? ImmutableList.of() : trees;
features = features == null ? ImmutableList.of() : features;
buckets = buckets == null ? Collections.emptySet() : buckets;
HashObjectFunnels.tree(hasher, trees, features, buckets);

final byte[] rawKey = hasher.hash().asBytes();
Expand Down Expand Up @@ -228,28 +245,41 @@ private static final class TreeFunnel implements Funnel<RevTree> {
@Override
public void funnel(RevTree from, PrimitiveSink into) {
RevObjectTypeFunnel.funnel(TYPE.TREE, into);
from.forEachTree((n) -> NodeFunnel.funnel(n, into));
from.forEachFeature((n) -> NodeFunnel.funnel(n, into));
from.forEachTree(n -> NodeFunnel.funnel(n, into));
from.forEachFeature(n -> NodeFunnel.funnel(n, into));

from.forEachBucket(bucket -> {
Funnels.integerFunnel().funnel(bucket.getIndex(), into);
ObjectIdFunnel.funnel(bucket.getObjectId(), into);
});
}

@Deprecated
public void funnel(PrimitiveSink into, List<Node> trees, List<Node> features,
SortedMap<Integer, Bucket> buckets) {

RevObjectTypeFunnel.funnel(TYPE.TREE, into);
trees.forEach((n) -> NodeFunnel.funnel(n, into));
features.forEach((n) -> NodeFunnel.funnel(n, into));
trees.forEach(n -> NodeFunnel.funnel(n, into));
features.forEach(n -> NodeFunnel.funnel(n, into));

for (Entry<Integer, Bucket> entry : buckets.entrySet()) {
Funnels.integerFunnel().funnel(entry.getKey(), into);
ObjectIdFunnel.funnel(entry.getValue().getObjectId(), into);
}
}
};

public void funnel(PrimitiveSink into, List<Node> trees, List<Node> features,
Iterable<Bucket> buckets) {

RevObjectTypeFunnel.funnel(TYPE.TREE, into);
trees.forEach(n -> NodeFunnel.funnel(n, into));
features.forEach(n -> NodeFunnel.funnel(n, into));
buckets.forEach(b -> {
Funnels.integerFunnel().funnel(b.getIndex(), into);
ObjectIdFunnel.funnel(b.getObjectId(), into);
});
}
}

private static final class FeatureFunnel implements Funnel<RevFeature> {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

import java.util.List;
import java.util.Map;
import java.util.SortedMap;
import java.util.SortedSet;

import org.eclipse.jdt.annotation.Nullable;
Expand Down Expand Up @@ -56,10 +55,6 @@ public static RevObjectFactory defaultInstance() {
public @NonNull RevTree createTree(@NonNull ObjectId id, long size, @NonNull List<Node> trees,
@NonNull List<Node> features);

@Deprecated
public @NonNull RevTree createTree(@NonNull ObjectId id, long size, int childTreeCount,
@NonNull SortedMap<Integer, Bucket> buckets);

public @NonNull RevTree createTree(@NonNull ObjectId id, long size, int childTreeCount,
@NonNull SortedSet<Bucket> buckets);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
* capacity of it's feature or tree lists has been surpased.
* <p>
* The {@link #getId() id} of a {@code RevTree} is computed out of its directly contained
* {@link RevTree#trees() tree}, {@link RevTree#features() feature}, and {@link RevTree#buckets()
* {@link RevTree#trees() tree}, {@link RevTree#features() feature}, and {@link RevTree#getBuckets()
* bucket} pointers as mandated by {@link HashObjectFunnels}.
* <p>
* Two trees that contain the same values hash out to the same {@link ObjectId}, as long as they
Expand Down Expand Up @@ -80,7 +80,7 @@ public interface RevTree extends RevObject {
* The empty tree object id, as results from calling {@link HashObjectFunnels#hashTree
* HashObjectFunnels.hashTree} with empty arguments.
*/
ObjectId EMPTY_TREE_ID = HashObjectFunnels.hashTree(null, null, null);
ObjectId EMPTY_TREE_ID = HashObjectFunnels.hashTree(null, null, (Iterable<Bucket>) null);

/**
* A "null object" to represent the empty tree
Expand Down Expand Up @@ -177,7 +177,7 @@ public default TYPE getType() {
* nodes)
*/
public default boolean isEmpty() {
boolean empty = trees().isEmpty() && features().isEmpty() && buckets().isEmpty();
boolean empty = treesSize() == 0 && featuresSize() == 0 && bucketsSize() == 0;
if (empty) {
Preconditions.checkState(size() == 0L);
Preconditions.checkState(EMPTY_TREE_ID.equals(getId()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@
import java.util.List;
import java.util.Map;
import java.util.ServiceLoader;
import java.util.SortedMap;
import java.util.SortedSet;
import java.util.TreeSet;

import org.eclipse.jdt.annotation.Nullable;
import org.locationtech.geogig.model.Bucket;
Expand Down Expand Up @@ -76,13 +74,6 @@ public class RevObjectFactoryImpl implements RevObjectFactory {
return new LeafTree(id, size, f, t);
}

@Deprecated
public @Override @NonNull RevTree createTree(final @NonNull ObjectId id, final long size,
final int childTreeCount, @NonNull SortedMap<Integer, Bucket> buckets) {

return new NodeTree(id, size, childTreeCount, new TreeSet<>(buckets.values()));
}

public @Override @NonNull RevTree createTree(final @NonNull ObjectId id, final long size,
final int childTreeCount, @NonNull SortedSet<Bucket> buckets) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import java.util.concurrent.ForkJoinWorkerThread;
import java.util.concurrent.RecursiveAction;

import org.locationtech.geogig.model.Bucket;
import org.locationtech.geogig.model.ObjectId;
import org.locationtech.geogig.model.RevTree;
import org.locationtech.geogig.repository.IndexInfo;
Expand Down Expand Up @@ -156,7 +157,7 @@ public TreeCopyTask(RevTree tree, IndexDatabase src, IndexDatabase target) {
if (tree.bucketsSize() > 0) {
Iterable<ObjectId> bucketIds;
Iterator<RevTree> buckets;
bucketIds = Iterables.transform(tree.buckets().values(), b -> b.getObjectId());
bucketIds = Iterables.transform(tree.getBuckets(), Bucket::getObjectId);
buckets = src.getAll(bucketIds, BulkOpListener.NOOP_LISTENER, RevTree.class);
while (buckets.hasNext()) {
RevTree bucket = buckets.next();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ public ImmutableSortedMap<Integer, Bucket> buckets() {

@Override
public Iterable<Bucket> getBuckets() {
return Collections.emptySet();
return buckets.values();
}
};

Expand Down Expand Up @@ -244,7 +244,7 @@ public Iterable<Bucket> getBuckets() {

assertEquals(treeHash, id2);

ObjectId treeHash2 = HashObjectFunnels.hashTree(null, null, null);
ObjectId treeHash2 = HashObjectFunnels.hashTree(null, null, (Iterable<Bucket>) null);

assertEquals(treeHash2, id1);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public ImmutableSortedMap<Integer, Bucket> buckets() {

@Override
public Iterable<Bucket> getBuckets() {
return Collections.emptySet();
return buckets.values();
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.stream.Collectors;

import org.locationtech.geogig.di.CanRunDuringConflict;
import org.locationtech.geogig.model.Bucket;
import org.locationtech.geogig.model.Node;
import org.locationtech.geogig.model.NodeRef;
import org.locationtech.geogig.model.ObjectId;
Expand All @@ -28,6 +28,7 @@

import com.google.common.base.Optional;
import com.google.common.base.Preconditions;
import com.google.common.collect.Iterables;

/**
*
Expand Down Expand Up @@ -84,8 +85,8 @@ private List<NodeRef> getSubTrees(RevTree tree, String parentPath) {
subtrees.addAll(toNodeRef(tree.trees(), parentPath));
}
if (tree.bucketsSize() > 0) {
List<ObjectId> bucketIds = tree.buckets().values().stream().map(b -> b.getObjectId())
.collect(Collectors.toList());
Iterable<ObjectId> bucketIds = Iterables.transform(tree.getBuckets(),
Bucket::getObjectId);
Iterator<RevTree> bucketTrees = source.getAll(bucketIds, BulkOpListener.NOOP_LISTENER,
RevTree.class);
bucketTrees
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import java.util.Set;
import java.util.SortedMap;
import java.util.TreeMap;
import java.util.TreeSet;
import java.util.function.BooleanSupplier;

import org.eclipse.jdt.annotation.Nullable;
Expand Down Expand Up @@ -50,7 +51,6 @@
import com.google.common.collect.ArrayListMultimap;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.ImmutableSortedMap;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.google.common.collect.Multimap;
Expand Down Expand Up @@ -172,18 +172,18 @@ private LegacyTreeBuilder(final ObjectStore obSotre, @Nullable final RevTree cop
this.initialNumTrees = copy.numTrees();

if (!copy.trees().isEmpty()) {
checkArgument(copy.buckets().isEmpty());
checkArgument(0 == copy.bucketsSize());
for (Node node : copy.trees()) {
putInternal(node);
}
}
if (!copy.features().isEmpty()) {
checkArgument(copy.buckets().isEmpty());
checkArgument(0 == copy.bucketsSize());
for (Node node : copy.features()) {
putInternal(node);
}
}
if (!copy.buckets().isEmpty()) {
if (copy.bucketsSize() > 0) {
checkArgument(copy.features().isEmpty());
bucketTreesByBucket.putAll(copy.buckets());
}
Expand Down Expand Up @@ -378,19 +378,18 @@ public static RevTree createLeafTree(long size, Collection<Node> features,
treesList = NODE_STORAGE_ORDER.immutableSortedCopy(trees);
}

final ObjectId id = HashObject.hashTree(treesList, featuresList, null);
final ObjectId id = HashObject.hashTree(treesList, featuresList, (Iterable<Bucket>) null);

return RevObjectFactory.defaultInstance().createTree(id, size, treesList, featuresList);
}

private RevTree createNodeTree(long size, int numTrees,
@NonNull SortedMap<Integer, Bucket> buckets) {

ImmutableSortedMap<Integer, Bucket> innerTrees = ImmutableSortedMap.copyOf(buckets);
final ObjectId id = HashObject.hashTree(null, null, buckets.values());

final ObjectId id = HashObject.hashTree(null, null, innerTrees);

return RevObjectFactory.defaultInstance().createTree(id, size, numTrees, innerTrees);
return RevObjectFactory.defaultInstance().createTree(id, size, numTrees,
new TreeSet<>(buckets.values()));
}

private long sizeOf(Node node) {
Expand Down Expand Up @@ -629,8 +628,8 @@ public RevTree build() {
}

ObjectId oldid = HashObject.hashTree(original.trees(), original.features(),
original.buckets());
ObjectId newid = HashObject.hashTree(tree.trees(), tree.features(), tree.buckets());
original.getBuckets());
ObjectId newid = HashObject.hashTree(tree.trees(), tree.features(), tree.getBuckets());

return oldid.equals(newid) ? original : tree;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
import java.util.Collections;
import java.util.List;
import java.util.SortedMap;
import java.util.SortedSet;
import java.util.TreeSet;
import java.util.function.BooleanSupplier;

import org.eclipse.jdt.annotation.Nullable;
Expand Down Expand Up @@ -93,13 +95,22 @@ public interface RevTreeBuilder {

public void dispose();

@Deprecated
static RevTree build(final long size, final int childTreeCount, @Nullable List<Node> trees,
@Nullable List<Node> features, @Nullable SortedMap<Integer, Bucket> buckets) {

ObjectId id = HashObject.hashTree(trees, features, buckets);
SortedSet<Bucket> b = buckets == null ? Collections.emptySortedSet()
: new TreeSet<>(buckets.values());
return build(size, childTreeCount, trees, features, b);
}

static RevTree build(final long size, final int childTreeCount, @Nullable List<Node> trees,
@Nullable List<Node> features, @Nullable SortedSet<Bucket> buckets) {

trees = trees == null ? Collections.emptyList() : trees;
features = features == null ? Collections.emptyList() : features;
buckets = buckets == null ? Collections.emptySortedMap() : buckets;
buckets = buckets == null ? Collections.emptySortedSet() : buckets;
ObjectId id = HashObject.hashTree(trees, features, buckets);

if (buckets.isEmpty()) {
return RevObjectFactory.defaultInstance().createTree(id, size, trees, features);
Expand Down
Loading

0 comments on commit 43d6dce

Please sign in to comment.