SWPL — Skew-Phase Law
A data structure selection law under Zipf-skewed workloads.
The Law
Data structure performance under Zipf(α) access is not a continuous degradation — it exhibits sharp phase boundaries in the (α, w) plane, and any fixed structure is provably suboptimal in at least one phase.
Critical threshold: α = 1
The threshold α = 1 is the Riemann ζ convergence point:
| α | ζ(α) | Hot set | Best structure |
|---|---|---|---|
| α ≤ 1 | diverges | Θ(n) — all keys are "hot" | Static B-tree / hash |
| α > 1 | finite | Θ(δ^{-1/(α-1)}) | Adaptive (splay, working-set tree) |
| w ≥ 0.5 | — | — | LSM / write-optimised |
Theorem (SWPL Crossover)
For any comparison-based dictionary on n keys with Zipf(α) access:
- α > 1 + ε → adaptive structure (splay) dominates
- α < 1 − ε → static structure (B-tree) dominates
- ε → 0 as n → ∞
The proof follows from the hot-set scaling lemma: a hot set of size M(δ) = Θ([δ(α−1)ζ(α)]^{-1/(α−1)}) covers (1−δ) of accesses. Splay achieves O(log M), while a static tree must pay Ω(log n) regardless of pattern.
Install
pip install swpl
Quick start
from swpl import recommend, estimate_alpha
# Direct recommendation
rec = recommend(alpha=1.4, write_ratio=0.1, ordered=True)
print(rec["winner"]) # "Adaptive tree (splay / working-set tree)"
print(rec["reason"])
# Estimate α from access log
from pathlib import Path
lines = Path("access.log").read_text().splitlines()
result = analyze_workload(lines, ordered=True)
print(f"Estimated α: {result['estimated_alpha']}")
print(f"Recommended: {result['recommendation']['winner']}")
CLI
# Analyze a workload
swpl analyze access.log
# Direct recommendation from parameters
swpl recommend --alpha 1.5 --ordered
# Generate phase diagrams
swpl plot
Citation
If you use SWPL in your research, cite as:
@misc{zhang2026swpl,
title = {SWPL: A Skew–Phase Law for Data Structure Selection},
author = {Zhang, Yangyi},
year = {2026},
howpublished = {\url{https://github.com/yz1571/swpl}}
}
Repository structure
swpl/
├── pyproject.toml # Build config
├── LICENSE # MIT
├── README.md
├── data/ # Experimental data
└── swpl/
├── __init__.py
├── cli.py # CLI interface
├── recommend.py # Core: Theorem + MLE α estimation + recommendation
└── plot.py # Phase diagram / hot-set / crossover plots
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file swpl-0.1.0.tar.gz.
File metadata
- Download URL: swpl-0.1.0.tar.gz
- Upload date:
- Size: 13.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/7.0.0 CPython/3.13.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
51fb7b789e00c21957550b01af3ef84126f3f26d2e2a7e26c4d7834f4c226a66
|
|
| MD5 |
2e898e9ebd1c37f45a1ef420bb18fba4
|
|
| BLAKE2b-256 |
b7a33028880b94eafa90c0b2f6bd925a4d747cda02458e8b3371ac1495ca937a
|
File details
Details for the file swpl-0.1.0-py3-none-any.whl.
File metadata
- Download URL: swpl-0.1.0-py3-none-any.whl
- Upload date:
- Size: 14.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/7.0.0 CPython/3.13.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d3e75af6c7b149b31a385e16eeb934469bd198c8177a41da6faa6b7bf57c4be4
|
|
| MD5 |
8705b56d08aae6d792caebf5eec1030c
|
|
| BLAKE2b-256 |
de4f2a5d1a6328f2178bc649a86abd1cf0b7f2e5213654423c70d370e3f434ae
|