How sambit003/algoat works
Purpose and Public Entry Points
Algoat is a C++20 algorithm library with Python bindings. Its core value is trait-driven selection of sorting/searching implementations, with configurable overrides and specialized numeric paths. C++ consumers include the umbrella API at include/algoat/algoat.hpp; Python consumers import the compiled module exposed through python/algoat/__init__.py and implemented in python/bindings.cpp.
Core Dispatch Architecture
The Registry/Dispatcher layer separates algorithm selection from algorithm implementations. Algorithms are represented through std::variant rather than virtual interfaces, avoiding vtable dispatch. The dispatcher profiles input data and resolves either explicit configuration or a heuristic fallback.
• include/algoat/core/registry.hpp
• include/algoat/core/dispatcher.hpp
• src/core/dispatcher.cpp
Data Traits and Configuration Boundary
DataTraits is the single-pass input-analysis boundary: size, ordering characteristics, and duplicates guide dynamic selection. AlgoConfig loads runtime JSON settings, allowing callers/deployments to force algorithms or alter fallback behavior rather than recompiling selection policy. JSON support is an external nlohmann/json dependency.
• include/algoat/core/traits.hpp
• include/algoat/core/config.hpp
• src/core/config.cpp
Sorting Pipeline
The main sort flow accepts contiguous/span-oriented data, derives traits, asks the dispatcher for a suitable backend, then invokes the selected implementation. Default policy favors insertion sort for small inputs, TimSort for partially ordered data, radix sorting for applicable large integer inputs, and IntroSort otherwise. The broad header-based sorting suite is collected behind:
• include/algoat/sorting/sorting.hpp
• include/algoat/sorting/introsort.hpp
• include/algoat/sorting/timsort.hpp
Some principal implementations are compiled into the native library:
• src/sorting/quicksort.cpp
• src/sorting/mergesort.cpp
• src/sorting/heapsort.cpp
Search Pipeline
Search APIs similarly expose a unified selection boundary over binary, interpolation, and linear search. The choice depends on input traits such as sortedness; interpolation search has its own arithmetic-probe fallback behavior.
• include/algoat/searching/searching.hpp
• include/algoat/searching/binary_search.hpp
• src/searching/interpolation_search.cpp
Specialized Numeric Backends
Domain-specific non-comparison paths bypass generic comparison sorting where data type permits: boolean counting/memory operations, float16 order-preserving bit transformations plus counting sort, and complex-number Morton/Z-order keys followed by radix sorting. The Morton implementation can use BMI2 hardware instructions where available, creating a CPU-feature-sensitive optimization boundary.
• include/algoat/numerics/float16_sort.hpp
• include/algoat/numerics/morton.hpp
• include/algoat/sorting/boolean_sort.hpp
Python Native Boundary and Delivery
Nanobind bridges Python lists and contiguous NumPy arrays to the C++ dispatch/algorithm layer, with typed wrappers for supported primitive and complex dtypes. The binding is intended to preserve direct array views where possible and provides Python-level return/in-place semantics.
• python/bindings.cpp
• python/python_types.hpp
• python/python_wrappers.hpp
CMake builds the core library, examples, and Python extension; pyproject.toml packages the Python distribution. Binary wheel production is automated by .github/workflows/wheels.yml; C++ package-consumer integration is represented by conanfile.py, vcpkg.json, and cmake/AlgoatConfig.cmake.in.
Main entry points: dispatcher.hpp Dispatcher · sorting.hpp Sorting API · searching.hpp Search API · python_wrappers.hpp Typed Python Wrappers
Components 20
C++ Selection Core
- C++ Umbrella API
include/algoat/algoat.hpp - DataTraits · Single-pass analysis of size, ordering, and duplicates.
include/algoat/core/traits.hpp - AlgoConfig · Loads JSON overrides for algorithm selection.
include/algoat/core/config.hpp - Algorithm Registry · Represents available algorithms with std::variant.
include/algoat/core/registry.hpp - Dispatcher · Resolves explicit policy or trait-based fallback.
include/algoat/core/dispatcher.hpp - Dispatcher Implementation
src/core/dispatcher.cpp
Algorithm Backends
- Sorting API · Unified contiguous/span-oriented sorting entry point.
include/algoat/sorting/sorting.hpp - Sort Policy Backends · Insertion, TimSort, IntroSort, and compiled quick/merge/heap implementations.
include/algoat/sorting/introsort.hpp - TimSort · Preferred for partially ordered input.
include/algoat/sorting/timsort.hpp - Compiled Sorts · Quicksort, mergesort, and heapsort implementations.
src/sorting/quicksort.cpp - Specialized Numeric Sorts · Boolean, float16, and complex radix-oriented paths.
include/algoat/numerics/float16_sort.hpp - Morton Key Generation · Complex ordering keys may use BMI2 instructions.
include/algoat/numerics/morton.hpp - Search API · Unified binary, interpolation, and linear search boundary.
include/algoat/searching/searching.hpp - Interpolation Search · Uses arithmetic probes with fallback behavior.
src/searching/interpolation_search.cpp
Python Binding
- Python Package API
python/algoat/__init__.py - Nanobind Extension · Bridges Python lists and contiguous NumPy arrays to C++.
python/bindings.cpp - Typed Python Wrappers · Preserve direct array views where possible.
python/python_wrappers.hpp
Build & Distribution
- CMake Build · Builds the core library, examples, and Python extension.
- Wheel Production · Automates binary wheel builds.
.github/workflows/wheels.yml - Python Packaging
pyproject.toml
Connections 23
- C++ Umbrella API → Sorting API: exports
- C++ Umbrella API → Search API: exports
- Sorting API → DataTraits: profiles input
- Sorting API → Dispatcher: selects backend
- Search API → DataTraits: uses traits
- Search API → Dispatcher: selects strategy
- DataTraits → Dispatcher: selection signals
- AlgoConfig → Dispatcher: policy overrides
- Algorithm Registry → Dispatcher: candidate variants
- Dispatcher Implementation → Dispatcher: implements
- Dispatcher → Sort Policy Backends: comparison sort
- Dispatcher → TimSort: partially ordered
- Dispatcher → Specialized Numeric Sorts: applicable numeric type
- Dispatcher → Interpolation Search: search selection
- Sort Policy Backends → Compiled Sorts: compiled implementations
- Specialized Numeric Sorts → Morton Key Generation: complex ordering
- Python Package API → Nanobind Extension: imports
- Nanobind Extension → Typed Python Wrappers: uses
- Typed Python Wrappers → Sorting API: dispatches sort calls
- Typed Python Wrappers → Search API: dispatches search calls
- CMake Build → Nanobind Extension: builds extension
- Python Packaging → Python Package API: packages
- Wheel Production → Python Packaging: produces wheels