Skip to content

Commit

Permalink
Adjust backports for #14157 & #14174
Browse files Browse the repository at this point in the history
  • Loading branch information
benwtrent committed Jan 28, 2025
1 parent 29e681b commit 26af3b6
Show file tree
Hide file tree
Showing 15 changed files with 80 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -488,6 +488,11 @@ public int entryNode() {
throw new UnsupportedOperationException();
}

@Override
public int maxConn() {
throw new UnsupportedOperationException();
}

@Override
public NodesIterator getNodesOnLevel(int level) {
throw new UnsupportedOperationException();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,11 @@ public int entryNode() {
throw new UnsupportedOperationException();
}

@Override
public int maxConn() {
return maxConn;
}

@Override
public NodesIterator getNodesOnLevel(int level) {
throw new UnsupportedOperationException();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -548,6 +548,11 @@ public int entryNode() {
return entryNode;
}

@Override
public int maxConn() {
return (int) bytesForConns / Integer.BYTES - 1;
}

@Override
public NodesIterator getNodesOnLevel(int level) {
if (level == 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,11 @@ public int entryNode() {
return entryNode;
}

@Override
public int maxConn() {
return maxConn;
}

@Override
public NodesIterator getNodesOnLevel(int level) {
if (level == 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,11 @@ public int entryNode() {
return entryNode;
}

@Override
public int maxConn() {
return (int) bytesForConns / Integer.BYTES - 1;
}

@Override
public NodesIterator getNodesOnLevel(int level) {
if (level == 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,7 @@ private static final class OffHeapHnswGraph extends HnswGraph {
final int size;
final long bytesForConns;
final long bytesForConns0;
final int maxConn;

int arcCount;
int arcUpTo;
Expand All @@ -463,6 +464,7 @@ private static final class OffHeapHnswGraph extends HnswGraph {
this.bytesForConns = Math.multiplyExact(Math.addExact(entry.M, 1L), Integer.BYTES);
this.bytesForConns0 =
Math.multiplyExact(Math.addExact(Math.multiplyExact(entry.M, 2L), 1), Integer.BYTES);
maxConn = entry.M;
}

@Override
Expand Down Expand Up @@ -501,6 +503,11 @@ public int numLevels() {
return numLevels;
}

@Override
public int maxConn() {
return maxConn;
}

@Override
public int entryNode() {
return entryNode;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -537,6 +537,11 @@ public int entryNode() throws IOException {
return entryNode;
}

@Override
public int maxConn() {
return currentNeighborsBuffer.length / 2;
}

@Override
public NodesIterator getNodesOnLevel(int level) {
if (level == 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,11 @@ public int numLevels() {
return graph.numLevels();
}

@Override
public int maxConn() {
return graph.maxConn();
}

@Override
public int entryNode() {
throw new UnsupportedOperationException("Not supported on a mock graph");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,11 @@ public int entryNode() {
throw new UnsupportedOperationException("Not supported on a mock graph");
}

@Override
public int maxConn() {
throw new UnsupportedOperationException("Not supported on a mock graph");
}

@Override
public NodesIterator getNodesOnLevel(int level) {
if (level == 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -526,6 +526,11 @@ public int numLevels() throws IOException {
return numLevels;
}

@Override
public int maxConn() {
return currentNeighborsBuffer.length >> 1;
}

@Override
public int entryNode() throws IOException {
return entryNode;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,11 @@ public int numLevels() {
return graph.numLevels();
}

@Override
public int maxConn() {
return graph.maxConn();
}

@Override
public int entryNode() {
throw new UnsupportedOperationException("Not supported on a mock graph");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@ public int maxNodeId() {
/** Returns the number of levels of the graph */
public abstract int numLevels() throws IOException;

/** returns M, the maximum number of connections for a node. */
public abstract int maxConn() throws IOException;

/** Returns graph's entry point on the top level * */
public abstract int entryNode() throws IOException;

Expand Down Expand Up @@ -118,6 +121,11 @@ public int numLevels() {
return 0;
}

@Override
public int maxConn() {
return 0;
}

@Override
public int entryNode() {
return 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,11 @@ public int entryNode() {
return entryNode.get().node;
}

@Override
public int maxConn() {
return nsize - 1;
}

/**
* Try to set the entry node if the graph does not have one
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1337,6 +1337,11 @@ public int entryNode() throws IOException {
return delegate.entryNode();
}

@Override
public int maxConn() throws IOException {
return delegate.maxConn();
}

@Override
public NodesIterator getNodesOnLevel(int level) throws IOException {
return delegate.getNodesOnLevel(level);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,11 @@ public int entryNode() {
return 0;
}

@Override
public int maxConn() {
return 0;
}

@Override
public String toString() {
StringBuilder buf = new StringBuilder();
Expand Down

0 comments on commit 26af3b6

Please sign in to comment.