Skip to content

Solid multimap #45

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
May 4, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

## Unreleased

- Nothing yet
- Added `PhTreeMultiMapSolidF2`, a multimap for solids(boxes).
It is called `F2` because it is analogous to `PhTreeMultimapF2`
[#45](https://github.com/tzaeschke/phtree/pull/45)

## 2.8.2 - 2025-02-02

Expand Down
55 changes: 55 additions & 0 deletions src/main/java/ch/ethz/globis/phtree/PhEntryDistSF.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
* Copyright 2011-2025 Tilmann Zäschke. All Rights Reserved.
*
* This software is the proprietary information of Tilmann Zäschke.
* Use is subject to license terms.
*/
package ch.ethz.globis.phtree;

import java.util.Objects;

public class PhEntryDistSF<T> extends PhEntrySF<T> {
private double dist;

/**
* @param lower lower corner of rectangle key
* @param upper upper corner of rectangle key
* @param value value
* @param dist distance value
*/
public PhEntryDistSF(double[] lower, double[] upper, T value, double dist) {
super(lower, upper, value);
this.dist = dist;
}

void setValueDist(T value, double dist) {
setValue(value);
this.dist = dist;
}

/**
* @return the distance to the center point of the kNN query
*/
public double dist() {
return dist;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
if (!super.equals(o)) return false;
PhEntryDistSF<?> that = (PhEntryDistSF<?>) o;
return Double.compare(dist, that.dist) == 0;
}

@Override
public int hashCode() {
return Objects.hash(super.hashCode(), dist);
}

@Override
public String toString() {
return super.toString() + " dist=" + dist;
}
}
77 changes: 77 additions & 0 deletions src/main/java/ch/ethz/globis/phtree/PhEntrySF.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
/*
* Copyright 2011-2025 Tilmann Zäschke. All Rights Reserved.
*
* This software is the proprietary information of Tilmann Zäschke.
* Use is subject to license terms.
*/
package ch.ethz.globis.phtree;

import java.util.Arrays;

/**
* Entries in a PH-tree with ranged objects.
* @param <T> value type of the entry
*/
public class PhEntrySF<T> {

private final double[] lower;
private final double[] upper;
private T value;

/**
* Range object constructor.
* @param lower lower left corner
* @param upper upper right corner
* @param value The value associated with the point
*/
public PhEntrySF(double[] lower, double[] upper, T value) {
this.lower = lower;
this.upper = upper;
this.value = value;
}

/**
* @return the value of the entry
*/
public T value() {
return value;
}

/**
* @return lower left corner of the entry
*/
public double[] lower() {
return lower;
}

/**
* @return upper right corner of the entry
*/
public double[] upper() {
return upper;
}

void setValue(T value) {
this.value = value;
}

@SuppressWarnings("unchecked")
@Override
public boolean equals(Object obj) {
if (!(obj instanceof PhEntrySF)) {
return false;
}
PhEntrySF<T> e = (PhEntrySF<T>) obj;
return Arrays.equals(lower, e.lower) && Arrays.equals(upper, e.upper);
}

@Override
public int hashCode() {
return Arrays.hashCode(lower) ^ Arrays.hashCode(upper);
}

@Override
public String toString() {
return "{" + Arrays.toString(lower) + "," + Arrays.toString(upper) + "} => " + value;
}
}
10 changes: 5 additions & 5 deletions src/main/java/ch/ethz/globis/phtree/PhTreeMultiMapF2.java
Original file line number Diff line number Diff line change
Expand Up @@ -217,8 +217,8 @@ public boolean remove(double[] key, T value) {
/**
* @return an iterator over all elements in the tree
*/
public PhExtentF<T> queryExtent() {
return new PhExtentF<>(pht.queryExtent(), pht.getDim(), pre);
public PhExtentSF<T> queryExtent() {
return new PhExtentSF<>(pht.queryExtent(), pht.getDim(), pre);
}

/**
Expand Down Expand Up @@ -642,10 +642,10 @@ private void checkNext() {
*
* @param <T> value type
*/
public static class PhExtentF<T> extends PhIteratorF<T> {
public static class PhExtentSF<T> extends PhIteratorF<T> {
private final PhExtent<Object> iter;

protected PhExtentF(PhExtent<Object> iter, int dims, PreProcessorPointF pre) {
protected PhExtentSF(PhExtent<Object> iter, int dims, PreProcessorPointF pre) {
super(iter, dims, pre);
this.iter = iter;
}
Expand All @@ -656,7 +656,7 @@ protected PhExtentF(PhExtent<Object> iter, int dims, PreProcessorPointF pre) {
* @return this
*/
@Override
public PhExtentF<T> reset() {
public PhExtentSF<T> reset() {
iter.reset();
super.reset();
return this;
Expand Down
Loading