Skip to content

Commit 4eb607f

Browse files
authored
javadoc for base [disk,exceptions] (#547)
javadoc backfill for jvector_base [disk,exceptions]
1 parent 30e8932 commit 4eb607f

File tree

12 files changed

+155
-8
lines changed

12 files changed

+155
-8
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
target/
2+
local/
23
.mvn/wrapper/maven-wrapper.jar
34
.java-version
45

jvector-base/src/main/java/io/github/jbellis/jvector/disk/BufferedRandomAccessWriter.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,11 @@ public class BufferedRandomAccessWriter implements RandomAccessWriter {
3535
private final RandomAccessFile raf;
3636
private final DataOutputStream stream;
3737

38+
/**
39+
* Creates a buffered random access writer for the given path.
40+
* @param path the path to write to
41+
* @throws FileNotFoundException if the file cannot be created
42+
*/
3843
public BufferedRandomAccessWriter(Path path) throws FileNotFoundException {
3944
raf = new RandomAccessFile(path.toFile(), "rw");
4045
stream = new DataOutputStream(new BufferedOutputStream(new RandomAccessOutputStream(raf)));
@@ -88,10 +93,9 @@ public void flush() throws IOException {
8893
}
8994

9095
/**
91-
* return the CRC32 checksum for the range [startOffset .. endOffset)
92-
* <p>
93-
* the file pointer will be left at endOffset.
94-
* <p>
96+
* Returns the CRC32 checksum for the range [startOffset .. endOffset)
97+
*
98+
* The file pointer will be left at endOffset.
9599
*/
96100
@Override
97101
public long checksum(long startOffset, long endOffset) throws IOException {

jvector-base/src/main/java/io/github/jbellis/jvector/disk/ByteBufferReader.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,13 @@
2323
* RandomAccessReader that reads from a ByteBuffer
2424
*/
2525
public class ByteBufferReader implements RandomAccessReader {
26+
/** The underlying ByteBuffer. */
2627
protected final ByteBuffer bb;
2728

29+
/**
30+
* Creates a ByteBufferReader from the given ByteBuffer.
31+
* @param sourceBB the source ByteBuffer
32+
*/
2833
public ByteBufferReader(ByteBuffer sourceBB) {
2934
bb = sourceBB;
3035
}

jvector-base/src/main/java/io/github/jbellis/jvector/disk/IndexWriter.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,14 @@
2020
import java.io.DataOutput;
2121
import java.io.IOException;
2222

23+
/**
24+
* Interface for writing index data.
25+
*/
2326
public interface IndexWriter extends DataOutput, Closeable {
2427
/**
28+
* Returns the current position in the output.
2529
* @return the current position in the output
30+
* @throws IOException if an I/O error occurs
2631
*/
2732
long position() throws IOException;
2833
}

jvector-base/src/main/java/io/github/jbellis/jvector/disk/RandomAccessReader.java

Lines changed: 68 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,32 +32,99 @@
3232
* uses the ReaderSupplier API to create a RandomAccessReader per thread, as needed.
3333
*/
3434
public interface RandomAccessReader extends AutoCloseable {
35+
/**
36+
* Seeks to the specified offset.
37+
* @param offset the offset to seek to
38+
* @throws IOException if an I/O error occurs
39+
*/
3540
void seek(long offset) throws IOException;
3641

42+
/**
43+
* Returns the current position.
44+
* @return the current position
45+
* @throws IOException if an I/O error occurs
46+
*/
3747
long getPosition() throws IOException;
3848

49+
/**
50+
* Reads an integer.
51+
* @return the integer value
52+
* @throws IOException if an I/O error occurs
53+
*/
3954
int readInt() throws IOException;
4055

56+
/**
57+
* Reads a float.
58+
* @return the float value
59+
* @throws IOException if an I/O error occurs
60+
*/
4161
float readFloat() throws IOException;
4262

63+
/**
64+
* Reads a long.
65+
* @return the long value
66+
* @throws IOException if an I/O error occurs
67+
*/
4368
long readLong() throws IOException;
4469

70+
/**
71+
* Reads bytes into the array.
72+
* @param bytes the byte array to read into
73+
* @throws IOException if an I/O error occurs
74+
*/
4575
void readFully(byte[] bytes) throws IOException;
4676

77+
/**
78+
* Reads bytes into the buffer.
79+
* @param buffer the ByteBuffer to read into
80+
* @throws IOException if an I/O error occurs
81+
*/
4782
void readFully(ByteBuffer buffer) throws IOException;
4883

84+
/**
85+
* Reads floats into the array.
86+
* @param floats the float array to read into
87+
* @throws IOException if an I/O error occurs
88+
*/
4989
default void readFully(float[] floats) throws IOException {
5090
read(floats, 0, floats.length);
5191
}
5292

93+
/**
94+
* Reads longs into the array.
95+
* @param vector the long array to read into
96+
* @throws IOException if an I/O error occurs
97+
*/
5398
void readFully(long[] vector) throws IOException;
5499

100+
/**
101+
* Reads integers into the array.
102+
* @param ints the int array to read into
103+
* @param offset the offset in the array
104+
* @param count the number of integers to read
105+
* @throws IOException if an I/O error occurs
106+
*/
55107
void read(int[] ints, int offset, int count) throws IOException;
56108

109+
/**
110+
* Reads floats into the array.
111+
* @param floats the float array to read into
112+
* @param offset the offset in the array
113+
* @param count the number of floats to read
114+
* @throws IOException if an I/O error occurs
115+
*/
57116
void read(float[] floats, int offset, int count) throws IOException;
58117

118+
/**
119+
* Closes this reader.
120+
* @throws IOException if an I/O error occurs
121+
*/
59122
void close() throws IOException;
60123

61-
// Length of the reader slice
124+
/**
125+
* Returns the length of the reader slice.
126+
* @return the length
127+
* @throws IOException if an I/O error occurs
128+
*/
62129
long length() throws IOException;
63130
}

jvector-base/src/main/java/io/github/jbellis/jvector/disk/RandomAccessWriter.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,25 @@
2424
* A DataOutput that adds methods for random access writes
2525
*/
2626
public interface RandomAccessWriter extends IndexWriter {
27+
/**
28+
* Seeks to the specified position.
29+
* @param position the position to seek to
30+
* @throws IOException if an I/O error occurs
31+
*/
2732
void seek(long position) throws IOException;
2833

34+
/**
35+
* Flushes any buffered data.
36+
* @throws IOException if an I/O error occurs
37+
*/
2938
void flush() throws IOException;
3039

40+
/**
41+
* Computes a checksum for the specified range.
42+
* @param startOffset the start offset
43+
* @param endOffset the end offset
44+
* @return the checksum value
45+
* @throws IOException if an I/O error occurs
46+
*/
3147
long checksum(long startOffset, long endOffset) throws IOException;
3248
}

jvector-base/src/main/java/io/github/jbellis/jvector/disk/ReaderSupplier.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,10 @@
2323
*/
2424
public interface ReaderSupplier extends AutoCloseable {
2525
/**
26+
* Creates a new reader.
2627
* @return a new reader. It is up to the caller to re-use these readers or close them,
2728
* the ReaderSupplier is not responsible for caching them.
29+
* @throws IOException if an I/O error occurs
2830
*/
2931
RandomAccessReader get() throws IOException;
3032

jvector-base/src/main/java/io/github/jbellis/jvector/disk/ReaderSupplierFactory.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,26 @@
2222
import java.util.logging.Level;
2323
import java.util.logging.Logger;
2424

25+
/**
26+
* Factory for creating ReaderSupplier instances.
27+
*/
2528
public class ReaderSupplierFactory {
2629
private static final Logger LOG = Logger.getLogger(ReaderSupplierFactory.class.getName());
2730
private static final String MEMORY_SEGMENT_READER_CLASSNAME = "io.github.jbellis.jvector.disk.MemorySegmentReader$Supplier";
2831
private static final String MMAP_READER_CLASSNAME = "io.github.jbellis.jvector.example.util.MMapReader$Supplier";
2932

33+
/**
34+
* Private constructor to prevent instantiation.
35+
*/
36+
private ReaderSupplierFactory() {
37+
}
38+
39+
/**
40+
* Opens a ReaderSupplier for the given path.
41+
* @param path the path to open
42+
* @return a ReaderSupplier for the path
43+
* @throws IOException if an I/O error occurs
44+
*/
3045
public static ReaderSupplier open(Path path) throws IOException {
3146
try {
3247
// prefer MemorySegmentReader (available under JDK 20+)

jvector-base/src/main/java/io/github/jbellis/jvector/disk/SimpleMappedReader.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,18 @@ public void close() {
5555
// Individual readers don't close anything
5656
}
5757

58+
/**
59+
* Supplier for SimpleMappedReader instances.
60+
*/
5861
public static class Supplier implements ReaderSupplier {
5962
private final MappedByteBuffer buffer;
6063
private static final Unsafe unsafe = getUnsafe();
6164

65+
/**
66+
* Creates a Supplier for the given path.
67+
* @param path the path to read from
68+
* @throws IOException if an I/O error occurs
69+
*/
6270
public Supplier(Path path) throws IOException {
6371
try (var raf = new RandomAccessFile(path.toString(), "r")) {
6472
if (raf.length() > Integer.MAX_VALUE) {

jvector-base/src/main/java/io/github/jbellis/jvector/disk/SimpleReader.java

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,17 @@
2323
import java.nio.ByteOrder;
2424
import java.nio.file.Path;
2525

26-
// TODO what are the low-hanging optimization options here?
27-
// The requirement that we need to read from a file that is potentially changing in length
28-
// limits our options.
26+
/**
27+
* Simple implementation of RandomAccessReader using RandomAccessFile.
28+
*/
2929
public class SimpleReader implements RandomAccessReader {
3030
RandomAccessFile raf;
3131

32+
/**
33+
* Creates a SimpleReader for the given path.
34+
* @param path the path to read from
35+
* @throws FileNotFoundException if the file cannot be found
36+
*/
3237
public SimpleReader(Path path) throws FileNotFoundException {
3338
raf = new RandomAccessFile(path.toFile(), "r");
3439
}
@@ -105,9 +110,16 @@ public long length() throws IOException {
105110
return raf.length();
106111
}
107112

113+
/**
114+
* Supplier for SimpleReader instances.
115+
*/
108116
public static class Supplier implements ReaderSupplier {
109117
private final Path path;
110118

119+
/**
120+
* Creates a Supplier for the given path.
121+
* @param path the path to read from
122+
*/
111123
public Supplier(Path path) {
112124
this.path = path;
113125
}

0 commit comments

Comments
 (0)