# garrisonj/sorted_containers architecture

> Architecture diagram of the GitHub repository garrisonj/sorted_containers, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2024-12-29). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/garrisonj/sorted_containers
- Repository: https://github.com/garrisonj/sorted_containers

## Overview

##### Specific Implementation Details

- The load factor configuration (default 1000)
- The subarray structure for SortedArray
- The dual data structure approach for SortedSet and SortedHash

**SortedArray: [[1,2,4],[5,6,7]] <- Show subarray structure**
**SortedSet: {SortedArray + Set}**
**SortedHash: {SortedArray(keys) + Hash}**

##### The performance optimization strategy

Remember to include a small benchmark results section in the corner to validate the design choices, using the data from the README's benchmark section.

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Public_Interface
        SA["SortedArray"]:::public
        SS["SortedSet"]:::public
        SH["SortedHash"]:::public
    end

    subgraph Implementation
        SAI["Segmented Array Implementation"]:::impl
        SSI["Set + SortedArray Implementation"]:::impl
        SHI["Hash + SortedArray Implementation"]:::impl
        LF["Load Factor<br/>(Default: 1000)"]:::perf
    end

    subgraph Infrastructure
        CE["Core Extensions"]:::infra
        VM["Version Management"]:::infra
    end

    subgraph Testing_And_Benchmarks
        TS["Test Suite"]:::test
        BM["Benchmark System"]:::test
        BR["Benchmark Results"]:::test
        BV["Benchmark Visualization"]:::test
    end

    %% Relationships
    SA --> SAI
    SS --> SSI
    SH --> SHI
    SAI -.-> LF
    SSI -.-> SAI
    SHI -.-> SAI
    SA & SS & SH -.-> CE

    %% Performance Indicators
    SAP["Insert: O(n)<br/>Delete: O(n)<br/>Lookup: O(log n)"]:::perf
    SSP["Insert: O(n)<br/>Delete: O(n)<br/>Lookup: O(log n)"]:::perf
    SHP["Insert: O(n)<br/>Delete: O(n)<br/>Lookup: O(log n)"]:::perf

    SA -.-> SAP
    SS -.-> SSP
    SH -.-> SHP

    %% Notes
    note["Memory Efficient<br/>Cache Locality Optimized<br/>Practical Performance Focus"]:::note

    %% Legend
    subgraph Legend
        L1["Public Interface"]:::public
        L2["Implementation"]:::impl
        L3["Infrastructure"]:::infra
        L4["Performance Critical"]:::perf
        L5["Testing"]:::test
    end

    %% Click Events
    click SA "https://github.com/GarrisonJ/sorted_containers/blob/main/lib/sorted_containers/sorted_array.rb"
    click SS "https://github.com/GarrisonJ/sorted_containers/blob/main/lib/sorted_containers/sorted_set.rb"
    click SH "https://github.com/GarrisonJ/sorted_containers/blob/main/lib/sorted_containers/sorted_hash.rb"
    click CE "https://github.com/GarrisonJ/sorted_containers/blob/main/lib/sorted_containers/core_extensions.rb"
    click VM "https://github.com/GarrisonJ/sorted_containers/blob/main/lib/sorted_containers/version.rb"
    click BM "https://github.com/GarrisonJ/sorted_containers/blob/main/benchmark/benchmark.rb"
    click BR "https://github.com/GarrisonJ/sorted_containers/blob/main/benchmark/benchmark_results.csv"
    click BV "https://github.com/GarrisonJ/sorted_containers/blob/main/benchmark/build_graphs.rb"
    click TS "https://github.com/GarrisonJ/sorted_containers/tree/main/spec"

    %% Styles
    classDef public fill:#3498db,stroke:#2980b9,color:white
    classDef impl fill:#2ecc71,stroke:#27ae60,color:white
    classDef infra fill:#95a5a6,stroke:#7f8c8d,color:white
    classDef perf fill:#e74c3c,stroke:#c0392b,color:white
    classDef test fill:#9b59b6,stroke:#8e44ad,color:white
    classDef note fill:#f1c40f,stroke:#f39c12,color:black
```
