Skip to content

feat: add lookup_index_by_key to Rust Vector for index-based search#8959

Open
statxc wants to merge 3 commits intogoogle:masterfrom
statxc:rust/add-lookup-index-by-key
Open

feat: add lookup_index_by_key to Rust Vector for index-based search#8959
statxc wants to merge 3 commits intogoogle:masterfrom
statxc:rust/add-lookup-index-by-key

Conversation

@statxc
Copy link

@statxc statxc commented Mar 6, 2026

Closes: #8667

Problem

lookup_by_key performs binary search on sorted vectors but can only return the matched object. There is no way to get the element's index, which is needed when using vector positions as references (e.g., graph adjacency lists, ECS entity lookups, index-based cross-referencing between vectors).

Fix

Add lookup_index_by_key to Vector - identical binary search logic as lookup_by_key, but returns Option<usize> (the index) instead of Option<T::Inner> (the object).

Changes

  • rust/flatbuffers/src/vector.rs - add lookup_index_by_key method on Vector<'a, T>
  • tests/rust_usage_test/tests/integration_test.rs - add 5 test cases for the new method

Test plan

# Run new tests
cd tests/rust_usage_test && cargo test lookup_index_by_key

# Run full test suite
cd tests/rust_usage_test && cargo test

@statxc statxc requested a review from dbaileychess as a code owner March 6, 2026 21:25
@github-actions github-actions bot added the rust label Mar 6, 2026
@statxc
Copy link
Author

statxc commented Mar 6, 2026

@jtdavis777 I'd appreciate you also review this PR.

@statxc
Copy link
Author

statxc commented Mar 7, 2026

Thanks for your feedback @jtdavis777 . I removed duplicated codes. Please review again

@statxc
Copy link
Author

statxc commented Mar 7, 2026

@jtdavis777 Any update for me, please

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Rust] Add support for binary search returning the index

2 participants