Skip to content

Commit a4e47a8

Browse files
committed
save point -- in the middle of just mess and mess
1 parent fc219c3 commit a4e47a8

15 files changed

+236
-1967
lines changed

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,17 +28,17 @@
2828

2929
/**
3030
* TODO.
31-
* @param <N> node type class.
31+
* @param <R> node type class.
3232
*/
33-
abstract class AbstractNode<N extends Neighbor> implements Node<N> {
33+
abstract class AbstractNode<R extends NodeReference> implements Node<R> {
3434
@Nonnull
3535
private final Tuple primaryKey;
3636

3737
@Nonnull
38-
private final List<N> neighbors;
38+
private final List<R> neighbors;
3939

4040
protected AbstractNode(@Nonnull final Tuple primaryKey,
41-
@Nonnull final List<N> neighbors) {
41+
@Nonnull final List<R> neighbors) {
4242
this.primaryKey = primaryKey;
4343
this.neighbors = ImmutableList.copyOf(neighbors);
4444
}
@@ -51,13 +51,13 @@ public Tuple getPrimaryKey() {
5151

5252
@Nonnull
5353
@Override
54-
public List<N> getNeighbors() {
54+
public List<R> getNeighbors() {
5555
return neighbors;
5656
}
5757

5858
@Nonnull
5959
@Override
60-
public N getNeighbor(final int index) {
60+
public R getNeighbor(final int index) {
6161
return neighbors.get(index);
6262
}
6363
}

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -173,16 +173,16 @@ public void deleteFromNodeIndexIfNecessary(@Nonnull final Transaction transactio
173173

174174
@Nonnull
175175
@Override
176-
public <N extends Neighbor> CompletableFuture<NodeWithLayer<N>> fetchNode(@Nonnull final Node.NodeCreator<N> creator,
177-
@Nonnull final ReadTransaction readTransaction,
178-
int layer, @Nonnull Tuple primaryKey) {
176+
public <N extends NodeReference> CompletableFuture<Node<N>> fetchNode(@Nonnull final Node.NodeCreator<N> creator,
177+
@Nonnull final ReadTransaction readTransaction,
178+
int layer, @Nonnull Tuple primaryKey) {
179179
return fetchNodeInternal(creator, readTransaction, layer, primaryKey).thenApply(this::checkNode);
180180
}
181181

182182
@Nonnull
183-
protected abstract <N extends Neighbor> CompletableFuture<NodeWithLayer<N>> fetchNodeInternal(@Nonnull Node.NodeCreator<N> creator,
184-
@Nonnull ReadTransaction readTransaction,
185-
int layer, @Nonnull Tuple primaryKey);
183+
protected abstract <N extends NodeReference> CompletableFuture<Node<N>> fetchNodeInternal(@Nonnull Node.NodeCreator<N> creator,
184+
@Nonnull ReadTransaction readTransaction,
185+
int layer, @Nonnull Tuple primaryKey);
186186

187187
/**
188188
* Method to perform basic invariant check(s) on a newly-fetched node.
@@ -194,7 +194,7 @@ protected abstract <N extends Neighbor> CompletableFuture<NodeWithLayer<N>> fetc
194194
* @return the node that was passed in
195195
*/
196196
@Nullable
197-
private <N extends Neighbor> NodeWithLayer<N> checkNode(@Nullable final NodeWithLayer<N> node) {
197+
private <N extends NodeReference> Node<N> checkNode(@Nullable final Node<N> node) {
198198
return node;
199199
}
200200

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

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -96,10 +96,10 @@ public CompletableFuture<EntryPointAndLayer> fetchEntryNodeKey(@Nonnull final Re
9696

9797
@Nonnull
9898
@Override
99-
protected <N extends Neighbor> CompletableFuture<NodeWithLayer<N>> fetchNodeInternal(@Nonnull final Node.NodeCreator<N> creator,
100-
@Nonnull final ReadTransaction readTransaction,
101-
final int layer,
102-
@Nonnull final Tuple primaryKey) {
99+
protected <R extends NodeReference> CompletableFuture<Node<R>> fetchNodeInternal(@Nonnull final Node.NodeCreator<R> creator,
100+
@Nonnull final ReadTransaction readTransaction,
101+
final int layer,
102+
@Nonnull final Tuple primaryKey) {
103103
final byte[] key = getDataSubspace().pack(Tuple.from(layer, primaryKey));
104104

105105
return readTransaction.get(key)
@@ -109,11 +109,11 @@ protected <N extends Neighbor> CompletableFuture<NodeWithLayer<N>> fetchNodeInte
109109
}
110110

111111
final Tuple nodeTuple = Tuple.fromBytes(valueBytes);
112-
final Node<N> node = nodeFromTuple(creator, nodeTuple);
112+
final Node<R> node = nodeFromTuple(creator, nodeTuple);
113113
final OnReadListener onReadListener = getOnReadListener();
114114
onReadListener.onNodeRead(node);
115115
onReadListener.onKeyValueRead(key, valueBytes);
116-
return node.withLayer(layer);
116+
return node;
117117
});
118118
}
119119

@@ -158,8 +158,8 @@ private Tuple toTuple(@Nonnull final Node node) {
158158
}
159159

160160
@Nonnull
161-
private <N extends Neighbor> Node<N> nodeFromTuple(@Nonnull final Node.NodeCreator<N> creator,
162-
@Nonnull final Tuple tuple) {
161+
private <N extends NodeReference> Node<N> nodeFromTuple(@Nonnull final Node.NodeCreator<N> creator,
162+
@Nonnull final Tuple tuple) {
163163
final NodeKind nodeKind = NodeKind.fromSerializedNodeKind((byte)tuple.getLong(0));
164164
final Tuple primaryKey = tuple.getNestedTuple(1);
165165
final Tuple vectorTuple;
@@ -179,27 +179,27 @@ private <N extends Neighbor> Node<N> nodeFromTuple(@Nonnull final Node.NodeCreat
179179
}
180180

181181
@Nonnull
182-
private <N extends Neighbor> Node<N> dataNodeFromTuples(@Nonnull final Node.NodeCreator<N> creator,
183-
@Nonnull final Tuple primaryKey,
184-
@Nonnull final Tuple vectorTuple,
185-
@Nonnull final Tuple neighborsTuple) {
182+
private <N extends NodeReference> Node<N> dataNodeFromTuples(@Nonnull final Node.NodeCreator<N> creator,
183+
@Nonnull final Tuple primaryKey,
184+
@Nonnull final Tuple vectorTuple,
185+
@Nonnull final Tuple neighborsTuple) {
186186
final Vector<Half> vector = vectorFromTuple(vectorTuple);
187187

188-
List<Neighbor> neighbors = Lists.newArrayListWithExpectedSize(neighborsTuple.size());
188+
List<NodeReference> nodeReferences = Lists.newArrayListWithExpectedSize(neighborsTuple.size());
189189

190190
for (final Object neighborObject : neighborsTuple) {
191191
final Tuple neighborTuple = (Tuple)neighborObject;
192-
neighbors.add(new Neighbor(neighborTuple));
192+
nodeReferences.add(new NodeReference(neighborTuple));
193193
}
194194

195-
return creator.create(NodeKind.DATA, primaryKey, vector, neighbors);
195+
return creator.create(NodeKind.DATA, primaryKey, vector, nodeReferences);
196196
}
197197

198198
@Nonnull
199-
private <N extends Neighbor> Node<N> intermediateNodeFromTuples(@Nonnull final Node.NodeCreator<N> creator,
200-
@Nonnull final Tuple primaryKey,
201-
@Nonnull final Tuple neighborsTuple) {
202-
List<NeighborWithVector> neighborsWithVectors = Lists.newArrayListWithExpectedSize(neighborsTuple.size());
199+
private <N extends NodeReference> Node<N> intermediateNodeFromTuples(@Nonnull final Node.NodeCreator<N> creator,
200+
@Nonnull final Tuple primaryKey,
201+
@Nonnull final Tuple neighborsTuple) {
202+
List<NodeReferenceWithVector> neighborsWithVectors = Lists.newArrayListWithExpectedSize(neighborsTuple.size());
203203
Half[] neighborVectorHalfs = null;
204204

205205
for (final Object neighborObject : neighborsTuple) {
@@ -213,7 +213,7 @@ private <N extends Neighbor> Node<N> intermediateNodeFromTuples(@Nonnull final N
213213
for (int i = 0; i < neighborVectorTuple.size(); i ++) {
214214
neighborVectorHalfs[i] = Half.shortBitsToHalf(shortFromBytes(neighborVectorTuple.getBytes(i)));
215215
}
216-
neighborsWithVectors.add(new NeighborWithVector(neighborPrimaryKey, new Vector.HalfVector(neighborVectorHalfs)));
216+
neighborsWithVectors.add(new NodeReferenceWithVector(neighborPrimaryKey, new Vector.HalfVector(neighborVectorHalfs)));
217217
}
218218

219219
return creator.create(NodeKind.INTERMEDIATE, primaryKey, null, neighborsWithVectors);

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

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,13 @@
3232
/**
3333
* TODO.
3434
*/
35-
class DataNode extends AbstractNode<Neighbor> {
35+
class DataNode extends AbstractNode<NodeReference> {
3636
@Nonnull
3737
private final Vector<Half> vector;
3838

3939
public DataNode(@Nonnull final Tuple primaryKey, @Nonnull final Vector<Half> vector,
40-
@Nonnull final List<Neighbor> neighbors) {
41-
super(primaryKey, neighbors);
40+
@Nonnull final List<NodeReference> nodeReferences) {
41+
super(primaryKey, nodeReferences);
4242
this.vector = vector;
4343
}
4444

@@ -65,24 +65,18 @@ public IntermediateNode asIntermediateNode() {
6565
throw new IllegalStateException("this is not a data node");
6666
}
6767

68-
@Nonnull
69-
@Override
70-
public NodeWithLayer<Neighbor> withLayer(final int layer) {
71-
return new NodeWithLayer<>(layer, this);
72-
}
73-
7468
@Override
75-
public NodeCreator<Neighbor> sameCreator() {
69+
public NodeCreator<NodeReference> sameCreator() {
7670
return DataNode::creator;
7771
}
7872

7973
@Nonnull
8074
@SuppressWarnings("unchecked")
81-
public static Node<Neighbor> creator(@Nonnull final NodeKind nodeKind,
82-
@Nonnull final Tuple primaryKey,
83-
@Nullable final Vector<Half> vector,
84-
@Nonnull final List<? extends Neighbor> neighbors) {
75+
public static Node<NodeReference> creator(@Nonnull final NodeKind nodeKind,
76+
@Nonnull final Tuple primaryKey,
77+
@Nullable final Vector<Half> vector,
78+
@Nonnull final List<? extends NodeReference> neighbors) {
8579
Verify.verify(nodeKind == NodeKind.INTERMEDIATE);
86-
return new DataNode(primaryKey, Objects.requireNonNull(vector), (List<Neighbor>)neighbors);
80+
return new DataNode(primaryKey, Objects.requireNonNull(vector), (List<NodeReference>)neighbors);
8781
}
8882
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public double getDistance() {
4949
return distance;
5050
}
5151

52-
public Element toElement() {
53-
return new Element(getPrimaryKey(), getDistance());
52+
public NodeReferenceWithDistance toElement() {
53+
return new NodeReferenceWithDistance(getPrimaryKey(), getDistance());
5454
}
5555
}

0 commit comments

Comments
 (0)