Wrap Voyager C++ headers in the voyager namespace (fixes #52) - #138
Open
Sanaullah-Turab wants to merge 3 commits into
Open
Sanaullah-Turab wants to merge 3 commits into
Sanaullah-Turab wants to merge 3 commits into
Conversation
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Voyager's C++ headers were declared in the global namespace instead of a Voyager specific one, which is a problem for anyone wanting to use the C++ library standalone since it risks symbol collisions with other code. This PR wraps all remaining Voyager specific headers in
namespace voyager { ... }, following the pattern already used inMetadata.hfrom an earlier PR, without touching the vendoredhnswlibcode.Related Issues
Closes #52
Changes Made
C++
Wrapped the following files in
namespace voyager:cpp/src/Enums.hcpp/src/std_utils.hcpp/src/array_utils.hcpp/src/E4M3.hcpp/src/StreamUtils.hcpp/src/Index.hcpp/src/TypedIndex.hhnswlib.h,hnswalg.h,visited_list_pool.h, andSpaces/*.hwere left untouched since they are vendored and already scoped undernamespace hnswlib.Updated
cpp/test/test_main.cppto qualifyIndex,SpaceType,StorageDataType,Metadata, and related test utilities withvoyager::.One deviation worth flagging for review: the vendored
hnswalg.huses the customInputStream/OutputStreamtypes that just moved intonamespace voyager, and I didn't want to edit vendored files to fix this. Instead I added a small alias block at the end ofStreamUtils.h:This lets
hnswalg.hresolve the types inside its own namespace with zero edits to vendored code. Open to a different approach here if maintainers prefer something else.Also fixed an unrelated small bug I hit along the way:
TypedIndex.hhadIndexCannotBeShrunkErrorandIndexFullErrorincorrectly prefixed withhnswlib::, when those exceptions are actually defined in the global namespace. Removed the incorrect prefix so they resolve correctly.Python
Updated
python/src/bindings.cppto qualifyIndex,SpaceType,StorageDataType,Metadata,InputStream,OutputStream, and related utilities withvoyager::.Updated
python/src/PythonInputStream.handpython/src/PythonOutputStream.hso their base classes arevoyager::InputStreamandvoyager::OutputStream.Also fixed a small unrelated bug in
tox.iniwheretox -e formatwas runningruff format --diff, which only checks formatting instead of applying it. Removed the--diffflag so the format command actually formats the code.Java
No changes.
Testing
C++:
make check-formattingandmake format(clang-format v16)make testviamake VoyagerTestsPython:
tox -e formatto apply formattingtoxto build the native extension and run the full test suiteChecklist
Additional Comments
The maintainers previously noted they don't guarantee C++ interface compatibility across versions for this exact reason, so this change is expected and welcome rather than a breaking surprise. Happy to adjust the
StreamUtils.halias approach if there's a preferred way to bridge the vendoredhnswlibcode with the new namespace.