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
21 changes: 21 additions & 0 deletions cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,24 @@ if (USEARCH_BUILD_BENCH_CPP)
setup_target(bench_cpp)
target_include_directories(bench_cpp PRIVATE ${clipp_SOURCE_DIR}/include)
endif ()

option(USEARCH_BUILD_TEST_CPP_INDEX_GT "Compile index_gt GTest-based unit tests" OFF)

if (USEARCH_BUILD_TEST_CPP_INDEX_GT)
find_package(Threads REQUIRED)
include(FetchContent)
FetchContent_Declare(googletest
GIT_REPOSITORY https://github.com/google/googletest.git
GIT_TAG v1.17.0)
FetchContent_MakeAvailable(googletest)

add_executable(index_gt_test index_gt_test.cpp)
target_include_directories(index_gt_test BEFORE PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/../include
${CMAKE_CURRENT_SOURCE_DIR}/../fp16/include)
target_compile_features(index_gt_test PRIVATE cxx_std_23)
target_link_libraries(index_gt_test PRIVATE Threads::Threads GTest::gtest_main)

include(GoogleTest)
gtest_discover_tests(index_gt_test)
endif ()
24 changes: 21 additions & 3 deletions cpp/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,16 @@ using namespace unum::usearch;

int main(int argc, char **argv) {
metric_punned_t metric(3, metric_kind_t::l2sq_k, scalar_kind_t::f32_k);

// If you plan to store more than 4 Billion entries - use `index_dense_big_t`.
// Or directly instantiate the template variant you need - `index_dense_gt<vector_key_t, internal_id_t>`.
index_dense_t index = index_dense_t::make(metric);
float vec[3] = {0.1, 0.3, 0.2};

index.reserve(10); // Pre-allocate memory for 10 vectors
index.add(42, &vec[0]); // Pass a key and a vector
auto results = index.search(&vec[0], 5); // Pass a query and limit number of results

for (std::size_t i = 0; i != results.size(); ++i)
// You can access the following properties of every match:
// results[i].element.key, results[i].element.vector, results[i].distance;
Expand Down Expand Up @@ -191,3 +191,21 @@ template <typename distance_at = default_distance_t, // `float`
typename tape_allocator_at = dynamic_allocator_at> //
class index_gt;
```

## Testing

`index_gt_test` is a GTest-based unit test suite for the low-level `index_gt` engine, covering add/search correctness, iterator semantics, prefetch, predicate filtering, and more.

**Build and run:**

```bash
cmake -B build -DUSEARCH_BUILD_TEST_CPP_INDEX_GT=ON
cmake --build build --target index_gt_test
./build/cpp/index_gt_test
```

To run a specific test or filter by name:

```bash
./build/index_gt_test --gtest_filter="index_gt_basic.*"
```
Loading
Loading