Skip to content

Commit 9d45524

Browse files
committed
Replace LinkedHashSet with arrays and implement spliterator
1 parent 2d9d51e commit 9d45524

File tree

8 files changed

+633
-54
lines changed

8 files changed

+633
-54
lines changed

src/main/java/org/gephi/graph/api/Rect2D.java

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,44 @@ public boolean intersects(float minX, float minY, float maxX, float maxY) {
174174
return this.minX <= maxX && minX <= this.maxX && this.maxY >= minY && maxY >= this.minY;
175175
}
176176

177+
/**
178+
* Returns true if this rectangle contains or intersects with the given
179+
* rectangle. This is equivalent to checking
180+
* {@code this.contains(rect) || this.intersects(rect)} but more efficient as it
181+
* performs the check in a single operation.
182+
*
183+
* @param rect the rectangle to check
184+
* @return true if this rectangle contains or intersects with the given
185+
* rectangle, false otherwise
186+
*/
187+
public boolean containsOrIntersects(Rect2D rect) {
188+
if (rect == this) {
189+
return true;
190+
}
191+
192+
return containsOrIntersects(rect.minX, rect.minY, rect.maxX, rect.maxY);
193+
}
194+
195+
/**
196+
* Returns true if this rectangle contains or intersects with the given
197+
* rectangle. This is equivalent to checking
198+
* {@code this.contains(minX, minY, maxX, maxY) || this.intersects(minX, minY, maxX, maxY)}
199+
* but more efficient as it performs the check in a single operation.
200+
*
201+
* @param minX the x coordinate of the minimum corner
202+
* @param minY the y coordinate of the minimum corner
203+
* @param maxX the x coordinate of the maximum corner
204+
* @param maxY the y coordinate of the maximum corner
205+
*
206+
* @return true if this rectangle contains or intersects with the given
207+
* rectangle, false otherwise
208+
*/
209+
public boolean containsOrIntersects(float minX, float minY, float maxX, float maxY) {
210+
// Two rectangles have overlap if they intersect - containment is a subset of
211+
// intersection
212+
return this.minX <= maxX && minX <= this.maxX && this.maxY >= minY && maxY >= this.minY;
213+
}
214+
177215
@Override
178216
public boolean equals(Object obj) {
179217
if (this == obj) {

src/main/java/org/gephi/graph/api/SpatialIndex.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,17 @@ public interface SpatialIndex {
3030
*/
3131
NodeIterable getNodesInArea(Rect2D rect);
3232

33+
/**
34+
* Returns the nodes in the given area using a faster, but approximate method.
35+
* <p>
36+
* All nodes in the provided area are guaranteed to be returned, but some nodes
37+
* outside the area may also be returned.
38+
*
39+
* @param rect area to query
40+
* @return nodes in the area
41+
*/
42+
NodeIterable getApproximateNodesInArea(Rect2D rect);
43+
3344
/**
3445
* Returns the edges in the given area.
3546
*

src/main/java/org/gephi/graph/impl/GraphStoreConfiguration.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ public final class GraphStoreConfiguration {
8585
public static final int SPATIAL_INDEX_MAX_LEVELS = 16;
8686
public static final int SPATIAL_INDEX_MAX_OBJECTS_PER_NODE = 8192;
8787
public static final float SPATIAL_INDEX_DIMENSION_BOUNDARY = 1e6f;
88+
public static final boolean SPATIAL_INDEX_APPROXIMATE_AREA_SEARCH = false;
8889
// Miscellaneous
8990
public static final double TIMESTAMP_STORE_GROWING_FACTOR = 1.1;
9091
public static final double INTERVAL_STORE_GROWING_FACTOR = 1.1;

src/main/java/org/gephi/graph/impl/GraphViewDecorator.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -876,6 +876,16 @@ public NodeIterable getNodesInArea(Rect2D rect) {
876876
graphStore.spatialIndex.nodesTree.lock);
877877
}
878878

879+
@Override
880+
public NodeIterable getApproximateNodesInArea(Rect2D rect) {
881+
if (graphStore.spatialIndex == null) {
882+
throw new UnsupportedOperationException("Spatial index is disabled (from Configuration)");
883+
}
884+
return new NodeIterableWrapper(
885+
() -> new NodeViewIterator(graphStore.spatialIndex.getApproximateNodesInArea(rect).iterator()),
886+
graphStore.spatialIndex.nodesTree.lock);
887+
}
888+
879889
@Override
880890
public EdgeIterable getEdgesInArea(Rect2D rect) {
881891
if (graphStore.spatialIndex == null) {

0 commit comments

Comments
 (0)