Skip to content

Commit

Permalink
squash-15
Browse files Browse the repository at this point in the history
  • Loading branch information
tzaeschke committed Jun 30, 2024
1 parent eb9f56e commit 914e9c0
Show file tree
Hide file tree
Showing 26 changed files with 2,424 additions and 59 deletions.
24 changes: 23 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,26 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

- Nothing yet

## [2.1.4 - Unreleased]

- Fixed tree corruption after remove() in QT2. [#40](https://github.com/tzaeschke/tinspin-indexes/issues/40)
- Fixed tree consistency (single-entry leaf after remove)
- Fixed tree consistency (nValues) -> verify
- Fixed bug in qt2.contains()
- Fixed QT2 inconsistency after root resizing after insert(). [#42](https://github.com/tzaeschke/tinspin-indexes/issues/42)
Essentially, we enforce all radii and the center of the root to be a power of two.
This should immensely reduce and problems with precision errors.

## [2.1.3] - 2023-11-19

### Fixed
- Fixed QuadtreeKD2 kNN finding previously deleted entries [#37](https://github.com/tzaeschke/tinspin-indexes/issue/37)

## [2.1.2] - 2023-10-31

### Fixed
- Fixed `create()` method for `IndexConfig` not being static [#33](https://github.com/tzaeschke/tinspin-indexes/issue/35)

## [2.1.1] - 2023-10-14

### Fixed
Expand Down Expand Up @@ -146,7 +166,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- Added CHANGELOG - [2015-10-11]
- Pushed to v1.3.3-SNAPSHOT - [2015-10-11]

[Unreleased]: https://github.com/tzaeschke/tinspin-indexes/compare/tinspin-indexes-2.1.1...HEAD
[Unreleased]: https://github.com/tzaeschke/tinspin-indexes/compare/tinspin-indexes-2.1.3...HEAD
[2.1.3]: https://github.com/tzaeschke/tinspin-indexes/compare/tinspin-indexes-2.1.2...tinspin-indexes-2.1.3
[2.1.2]: https://github.com/tzaeschke/tinspin-indexes/compare/tinspin-indexes-2.1.1...tinspin-indexes-2.1.2
[2.1.1]: https://github.com/tzaeschke/tinspin-indexes/compare/tinspin-indexes-2.1.0...tinspin-indexes-2.1.1
[2.1.0]: https://github.com/tzaeschke/tinspin-indexes/compare/tinspin-indexes-2.0.1...tinspin-indexes-2.1.0
[2.0.1]: https://github.com/tzaeschke/tinspin-indexes/compare/tinspin-indexes-2.0.0...tinspin-indexes-2.0.1
Expand Down
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ TinSpin indexes are also available via maven:
<dependency>
<groupId>org.tinspin</groupId>
<artifactId>tinspin-indexes</artifactId>
<version>2.1.0</version>
<version>2.1.3</version>
</dependency>
```

Expand All @@ -46,6 +46,9 @@ Note:
## Changelog

See [CHANGELOG](CHANGELOG.md) for details.
- 2.1.3 Fixed `remove()` not cleaning up properly and kNN returning deleted entries.
- 2.1.2 Made `create()` method `static` for `IndexConfig`.
- 2.1.1 Added `create()` method for `IndexConfig`.
- 2.1.0 **API:** Added factory methods for all indexes.
- 2.0.1 Fixed issue with dependencies in generated pom.
- **2.0.0** **Major API rewrite.**
Expand Down
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<groupId>org.tinspin</groupId>
<artifactId>tinspin-indexes</artifactId>
<packaging>jar</packaging>
<version>2.1.1</version>
<version>2.1.4-SNAPSHOT</version>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
Expand All @@ -24,7 +24,7 @@
<url>https://github.com/tzaeschke/tinspin-indexes</url>
<connection>scm:git:[email protected]:tzaeschke/tinspin-indexes.git</connection>
<developerConnection>scm:git:[email protected]:tzaeschke/tinspin-indexes.git</developerConnection>
<tag>tinspin-indexes-2.1.1</tag>
<tag>HEAD</tag>
</scm>
<developers>
<developer>
Expand Down
1 change: 1 addition & 0 deletions src/main/java/org/tinspin/index/Index.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public interface Index {
/**
* @return Collect and return some index statistics. Note that indexes are not required
* to fill all fields. Also, individual indexes may use subclasses with additional fields.
* Many indexes also perform consistency checks while gathering stats.
*/
Stats getStats();

Expand Down
16 changes: 10 additions & 6 deletions src/main/java/org/tinspin/index/IndexConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,30 +25,34 @@ protected IndexConfig(int dimensions) {
this.dimensions = dimensions;
}

public IndexConfig create(int dimensions) {
public static IndexConfig create(int dimensions) {
return new IndexConfig(dimensions);
}


/**
* Number of dimensions.
* @param dimensions Number of dimensions of keys.
* @return this
*/
public void setDimensions(int dimensions) {
public IndexConfig setDimensions(int dimensions) {
this.dimensions = dimensions;
return this;
}

/**
* @param defensiveKeyCopy
* Defensive keys copying. If `false`, the kd-tree will store the passed in
* Defensive keys copying. If 'false', the kd-tree will store the passed in
* double[] keys internally (this reduces required memory).
* If `true`, the keys are copied in order to avoid accidental modification.
* The latter obviously requires more memory.
* If 'true', the keys are copied in order to avoid accidental modification.
* The latter obviously requires more memory. Default is 'true'.
* <p>
* This setting works only for kd-trees.
* @return this
*/
public void setDefensiveKeyCopy(boolean defensiveKeyCopy) {
public IndexConfig setDefensiveKeyCopy(boolean defensiveKeyCopy) {
this.defensiveKeyCopy = defensiveKeyCopy;
return this;
}


Expand Down
5 changes: 4 additions & 1 deletion src/main/java/org/tinspin/index/Stats.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public class Stats {
public int minLevel = Integer.MAX_VALUE;
public int maxLevel = -1;
public int maxDepth = 0;
public int maxValuesInNode = 0;
public double sumLevel;
public int maxNodeSize = -1;
public int nLeaf;
Expand All @@ -49,7 +50,9 @@ public String toString() {
";nNodes=" + nNodes +
";nLeaf=" + nLeaf +
";nInner=" + nInner +
";minLevel=" + minLevel +
";maxDepth=" + maxDepth +
";maxValues=" + maxValuesInNode +
";minLevel=" + minLevel +
";maxLevel=" + maxLevel +
";avgLevel=" + (sumLevel/nEntries) +
";maxNodeSize=" + maxNodeSize;
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/org/tinspin/index/array/RectArray.java
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,9 @@ private ArrayList<BoxEntryKnn<T>> knnQuery(double[] center, int k) {
for (int i = 0; i < phc.length/2; i++) {
double[] min = phc[i*2];
double[] max = phc[i*2+1];
if (min == null) {
continue; // Entry has been removed
}
double dist = distREdge(center, min, max);
if (ret.size() < k) {
ret.add(new BoxEntryKnn<>(min, max, values[i].value(), dist));
Expand Down
1 change: 1 addition & 0 deletions src/main/java/org/tinspin/index/qthypercube/QNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,7 @@ void checkNode(QStats s, QNode<T> parent, int depth) {
s.nLeaf++;
s.nEntries += values.size();
s.histoValues[values.size()]++;
s.maxValuesInNode = Math.max(s.maxValuesInNode, values.size());
for (int i = 0; i < values.size(); i++) {
PointEntry<T> e = values.get(i);
if (!QUtil.fitsIntoNode(e.point(), center, radius*QUtil.EPS_MUL)) {
Expand Down
1 change: 1 addition & 0 deletions src/main/java/org/tinspin/index/qthypercube/QRNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,7 @@ void checkNode(QStats s, QRNode<T> parent, int depth) {
}
}
if (values != null) {
s.maxValuesInNode = Math.max(s.maxValuesInNode, values.size());
for (int i = 0; i < values.size(); i++) {
BoxEntry<T> e = values.get(i);
if (!QUtil.fitsIntoNode(e.min(), e.max(), center, radius*QUtil.EPS_MUL)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ public QStats getStats() {
* Statistics container class.
*/
public static class QStats extends Stats {
final int[] histoValues = new int[100];
final int[] histoValues = new int[1000];
final int[] histoSubs;

public QStats(int dims) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,8 @@ private void findNextElement() {
}

if (node.isLeaf()) {
for (PointEntry<T> entry : node.getValues()) {
processEntry(entry);
for (int i = 0; i < node.getValueCount(); i++) {
processEntry(node.getValues()[i]);
}
} else {
for (Object o : node.getEntries()) {
Expand Down
Loading

0 comments on commit 914e9c0

Please sign in to comment.