graph LR subgraph "Binary: 11100.1 (5 adders)" B0["2โด=16"] --> BSUM["+"] B1["2ยณ=8"] --> BSUM B2["2ยฒ=4"] --> BSUM B3["2โปยน=0.5"] --> BSUM B4["Wait... that's 5 terms!"] end subgraph "CSD: +00-00.+ (3 adders!)" C0["2โต=32"] --> CSUM["+"] C1["-2ยฒ=-4"] --> CSUM C2["2โฐ=1"] --> CSUM C3["2โปยน=0.5"] --> CSUM end style B4 fill:#ffcdd2,stroke:#c62828 style CSUM fill:#e8f5e9,stroke:#2e7d32,stroke-width:3px
graph TD subgraph "Core Library" H["include/csd/csd.hpp\n(public API, constexpr parsers)"] S1["source/csd.cpp\n(to_csd, to_csd_i, to_csdnnz, ...)"] S2["source/lcsre.cpp\n(Longest Repeated Substring)"] SL["source/logger.cpp\n(spdlog wrapper)"] end subgraph "Build Targets" B1["Csd (static lib)"] B2["test_csd (doctest + rapidcheck)"] B3["test_switch (Google Benchmark)"] B4["csd_cli (cxxopts CLI)"] end subgraph "Build System" X["xmake.lua"] C["CMakeLists.txt"] end S1 --> H SL --> B1 B1 --> B2 B1 --> B3 B1 --> B4 S1 --> B1 style H fill:#bbdefb,stroke:#1565c0,stroke-width:2px style B1 fill:#e8f5e9,stroke:#2e7d32,stroke-width:3px
graph TD subgraph "Python Package (csdigit)" PY1["src/csdigit/csd.py\n(to_csd, to_csd_i, to_decimal, ...)"] PY2["src/csdigit/lcsre.py\n(Longest Repeated Substring)"] PY3["src/csdigit/cli.py\n(argparse CLI)"] PY4["src/csdigit/csd_multiplier.py\n(Verilog generation)"] end subgraph "Tests" T1["tests/test_csd.py\n(pytest + hypothesis)"] T2["tests/test_lcsre.py"] T3["tests/test_csd_multiplier.py"] end PY1 --> T1 PY2 --> T2 PY4 --> T3 PY3 --> PY1 style PY1 fill:#c8e6c9,stroke:#2e7d32,stroke-width:2px style T1 fill:#bbdefb,stroke:#1565c0
graph TD subgraph "๐ด Critical (Big Impact)" P1["1. pow(2.0, rem) in hot loop"] P2["2. ceil(log2(...)) โ frexp"] P3["3. Logger re-created every call"] P4["4. spdlog/fmt linked to Csd core"] end subgraph "๐ก Moderate" P5["5. Temporary string in lcsre.cpp"] P6["6. Missing string::reserve()"] P7["7. vector<vector> double indirection"] end subgraph "๐ข Minor" P8["8. double ops in to_decimal_switch"] P9["9. Redundant fabs() in to_csdnnz"] end P1 --> P2 P4 --> P3 P6 --> P5 P7 --> P8 style P1 fill:#ffcdd2,stroke:#c62828,stroke-width:3px style P2 fill:#ffcdd2,stroke:#c62828,stroke-width:3px style P3 fill:#ffcdd2,stroke:#c62828,stroke-width:3px style P4 fill:#ffcdd2,stroke:#c62828,stroke-width:3px
graph LR subgraph "Before โ" A1["Consumer App"] --> B1["Csd"] B1 --> C1["spdlog"] B1 --> D1["fmt"] end subgraph "After โ " A2["Consumer App (no logger)"] --> B2["Csd (light)"] A3["Consumer App (with logger)"] --> B4["CsdLogger"] B4 --> B2 B4 --> C2["spdlog"] end style C1 fill:#ffcdd2,stroke:#c62828 style D1 fill:#ffcdd2,stroke:#c62828 style B2 fill:#e8f5e9,stroke:#2e7d32,stroke-width:3px style C2 fill:#fff9c4,stroke:#f9a825
graph LR subgraph "Vector-of-Vector โ" VV_Outer["outer vector"] --> VV_Row0["row 0 heap"] VV_Outer --> VV_Row1["row 1 heap"] VV_Row0 --> VV_Cell["cell (chase pointer)"] end subgraph "Flat Vector โ " FV["single contiguous block"] --> FV_Cell["cell (base + offset)"] end style VV_Outer fill:#ffcdd2,stroke:#c62828 style FV fill:#e8f5e9,stroke:#2e7d32,stroke-width:3px
graph LR subgraph "Python Before โ" PB["[[0]*n for _ in range(n)]\nO(nยฒ) memory\nn list allocations"] end subgraph "Python After โ " PA["[0] * (2 * n)\nO(n) memory\n1 list allocation"] end style PB fill:#ffcdd2,stroke:#c62828 style PA fill:#e8f5e9,stroke:#2e7d32,stroke-width:3px
graph LR A["Profile ๐"] --> B["Identify\nBottlenecks ๐ฏ"] B --> C["Prioritize ๐"] C --> D["Implement ๐ง"] D --> E["Test ๐งช"] E --> F{"Pass?"} F -- Yes --> G["Benchmark โก"] F -- No --> D G --> H["Ship ๐"] G --> A style A fill:#bbdefb,stroke:#1565c0 style E fill:#fff9c4,stroke:#f9a825,stroke-width:2px style H fill:#e8f5e9,stroke:#2e7d32,stroke-width:3px