# jonmat/fastindex architecture

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

- Interactive diagram: https://gitdiagram.com/jonmat/fastindex
- Repository: https://github.com/jonmat/fastindex

## Overview

##### Project Type and Purpose
- This is a C# class library solution (“FastIndex”) that implements an XOR‐filter based index (a perfect-hash–like structure) plus two auxiliary projects:
– A console application for performance benchmarking (BenchMark)
– A unit‐test suite demonstrating usage and validating correctness (FastIndex.Tests)

##### Main Components
1. Core Library (FastIndex)
- FastFilter module: builds the three‐segment XOR filter from 64-bit hashes
- Index generator: computes and stores the primary‐segment index in a lookaside byte array
- Public API: BuildFilter(), GetIndex(), Contains()
2. Test Harness (FastIndex.Tests)
- TestData & XXHash utility: generates fake phone‐number inputs and computes their hashes
- FastIndexTestHelper: example wiring of filter construction → index lookup → array population → collision validation
3. Benchmark App (BenchMark)
- Program.cs: console entry point, invokes BenchmarkDotNet jobs to measure Construct_FastFilter, Contains, Index lookups
- Dependency on BenchmarkDotNet library and on the FastIndex core library

##### Component Relationships and Data Flows
- Both BenchMark and FastIndex.Tests projects reference and invoke the core FastIndex library API.
- Client data flow:
[Raw Items (e.g. phone numbers)]
→ (XXHash) → [64-bit Hash Keys]
→ (FastFilter.Build) → [3× segment fingerprint arrays] + [lookaside byte array]
→ (optional serialize/persist) → [Stored Filter]
→ (Filter Load) → (GetIndex or Contains) → [Index or Boolean]
- Unit tests validate the flow end-to-end and measure false positives.
- Benchmark app measures timings of Build, Contains, Index operations.

##### Key Architectural Patterns & Principles
- Layered separation:
– Hash generation layer (XXHash)
– Core algorithm layer (XOR filter & index generation)
– Consumer layers (unit tests, benchmarks)
- Single responsibility: each project has a clear role (library vs. test vs. benchmark)
- Probabilistic data‐structure pattern: XOR filter internals with three fixed arrays and bit‐multiplexed lookaside storage

##### Technologies & Frameworks
- C#/.NET 6.0+ class library projects (.csproj)
- BenchmarkDotNet (for BenchMark)
- xUnit or NUnit (depending on FastIndex.Tests csproj)
- XXHash implementation in TestData

##### Essential Elements
– Brief notes on internal algorithm segments (3 arrays + lookaside byte array)

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External Input
    RawData["Raw Data (phone numbers)"]:::external

    %% Core Library
    subgraph "FastIndex Core Library"
        direction TB
        XorBuilder["FastFilter Module<br/>(3 segments arrays)"]:::core
        Indexer["Lookaside Byte-array Indexer"]:::core
        API["Public API<br/>BuildFilter(), GetIndex(), Contains()"]:::core
    end

    %% Persistence Storage
    Storage["Serialized Filter Storage"]:::storage

    %% Test Harness
    subgraph "FastIndex.Tests" 
        direction TB
        TestProj["FastIndex.Tests (.csproj)"]:::tests
        TestData["TestData & XXHash Utility"]:::tests
        Helper["FastIndexTestHelper"]:::tests
        Tests["Unit Tests"]:::tests
    end

    %% Benchmark App
    subgraph "BenchMark App"
        direction TB
        BenchProj["BenchMark (.csproj)"]:::bench
        Program["Program.cs<br/>(BenchmarkDotNet)"]:::bench
    end

    %% Data Flow and References
    RawData -->|"ComputeHash() → UInt64"| TestData
    TestData -->|"UInt64 keys"| XorBuilder
    XorBuilder -->|"BuildFilter()"| Indexer
    Indexer -->|"Stores index"| Storage
    Storage -->|"LoadFilter()"| API
    API -->|"GetIndex() → byte[]\nContains() → bool"| Tests
    API -->|"GetIndex() → byte[]\nContains() → bool"| Program

    API -.->|references| TestProj
    API -.->|references| BenchProj

    %% Click Events
    click XorBuilder "https://github.com/jonmat/fastindex/blob/main/FastIndex/FastIndex/FastFilter.cs"
    click API "https://github.com/jonmat/fastindex/blob/main/FastIndex/FastIndex/FastIndex.csproj"
    click TestProj "https://github.com/jonmat/fastindex/blob/main/FastIndex/FastIndex.Tests/FastIndex.Tests.csproj"
    click TestData "https://github.com/jonmat/fastindex/blob/main/FastIndex/FastIndex.Tests/TestData.cs"
    click Helper "https://github.com/jonmat/fastindex/blob/main/FastIndex/FastIndex.Tests/FastIndexTestHelper.cs"
    click Tests "https://github.com/jonmat/fastindex/blob/main/FastIndex/FastIndex.Tests/FastIndexTests.cs"
    click Program "https://github.com/jonmat/fastindex/blob/main/BenchMark/Program.cs"
    click BenchProj "https://github.com/jonmat/fastindex/blob/main/BenchMark/BenchMark.csproj"

    %% Styles
    classDef core fill:#ADD8E6,stroke:#333,stroke-width:1px
    classDef tests fill:#90EE90,stroke:#333,stroke-width:1px
    classDef bench fill:#FFA500,stroke:#333,stroke-width:1px
    classDef external fill:#CCCCCC,stroke:#333,stroke-width:1px
    classDef storage fill:#8B4513,stroke:#333,stroke-width:1px,stroke-dasharray: 5 5
```
