# sambit003/algoat architecture

> Architecture diagram of the GitHub repository sambit003/algoat, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-08-20). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/sambit003/algoat
- Repository: https://github.com/sambit003/algoat

## Overview

#### 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: [`include/algoat/core/dispatcher.hpp`](https://github.com/sambit003/algoat/blob/main/include/algoat/core/dispatcher.hpp) (Dispatcher), [`include/algoat/sorting/sorting.hpp`](https://github.com/sambit003/algoat/blob/main/include/algoat/sorting/sorting.hpp) (Sorting API), [`include/algoat/searching/searching.hpp`](https://github.com/sambit003/algoat/blob/main/include/algoat/searching/searching.hpp) (Search API), [`python/python_wrappers.hpp`](https://github.com/sambit003/algoat/blob/main/python/python_wrappers.hpp) (Typed Python Wrappers)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_core["C++ Selection Core"]
  node_cpp_api["C++ Umbrella API<br/>public header<br/>[algoat.hpp]"]
  node_traits["DataTraits<br/>input profiling<br/>[traits.hpp]"]
  node_config["AlgoConfig<br/>runtime policy<br/>[config.hpp]"]
  node_registry["Algorithm Registry<br/>variant registry<br/>[registry.hpp]"]
  node_dispatcher{{"Dispatcher<br/>selection engine<br/>[dispatcher.hpp]"}}
  node_dispatcher_impl["Dispatcher Implementation<br/>native source<br/>[dispatcher.cpp]"]
end

subgraph group_algorithms["Algorithm Backends"]
  node_sorting_api["Sorting API<br/>header suite<br/>[sorting.hpp]"]
  node_sort_policy["Sort Policy Backends<br/>comparison sorts<br/>[introsort.hpp]"]
  node_timsort["TimSort<br/>sorting backend<br/>[timsort.hpp]"]
  node_native_sorts["Compiled Sorts<br/>native backends<br/>[quicksort.cpp]"]
  node_numeric_backends["Specialized Numeric Sorts<br/>non-comparison backends<br/>[float16_sort.hpp]"]
  node_morton["Morton Key Generation<br/>CPU-aware numeric path<br/>[morton.hpp]"]
  node_search_api["Search API<br/>header suite<br/>[searching.hpp]"]
  node_interpolation["Interpolation Search<br/>search backend"]
end

subgraph group_python["Python Binding"]
  node_python_package["Python Package API<br/>Python entry point<br/>[__init__.py]"]
  node_bindings{{"Nanobind Extension<br/>native binding<br/>[bindings.cpp]"}}
  node_python_wrappers["Typed Python Wrappers<br/>dtype adapters"]
end

subgraph group_delivery["Build &amp; Distribution"]
  node_build["CMake Build<br/>build system"]
  node_wheel_ci["Wheel Production<br/>CI pipeline<br/>[wheels.yml]"]
  node_packaging["Python Packaging<br/>distribution metadata<br/>[pyproject.toml]"]
end

node_cpp_api -->|"exports"| node_sorting_api
node_cpp_api -->|"exports"| node_search_api
node_sorting_api -->|"profiles input"| node_traits
node_sorting_api -->|"selects backend"| node_dispatcher
node_search_api -->|"uses traits"| node_traits
node_search_api -->|"selects strategy"| node_dispatcher
node_traits -->|"selection signals"| node_dispatcher
node_config -->|"policy overrides"| node_dispatcher
node_registry -->|"candidate variants"| node_dispatcher
node_dispatcher_impl -->|"implements"| node_dispatcher
node_dispatcher -->|"comparison sort"| node_sort_policy
node_dispatcher -->|"partially ordered"| node_timsort
node_dispatcher -->|"applicable numeric type"| node_numeric_backends
node_dispatcher -->|"search selection"| node_interpolation
node_sort_policy -->|"compiled implementations"| node_native_sorts
node_numeric_backends -->|"complex ordering"| node_morton
node_python_package -->|"imports"| node_bindings
node_bindings -->|"uses"| node_python_wrappers
node_python_wrappers -->|"dispatches sort calls"| node_sorting_api
node_python_wrappers -->|"dispatches search calls"| node_search_api
node_build -->|"builds extension"| node_bindings
node_packaging -->|"packages"| node_python_package
node_wheel_ci -->|"produces wheels"| node_packaging

click node_cpp_api "https://github.com/sambit003/algoat/blob/main/include/algoat/algoat.hpp"
click node_traits "https://github.com/sambit003/algoat/blob/main/include/algoat/core/traits.hpp"
click node_config "https://github.com/sambit003/algoat/blob/main/include/algoat/core/config.hpp"
click node_registry "https://github.com/sambit003/algoat/blob/main/include/algoat/core/registry.hpp"
click node_dispatcher "https://github.com/sambit003/algoat/blob/main/include/algoat/core/dispatcher.hpp"
click node_dispatcher_impl "https://github.com/sambit003/algoat/blob/main/src/core/dispatcher.cpp"
click node_sorting_api "https://github.com/sambit003/algoat/blob/main/include/algoat/sorting/sorting.hpp"
click node_sort_policy "https://github.com/sambit003/algoat/blob/main/include/algoat/sorting/introsort.hpp"
click node_timsort "https://github.com/sambit003/algoat/blob/main/include/algoat/sorting/timsort.hpp"
click node_native_sorts "https://github.com/sambit003/algoat/blob/main/src/sorting/quicksort.cpp"
click node_numeric_backends "https://github.com/sambit003/algoat/blob/main/include/algoat/numerics/float16_sort.hpp"
click node_morton "https://github.com/sambit003/algoat/blob/main/include/algoat/numerics/morton.hpp"
click node_search_api "https://github.com/sambit003/algoat/blob/main/include/algoat/searching/searching.hpp"
click node_interpolation "https://github.com/sambit003/algoat/blob/main/src/searching/interpolation_search.cpp"
click node_python_package "https://github.com/sambit003/algoat/blob/main/python/algoat/__init__.py"
click node_bindings "https://github.com/sambit003/algoat/blob/main/python/bindings.cpp"
click node_python_wrappers "https://github.com/sambit003/algoat/blob/main/python/python_wrappers.hpp"
click node_wheel_ci "https://github.com/sambit003/algoat/blob/main/.github/workflows/wheels.yml"
click node_packaging "https://github.com/sambit003/algoat/blob/main/pyproject.toml"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_cpp_api,node_traits,node_config,node_registry,node_dispatcher,node_dispatcher_impl toneBlue
class node_sorting_api,node_sort_policy,node_timsort,node_native_sorts,node_numeric_backends,node_morton,node_search_api,node_interpolation toneAmber
class node_python_package,node_bindings,node_python_wrappers toneMint
class node_build,node_wheel_ci,node_packaging toneRose
```

## Components

### C++ Selection Core

- [C++ Umbrella API](https://github.com/sambit003/algoat/blob/main/include/algoat/algoat.hpp): public header · `include/algoat/algoat.hpp`
- [DataTraits](https://github.com/sambit003/algoat/blob/main/include/algoat/core/traits.hpp): input profiling · Single-pass analysis of size, ordering, and duplicates. · `include/algoat/core/traits.hpp`
- [AlgoConfig](https://github.com/sambit003/algoat/blob/main/include/algoat/core/config.hpp): runtime policy · Loads JSON overrides for algorithm selection. · `include/algoat/core/config.hpp`
- [Algorithm Registry](https://github.com/sambit003/algoat/blob/main/include/algoat/core/registry.hpp): variant registry · Represents available algorithms with std::variant. · `include/algoat/core/registry.hpp`
- [Dispatcher](https://github.com/sambit003/algoat/blob/main/include/algoat/core/dispatcher.hpp): selection engine · Resolves explicit policy or trait-based fallback. · `include/algoat/core/dispatcher.hpp`
- [Dispatcher Implementation](https://github.com/sambit003/algoat/blob/main/src/core/dispatcher.cpp): native source · `src/core/dispatcher.cpp`

### Algorithm Backends

- [Sorting API](https://github.com/sambit003/algoat/blob/main/include/algoat/sorting/sorting.hpp): header suite · Unified contiguous/span-oriented sorting entry point. · `include/algoat/sorting/sorting.hpp`
- [Sort Policy Backends](https://github.com/sambit003/algoat/blob/main/include/algoat/sorting/introsort.hpp): comparison sorts · Insertion, TimSort, IntroSort, and compiled quick/merge/heap implementations. · `include/algoat/sorting/introsort.hpp`
- [TimSort](https://github.com/sambit003/algoat/blob/main/include/algoat/sorting/timsort.hpp): sorting backend · Preferred for partially ordered input. · `include/algoat/sorting/timsort.hpp`
- [Compiled Sorts](https://github.com/sambit003/algoat/blob/main/src/sorting/quicksort.cpp): native backends · Quicksort, mergesort, and heapsort implementations. · `src/sorting/quicksort.cpp`
- [Specialized Numeric Sorts](https://github.com/sambit003/algoat/blob/main/include/algoat/numerics/float16_sort.hpp): non-comparison backends · Boolean, float16, and complex radix-oriented paths. · `include/algoat/numerics/float16_sort.hpp`
- [Morton Key Generation](https://github.com/sambit003/algoat/blob/main/include/algoat/numerics/morton.hpp): CPU-aware numeric path · Complex ordering keys may use BMI2 instructions. · `include/algoat/numerics/morton.hpp`
- [Search API](https://github.com/sambit003/algoat/blob/main/include/algoat/searching/searching.hpp): header suite · Unified binary, interpolation, and linear search boundary. · `include/algoat/searching/searching.hpp`
- [Interpolation Search](https://github.com/sambit003/algoat/blob/main/src/searching/interpolation_search.cpp): search backend · Uses arithmetic probes with fallback behavior. · `src/searching/interpolation_search.cpp`

### Python Binding

- [Python Package API](https://github.com/sambit003/algoat/blob/main/python/algoat/__init__.py): Python entry point · `python/algoat/__init__.py`
- [Nanobind Extension](https://github.com/sambit003/algoat/blob/main/python/bindings.cpp): native binding · Bridges Python lists and contiguous NumPy arrays to C++. · `python/bindings.cpp`
- [Typed Python Wrappers](https://github.com/sambit003/algoat/blob/main/python/python_wrappers.hpp): dtype adapters · Preserve direct array views where possible. · `python/python_wrappers.hpp`

### Build & Distribution

- **CMake Build**: build system · Builds the core library, examples, and Python extension.
- [Wheel Production](https://github.com/sambit003/algoat/blob/main/.github/workflows/wheels.yml): CI pipeline · Automates binary wheel builds. · `.github/workflows/wheels.yml`
- [Python Packaging](https://github.com/sambit003/algoat/blob/main/pyproject.toml): distribution metadata · `pyproject.toml`

## Connections

- 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
