---
name: calculate_page_offset
kind: function
lang: py
domain: core
version: "1.0.0"
purity: pure
signature: "def calculate_page_offset(pairs: list[dict]) -> int"
description: "Calcula offset entre numeros de pagina logicos y fisicos usando pares de referencia (moda de diferencias)."
tags: [pagination, offset, calculation]
uses_functions: []
uses_types: []
returns: []
returns_optional: false
error_type: ""
imports: []
params:
  - name: pairs
    desc: "lista de dicts con campos 'page' (numero logico) y 'physical_index' (indice fisico)"
output: "entero con el offset (diferencia moda entre physical_index - page)"
tested: false
tests: []
test_file_path: ""
file_path: "python/functions/core/core.py"
source_repo: "https://github.com/VectifyAI/PageIndex"
source_license: "MIT"
source_file: "pageindex/page_index.py"
---

## Ejemplo

```python
pairs = [
    {"page": 1, "physical_index": 5},
    {"page": 2, "physical_index": 6},
    {"page": 10, "physical_index": 14},
]
calculate_page_offset(pairs)
# 4 (la moda de las diferencias physical_index - page)
```

## Notas

Funcion pura. Cada par necesita campos 'page' (numero logico) y 'physical_index' (indice fisico). Retorna la diferencia mas frecuente (moda). Retorna 0 si no hay pares validos.
