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

ADD: leaf node javadoc

parent a2a7967f
No related branches found
No related tags found
No related merge requests found
...@@ -11,7 +11,7 @@ import java.util.stream.Collectors; ...@@ -11,7 +11,7 @@ import java.util.stream.Collectors;
/** /**
* Represents internal node of MH-Tree, i.e. a non-leaf node. * Represents internal node of MH-Tree, i.e. a non-leaf node.
*/ */
public class InternalNode extends Node implements Serializable { class InternalNode extends Node implements Serializable {
/** /**
* Serialization ID * Serialization ID
...@@ -98,7 +98,7 @@ public class InternalNode extends Node implements Serializable { ...@@ -98,7 +98,7 @@ public class InternalNode extends Node implements Serializable {
/** /**
* Adds this node and this node's descendants into {@code nodes}. * Adds this node and this node's descendants into {@code nodes}.
* *
* @param nodes list of nodes, where gathered nodes are added * @param nodes list of nodes
*/ */
void gatherNodes(List<Node> nodes) { void gatherNodes(List<Node> nodes) {
nodes.add(this); nodes.add(this);
...@@ -106,16 +106,12 @@ public class InternalNode extends Node implements Serializable { ...@@ -106,16 +106,12 @@ public class InternalNode extends Node implements Serializable {
} }
/** /**
* Returns a list of leaf nodes under this node. * Calls {@code gatherLeafNodes} on every child.
* *
* @return a list of leaf node under this node * @param leafNodes list of leaf nodes
*/ */
List<LeafNode> getLeafNodes() { void gatherLeafNodes(List<LeafNode> leafNodes) {
return children children.forEach(child -> child.gatherLeafNodes(leafNodes));
.stream()
.map(Node::getLeafNodes)
.flatMap(Collection::stream)
.collect(Collectors.toList());
} }
/** /**
......
...@@ -7,18 +7,23 @@ import messif.objects.LocalAbstractObject; ...@@ -7,18 +7,23 @@ import messif.objects.LocalAbstractObject;
import messif.objects.util.AbstractObjectIterator; import messif.objects.util.AbstractObjectIterator;
import java.io.Serializable; import java.io.Serializable;
import java.util.Collections; import java.util.ArrayList;
import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Set;
public class LeafNode extends Node implements Serializable { /**
* Represents leaf node of MH-Tree.
*/
class LeafNode extends Node implements Serializable {
/** /**
* Serialization ID * Serialization ID
*/ */
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
private LocalBucket bucket;
/**
* Bucket for storing objects of the MH-Tree.
*/
private final LocalBucket bucket;
LeafNode(PrecomputedDistances distances, LocalBucket bucket, InsertType insertType, ObjectToNodeDistance objectToNodeDistance) throws BucketStorageException { LeafNode(PrecomputedDistances distances, LocalBucket bucket, InsertType insertType, ObjectToNodeDistance objectToNodeDistance) throws BucketStorageException {
super(distances, insertType, objectToNodeDistance); super(distances, insertType, objectToNodeDistance);
...@@ -27,26 +32,66 @@ public class LeafNode extends Node implements Serializable { ...@@ -27,26 +32,66 @@ public class LeafNode extends Node implements Serializable {
this.bucket.addObjects(distances.getObjects()); this.bucket.addObjects(distances.getObjects());
} }
public void addObject(LocalAbstractObject object) throws BucketStorageException { /**
* Adds {@code object} to the node's bucket.
*
* @param object object to be added
* @throws BucketStorageException addition of object into bucket exception
*/
void addObject(LocalAbstractObject object) throws BucketStorageException {
bucket.addObject(object); bucket.addObject(object);
addNewObject(object); addObjectIntoHull(object);
} }
public Set<LocalAbstractObject> getObjects() { /**
Set<LocalAbstractObject> objects = new HashSet<>(bucket.getObjectCount()); * Returns a list of objects in node's bucket.
*
* @return a list of objects in node's bucket
*/
List<LocalAbstractObject> getObjects() {
List<LocalAbstractObject> objects = new ArrayList<>(bucket.getObjectCount());
for (AbstractObjectIterator<LocalAbstractObject> it = bucket.getAllObjects(); it.hasNext(); ) for (AbstractObjectIterator<LocalAbstractObject> it = bucket.getAllObjects(); it.hasNext(); ) {
objects.add(it.next()); objects.add(it.next());
}
return objects; return objects;
} }
public int getHeight() { /**
* Returns the number of objects stored in node's bucket.
*
* @return the number of objects stored in node's bucket
*/
int getObjectCount() {
return bucket.getObjectCount();
}
/**
* Returns the height of this node.
*
* @return the height of this node
*/
int getHeight() {
return 0; return 0;
} }
public List<Node> getNodesOnLevel(int level) { /**
return Collections.singletonList(this); * Adds this node into {@code nodes}.
*
* @param nodes list of nodes
*/
void gatherNodes(List<Node> nodes) {
nodes.add(this);
}
/**
* Adds this node into {@code leafNodes}.
*
* @param leafNodes list of leaf nodes
*/
void gatherLeafNodes(List<LeafNode> leafNodes) {
leafNodes.add(this);
} }
} }
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