Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import io.github.jbellis.jvector.disk.IndexWriter;
import io.github.jbellis.jvector.util.RamUsageEstimator;
import io.github.jbellis.jvector.vector.types.FloatArray;
import io.github.jbellis.jvector.vector.types.VectorFloat;

import java.io.IOException;
Expand All @@ -26,7 +27,7 @@
/**
* VectorFloat implementation backed by an on-heap float array.
*/
final public class ArrayVectorFloat implements VectorFloat<float[]>
final public class ArrayVectorFloat implements VectorFloat<float[]>, FloatArray
{
private final float[] data;

Expand Down Expand Up @@ -123,5 +124,10 @@ public int hashCode()
{
return this.getHashCode();
}

@Override
public float[] array() {
return get();
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
* Copyright DataStax, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package io.github.jbellis.jvector.vector.types;

/**
* Return the {@code float[]} representation of the {@link VectorFloat} if its type supports
* such conversions.
*/
public interface FloatArray {
float[] array();
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import io.github.jbellis.jvector.disk.IndexWriter;
import io.github.jbellis.jvector.util.RamUsageEstimator;
import io.github.jbellis.jvector.vector.types.FloatArray;
import io.github.jbellis.jvector.vector.types.VectorFloat;

import java.io.IOException;
Expand All @@ -27,7 +28,7 @@
/**
* VectorFloat implementation backed by an on-heap MemorySegment.
*/
final public class MemorySegmentVectorFloat implements VectorFloat<MemorySegment>
final public class MemorySegmentVectorFloat implements VectorFloat<MemorySegment>, FloatArray
{
private final MemorySegment segment;

Expand Down Expand Up @@ -141,4 +142,9 @@ public boolean equals(Object o)
public int hashCode() {
return this.getHashCode();
}

@Override
public float[] array() {
return (float[])segment.heapBase().get();
}
}
Loading