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
Metadata
Release files for swpl 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| swpl-0.1.0.tar.gz | 13.8 kB | Without provenance | Details for swpl-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| swpl-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for swpl-0.1.0-py3-none-any.whl |
Total release size: 28.6 kB
Release files / swpl-0.1.0.tar.gz
| Download URL | swpl-0.1.0.tar.gz |
|---|---|
| Size | 13.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
51fb7b789e00c21957550b01af3ef84126f3f26d2e2a7e26c4d7834f4c226a66
|
|
BLAKE2b-256 checksum How to use checksums |
b7a33028880b94eafa90c0b2f6bd925a4d747cda02458e8b3371ac1495ca937a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.13
|
Release files / swpl-0.1.0-py3-none-any.whl
| Download URL | swpl-0.1.0-py3-none-any.whl |
|---|---|
| Size | 14.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
d3e75af6c7b149b31a385e16eeb934469bd198c8177a41da6faa6b7bf57c4be4
|
|
BLAKE2b-256 checksum How to use checksums |
de4f2a5d1a6328f2178bc649a86abd1cf0b7f2e5213654423c70d370e3f434ae
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.13
|
Security for swpl 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.