Skip to content
Snippets Groups Projects
Verified Commit a1afa79d authored by David Procházka's avatar David Procházka
Browse files

DEL: distance computation, unused contains method

parent 9531e93e
No related branches found
No related tags found
No related merge requests found
...@@ -22,7 +22,7 @@ public class InternalNode extends Node implements Serializable { ...@@ -22,7 +22,7 @@ public class InternalNode extends Node implements Serializable {
children = new HashSet<>(); children = new HashSet<>();
} }
public void addChildren(Set<Node> children) { public void addChildren(List<Node> children) {
this.children.addAll(children); this.children.addAll(children);
} }
...@@ -48,10 +48,6 @@ public class InternalNode extends Node implements Serializable { ...@@ -48,10 +48,6 @@ public class InternalNode extends Node implements Serializable {
.collect(Collectors.toSet()); .collect(Collectors.toSet());
} }
public boolean contains(LocalAbstractObject object) {
return children.stream().anyMatch(child -> child.contains(object));
}
public int getHeight() { public int getHeight() {
return children.stream() return children.stream()
.mapToInt(Node::getHeight) .mapToInt(Node::getHeight)
...@@ -59,12 +55,12 @@ public class InternalNode extends Node implements Serializable { ...@@ -59,12 +55,12 @@ public class InternalNode extends Node implements Serializable {
.getMax() + 1; .getMax() + 1;
} }
public Set<Node> getNodesOnLevel(int level) { public List<Node> getNodesOnLevel(int level) {
if (getLevel() == level) return Collections.singleton(this); if (getLevel() == level) return Collections.singletonList(this);
return children.stream() return children.stream()
.map(child -> child.getNodesOnLevel(level)) .map(child -> child.getNodesOnLevel(level))
.flatMap(Collection::stream) .flatMap(Collection::stream)
.collect(Collectors.toSet()); .collect(Collectors.toList());
} }
} }
...@@ -9,6 +9,7 @@ import messif.objects.util.AbstractObjectIterator; ...@@ -9,6 +9,7 @@ import messif.objects.util.AbstractObjectIterator;
import java.io.Serializable; import java.io.Serializable;
import java.util.Collections; import java.util.Collections;
import java.util.HashSet; import java.util.HashSet;
import java.util.List;
import java.util.Set; import java.util.Set;
public class LeafNode extends Node implements Serializable { public class LeafNode extends Node implements Serializable {
...@@ -41,19 +42,11 @@ public class LeafNode extends Node implements Serializable { ...@@ -41,19 +42,11 @@ public class LeafNode extends Node implements Serializable {
return objects; return objects;
} }
public boolean contains(LocalAbstractObject object) {
for (AbstractObjectIterator<LocalAbstractObject> it = bucket.getAllObjects(); it.hasNext(); )
if (object == it.next())
return true;
return false;
}
public int getHeight() { public int getHeight() {
return 0; return 0;
} }
public Set<Node> getNodesOnLevel(int level) { public List<Node> getNodesOnLevel(int level) {
return Collections.singleton(this); return Collections.singletonList(this);
} }
} }
...@@ -18,9 +18,8 @@ public abstract class Node implements Serializable { ...@@ -18,9 +18,8 @@ public abstract class Node implements Serializable {
* Serialization ID * Serialization ID
*/ */
private static final long serialVersionUID = 420L; private static final long serialVersionUID = 420L;
private final ObjectToNodeDistance objectToNodeDistance;
protected final InsertType insertType; protected final InsertType insertType;
private final ObjectToNodeDistance objectToNodeDistance;
protected HullOptimizedRepresentationV3 hull; protected HullOptimizedRepresentationV3 hull;
protected Node parent; protected Node parent;
...@@ -31,7 +30,7 @@ public abstract class Node implements Serializable { ...@@ -31,7 +30,7 @@ public abstract class Node implements Serializable {
this.objectToNodeDistance = objectToNodeDistance; this.objectToNodeDistance = objectToNodeDistance;
} }
public static InternalNode createParent(Set<Node> nodes, PrecomputedDistances distances, InsertType insertType, ObjectToNodeDistance objectToNodeDistance) { public static InternalNode createParent(List<Node> nodes, PrecomputedDistances distances, InsertType insertType, ObjectToNodeDistance objectToNodeDistance) {
List<LocalAbstractObject> objects = nodes.stream() List<LocalAbstractObject> objects = nodes.stream()
.map(Node::getObjects) .map(Node::getObjects)
.flatMap(Collection::stream) .flatMap(Collection::stream)
...@@ -41,14 +40,11 @@ public abstract class Node implements Serializable { ...@@ -41,14 +40,11 @@ public abstract class Node implements Serializable {
} }
public double getDistance(LocalAbstractObject object) { public double getDistance(LocalAbstractObject object) {
switch (objectToNodeDistance) { return objectToNodeDistance.getDistance(object, this);
case FURTHEST_HULL_OBJECT: }
return getFurthestDistance(object);
case AVERAGE_DISTANCE: public double getNearestDistance(LocalAbstractObject object) {
return getAverageDistance(object); return ObjectToNodeDistance.NEAREST_HULL_OBJECT.getDistance(object, this);
default:
return getNearestDistance(object);
}
} }
public boolean isCovered(LocalAbstractObject object) { public boolean isCovered(LocalAbstractObject object) {
...@@ -80,11 +76,9 @@ public abstract class Node implements Serializable { ...@@ -80,11 +76,9 @@ public abstract class Node implements Serializable {
public abstract Set<LocalAbstractObject> getObjects(); public abstract Set<LocalAbstractObject> getObjects();
public abstract boolean contains(LocalAbstractObject object);
public abstract int getHeight(); public abstract int getHeight();
public abstract Set<Node> getNodesOnLevel(int level); public abstract List<Node> getNodesOnLevel(int level);
protected void rebuildHull(LocalAbstractObject object) { protected void rebuildHull(LocalAbstractObject object) {
List<LocalAbstractObject> objects = new ArrayList<>(getObjects()); List<LocalAbstractObject> objects = new ArrayList<>(getObjects());
...@@ -104,24 +98,4 @@ public abstract class Node implements Serializable { ...@@ -104,24 +98,4 @@ public abstract class Node implements Serializable {
rebuildHull(object); rebuildHull(object);
} }
public double getNearestDistance(LocalAbstractObject object) {
return hull.getHull().stream()
.mapToDouble(object::getDistance)
.min()
.orElse(Double.MAX_VALUE);
}
private double getFurthestDistance(LocalAbstractObject object) {
return hull.getHull().stream()
.mapToDouble(object::getDistance)
.max()
.orElse(Double.MIN_VALUE);
}
private double getAverageDistance(LocalAbstractObject object) {
return hull.getHull().stream()
.mapToDouble(object::getDistance)
.sum() / hull.getHull().size();
}
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment