# paosder/vector-map architecture

> Architecture diagram of the GitHub repository paosder/vector-map, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-01-21). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/paosder/vector-map
- Repository: https://github.com/paosder/vector-map

## Overview

##### Main Components

a) Core Components:
- VectorMap Data Structure
- Internal Map (Pointer Storage)
- Internal Array (Source Storage)
- Key-Value Pair Management System
- Iterator Implementation

b) Supporting Components:
- Test Framework Integration
- Build System
- Example Implementation (WebGL)

##### Specific Elements

**Rectangle: Core components**
**Rounded Rectangle: Operations**
**Diamond: Decision points**

##### Key Relationships to Highlight

a) Data Flow:
**Client -> VectorMap Interface**
- > Map (Index Storage)
- > Array (Data Storage)

b) Operation Flow:
**Set Operation -> Update Map -> Update Array**
**Get Operation -> Query Map -> Access Array**
**Delete Operation -> Swap with Tail -> Pop -> Update Map**
**Swap Operation -> Update Map Pointers**

##### Implementation Details

**VectorMap<K, V>**
- Private Map<K, number>
- Private Array<{key: K, value: V}>

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph Core["Core Data Structure"]
        VM["VectorMap<K,V>"]:::core
        IM["Internal Map<K,number>"]:::core
        IA["Internal Array<{key:K,value:V}>"]:::core
        VM --> IM
        VM --> IA
        IM <--> IA
    end

    subgraph Operations["Operations Layer"]
        Set["Set Operation"]:::operation
        Get["Get Operation"]:::operation
        Del["Delete Operation"]:::operation
        Swap["Swap Operation"]:::operation
        
        Set --> |"O(1)"| UpdateMap["Update Map"]:::internal
        UpdateMap --> UpdateArray["Update Array"]:::internal
        
        Get --> |"O(1)"| QueryMap["Query Map"]:::internal
        QueryMap --> AccessArray["Access Array"]:::internal
        
        Del --> |"O(1)"| SwapTail["Swap with Tail"]:::internal
        SwapTail --> PopLast["Pop Last Element"]:::internal
        PopLast --> UpdateMapRefs["Update Map References"]:::internal
        
        Swap --> |"O(1)"| UpdatePointers["Update Map Pointers"]:::internal
    end

    subgraph Integration["Integration Layer"]
        Iterator["Iterator Implementation"]:::integration
        TypeSystem["TypeScript Type System"]:::integration
        WebGL["WebGL Example"]:::integration
        
        WebGLShaders["Shader Components"]:::integration
        WebGLCore["WebGL Core"]:::integration
        
        WebGL --> WebGLShaders
        WebGL --> WebGLCore
    end

    subgraph Infrastructure["Build & Testing"]
        Build["Build System"]:::infra
        Tests["Test Framework"]:::infra
        CICD["CI/CD Pipeline"]:::infra
    end

    VM --> Operations
    Operations --> Integration
    Integration --> Infrastructure

    %% Click Events
    click VM "https://github.com/Paosder/vector-map/blob/master/src/map.ts"
    click TypeSystem "https://github.com/Paosder/vector-map/blob/master/src/index.ts"
    click Tests "https://github.com/Paosder/vector-map/blob/master/tests/map.spec.ts"
    click Build "https://github.com/Paosder/vector-map/blob/master/esbuild.config.mjs"
    click WebGL "https://github.com/Paosder/vector-map/blob/master/examples/webgl/src/world.ts"
    click WebGLCore "https://github.com/Paosder/vector-map/blob/master/examples/webgl/src/cube/index.ts"
    click WebGLShaders "https://github.com/Paosder/vector-map/blob/master/examples/webgl/src/cube/vert.glsl"
    click CICD "https://github.com/Paosder/vector-map/blob/master/.github/workflows/ci.yml"

    %% Styles
    classDef core fill:#3498db,stroke:#2980b9,color:white
    classDef operation fill:#2ecc71,stroke:#27ae60,color:white
    classDef internal fill:#f1c40f,stroke:#f39c12,color:black
    classDef integration fill:#9b59b6,stroke:#8e44ad,color:white
    classDef infra fill:#95a5a6,stroke:#7f8c8d,color:white

    %% Legend
    subgraph Legend
        L1["Core Components"]:::core
        L2["Operations"]:::operation
        L3["Internal Processes"]:::internal
        L4["Integration Points"]:::integration
        L5["Infrastructure"]:::infra
    end
```
