Skip to content

Commit 267e633

Browse files
committed
adressing comments and simplifying code
1 parent 1a5fe4a commit 267e633

File tree

13 files changed

+141
-131
lines changed

13 files changed

+141
-131
lines changed

fdb-extensions/src/main/java/com/apple/foundationdb/async/hnsw/AbstractNode.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,6 @@ abstract class AbstractNode<N extends NodeReference> implements Node<N> {
4545

4646
/**
4747
* Constructs a new {@code AbstractNode} with a specified primary key and a list of neighbors.
48-
* <p>
49-
* This constructor creates a defensive, immutable copy of the provided {@code neighbors} list.
50-
* This ensures that the internal state of the node cannot be modified by external
51-
* changes to the original list after construction.
5248
*
5349
* @param primaryKey the unique identifier for this node; must not be {@code null}
5450
* @param neighbors the list of nodes connected to this node; must not be {@code null}

fdb-extensions/src/main/java/com/apple/foundationdb/async/hnsw/AbstractStorageAdapter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
/**
3737
* An abstract base class for {@link StorageAdapter} implementations.
3838
* <p>
39-
* This class provides the common infrastructure for managing HNSW graph data within {@link Subspace}.
39+
* This class provides the common infrastructure for managing HNSW graph data within a {@link Subspace}.
4040
* It handles the configuration, node creation, and listener management, while delegating the actual
4141
* storage-specific read and write operations to concrete subclasses through the {@code fetchNodeInternal}
4242
* and {@code writeNodeInternal} abstract methods.

fdb-extensions/src/main/java/com/apple/foundationdb/async/hnsw/AggregatedVector.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,14 @@
2121
package com.apple.foundationdb.async.hnsw;
2222

2323
import com.apple.foundationdb.linear.RealVector;
24+
import com.google.common.base.Objects;
2425

2526
import javax.annotation.Nonnull;
2627

28+
/**
29+
* A record-like class wrapping a {@link RealVector} and a count. This data structure is used to keep a running sum
30+
* of many vectors in order to compute their centroid at a later time.
31+
*/
2732
class AggregatedVector {
2833
private final int partialCount;
2934
@Nonnull
@@ -44,20 +49,17 @@ public RealVector getPartialVector() {
4449
}
4550

4651
@Override
47-
public final boolean equals(final Object o) {
52+
public boolean equals(final Object o) {
4853
if (!(o instanceof AggregatedVector)) {
4954
return false;
5055
}
51-
5256
final AggregatedVector that = (AggregatedVector)o;
53-
return partialCount == that.partialCount && partialVector.equals(that.partialVector);
57+
return partialCount == that.partialCount && Objects.equal(partialVector, that.partialVector);
5458
}
5559

5660
@Override
5761
public int hashCode() {
58-
int result = partialCount;
59-
result = 31 * result + partialVector.hashCode();
60-
return result;
62+
return Objects.hashCode(partialCount, partialVector);
6163
}
6264

6365
@Override

fdb-extensions/src/main/java/com/apple/foundationdb/async/hnsw/CompactStorageAdapter.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,6 @@ class CompactStorageAdapter extends AbstractStorageAdapter<NodeReference> implem
5757

5858
/**
5959
* Constructs a new {@code CompactStorageAdapter}.
60-
* <p>
61-
* This constructor initializes the adapter by delegating to the superclass,
62-
* setting up the necessary components for managing an HNSW graph.
6360
*
6461
* @param config the HNSW graph configuration, must not be null. See {@link Config}.
6562
* @param nodeFactory the factory used to create new nodes of type {@link NodeReference}, must not be null.

fdb-extensions/src/main/java/com/apple/foundationdb/async/hnsw/EntryNodeReference.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,6 @@ public EntryNodeReference withVector(@Nonnull RealVector newVector) {
7777
*/
7878
@Override
7979
public boolean equals(final Object o) {
80-
if (!(o instanceof EntryNodeReference)) {
81-
return false;
82-
}
8380
if (!super.equals(o)) {
8481
return false;
8582
}

fdb-extensions/src/main/java/com/apple/foundationdb/async/hnsw/HNSW.java

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1547,34 +1547,4 @@ private boolean shouldMaintainStats(final int batchSize) {
15471547
double pBatch = -Math.expm1(batchSize * Math.log1p(-getConfig().getMaintainStatsProbability()));
15481548
return random.nextDouble() < pBatch;
15491549
}
1550-
1551-
private static class NodeReferenceWithLayer extends NodeReferenceWithVector {
1552-
private final int layer;
1553-
1554-
public NodeReferenceWithLayer(@Nonnull final Tuple primaryKey, @Nonnull final RealVector vector,
1555-
final int layer) {
1556-
super(primaryKey, vector);
1557-
this.layer = layer;
1558-
}
1559-
1560-
public int getLayer() {
1561-
return layer;
1562-
}
1563-
1564-
@Override
1565-
public boolean equals(final Object o) {
1566-
if (!(o instanceof NodeReferenceWithLayer)) {
1567-
return false;
1568-
}
1569-
if (!super.equals(o)) {
1570-
return false;
1571-
}
1572-
return layer == ((NodeReferenceWithLayer)o).layer;
1573-
}
1574-
1575-
@Override
1576-
public int hashCode() {
1577-
return Objects.hash(super.hashCode(), layer);
1578-
}
1579-
}
15801550
}

fdb-extensions/src/main/java/com/apple/foundationdb/async/hnsw/NodeReference.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,10 @@ public NodeReferenceWithVector asNodeReferenceWithVector() {
7878
*/
7979
@Override
8080
public boolean equals(final Object o) {
81-
if (!(o instanceof NodeReference)) {
81+
if (this == o) {
82+
return true;
83+
}
84+
if (o.getClass() != this.getClass()) {
8285
return false;
8386
}
8487
final NodeReference that = (NodeReference)o;

fdb-extensions/src/main/java/com/apple/foundationdb/async/hnsw/NodeReferenceWithDistance.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,6 @@ public double getDistance() {
7272
*/
7373
@Override
7474
public boolean equals(final Object o) {
75-
if (!(o instanceof NodeReferenceWithDistance)) {
76-
return false;
77-
}
7875
if (!super.equals(o)) {
7976
return false;
8077
}

fdb-extensions/src/main/java/com/apple/foundationdb/async/hnsw/NodeReferenceWithVector.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,6 @@ public NodeReferenceWithVector asNodeReferenceWithVector() {
9494
*/
9595
@Override
9696
public boolean equals(final Object o) {
97-
if (!(o instanceof NodeReferenceWithVector)) {
98-
return false;
99-
}
10097
if (!super.equals(o)) {
10198
return false;
10299
}

fdb-extensions/src/main/java/com/apple/foundationdb/async/hnsw/StorageTransform.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,12 @@
2727

2828
import javax.annotation.Nonnull;
2929

30-
public class StorageTransform extends AffineOperator {
30+
/**
31+
* A special affine operator that uses a random rotator seeded by the current {@link AccessInfo} and a given
32+
* (pre-rotated) centroid. This operator is used inside the HNSW to transform back and forth between the coordinate
33+
* system of the client and the coordinate system that is currently employed in the HNSW.
34+
*/
35+
class StorageTransform extends AffineOperator {
3136
public StorageTransform(final long seed, final int numDimensions, @Nonnull final RealVector translationVector) {
3237
super(new FhtKacRotator(seed, numDimensions, 10), translationVector);
3338
}

0 commit comments

Comments
 (0)