# florents-tselai/pgxicor architecture

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

- Interactive diagram: https://gitdiagram.com/florents-tselai/pgxicor
- Repository: https://github.com/florents-tselai/pgxicor

## Overview

pgxicor is a PostgreSQL extension that exposes XI correlation as the `xicor(X, Y)` aggregate. The main workflow collects input pairs in aggregate state, converts the accumulated arrays into an XI problem, computes the score using sorted X ranks and Y ranks, and returns a float. Optional tie handling and reproducibility settings are configured through PostgreSQL variables. The score implementation and helper declarations share the two core source files; edges below follow visible calls, while PostgreSQL’s aggregate dispatch is documented in the README but its SQL registration was not sampled.

Main entry points: [`src/pgxicor.c`](https://github.com/florents-tselai/pgxicor/blob/main/src/pgxicor.c) (Aggregate finalizer), [`src/pgxicor.h`](https://github.com/florents-tselai/pgxicor/blob/main/src/pgxicor.h) (Input problem types)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_aggregate["Aggregate workflow"]
  node_transition["State transition<br/>[pgxicor.c]"]
  node_finalize["Aggregate finalizer<br/>[pgxicor.c]"]
  node_settings["XI settings<br/>[pgxicor.c]"]
end

subgraph group_calculation["XI calculation"]
  node_problem["Input problem types<br/>[pgxicor.h]"]
  node_builder["Array input builder<br/>[pgxicor.c]"]
  node_score["XI score<br/>[pgxicor.c]"]
  node_ordering["Argsort helpers<br/>[pgxicor.c]"]
end

node_query(("SQL caller"))

node_query -->|"aggregates pairs"| node_transition
node_transition -.->|"returns state"| node_finalize
node_finalize -->|"reads settings"| node_settings
node_finalize -->|"builds problem"| node_builder
node_builder -->|"fills arrays"| node_problem
node_finalize -->|"computes score"| node_score
node_score -->|"sorts X"| node_ordering

click node_transition "https://github.com/florents-tselai/pgxicor/blob/main/src/pgxicor.c"
click node_finalize "https://github.com/florents-tselai/pgxicor/blob/main/src/pgxicor.c"
click node_problem "https://github.com/florents-tselai/pgxicor/blob/main/src/pgxicor.h"
click node_builder "https://github.com/florents-tselai/pgxicor/blob/main/src/pgxicor.c"
click node_score "https://github.com/florents-tselai/pgxicor/blob/main/src/pgxicor.c"
click node_ordering "https://github.com/florents-tselai/pgxicor/blob/main/src/pgxicor.c"
click node_settings "https://github.com/florents-tselai/pgxicor/blob/main/src/pgxicor.c"

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_transition,node_finalize,node_settings toneBlue
class node_problem,node_builder,node_score,node_ordering toneAmber
class node_query toneIndigo
```

## Components

### Aggregate workflow

- [State transition](https://github.com/florents-tselai/pgxicor/blob/main/src/pgxicor.c): `src/pgxicor.c`
- [Aggregate finalizer](https://github.com/florents-tselai/pgxicor/blob/main/src/pgxicor.c): `src/pgxicor.c`
- [XI settings](https://github.com/florents-tselai/pgxicor/blob/main/src/pgxicor.c): `src/pgxicor.c`

### XI calculation

- [Input problem types](https://github.com/florents-tselai/pgxicor/blob/main/src/pgxicor.h): `src/pgxicor.h`
- [Array input builder](https://github.com/florents-tselai/pgxicor/blob/main/src/pgxicor.c): `src/pgxicor.c`
- [XI score](https://github.com/florents-tselai/pgxicor/blob/main/src/pgxicor.c): `src/pgxicor.c`
- [Argsort helpers](https://github.com/florents-tselai/pgxicor/blob/main/src/pgxicor.c): `src/pgxicor.c`

### Other components

- **SQL caller**

## Connections

- SQL caller → State transition: aggregates pairs (evidence: `README.md`)
- State transition → Aggregate finalizer: returns state (evidence: `src/pgxicor.c`)
- Aggregate finalizer → XI settings: reads settings (evidence: `src/pgxicor.c`)
- Aggregate finalizer → Array input builder: builds problem (evidence: `src/pgxicor.c`)
- Array input builder → Input problem types: fills arrays (evidence: `src/pgxicor.c`)
- Aggregate finalizer → XI score: computes score (evidence: `src/pgxicor.c`)
- XI score → Argsort helpers: sorts X (evidence: `src/pgxicor.c`)
