Skip to main content

Wavelet Matrix

CI codecov PyPI - Version PyPI - License PyPI - PythonVersion PyPI - Implementation PyPI - Types PyPI Downloads PyPI - Format Rust GitHub Repo stars

High-performance Wavelet Matrix implementation powered by Rust,
supporting fast rank / select / range queries over indexed sequences

Features:

  • Fast rank, select, quantile
  • Rich range queries (freq / sum / top-k / min / max)
  • Optional disk-backed storage for static WaveletMatrix (on_disk=True)
  • Optional dynamic updates (insert / remove / update)

Installation

pip install wavelet-matrix

WaveletMatrix

WaveletMatrix indexes a static sequence of integers,
enabling fast queries where runtime depends on bit-width, not data size.

from wavelet_matrix import WaveletMatrix

data = [5, 4, 5, 5, 2, 1, 5, 6, 1, 3, 5, 0]
wm = WaveletMatrix(data)

WaveletMatrix also supports disk-backed storage for large static sequences.
Set on_disk=True to keep its internal data on disk instead of holding it all in memory.

wm = WaveletMatrix(data, on_disk=True)

Frequency Queries

Count occurrences (rank)

wm.rank(value=5, end=9)
# 4

Find position (select)

wm.select(value=5, kth=4)
# 6

Order Statistics

k-th smallest value (quantile)

wm.quantile(start=2, end=12, kth=8)
# 5

Range Aggregation

Sum values (range_sum)

wm.range_sum(start=2, end=8)
# 24

Count values in [lower, upper) (range_freq)

wm.range_freq(start=1, end=9, lower=4, upper=6)
# 4

List values with counts (range_list)

wm.range_list(start=1, end=9, lower=4, upper=6)
# [{'value': 4, 'count': 1}, {'value': 5, 'count': 3}]

Top-K Queries

Most frequent values (topk)

wm.topk(start=1, end=10, k=2)
# [{'value': 5, 'count': 3}, {'value': 1, 'count': 2}]

Extreme values (range_maxk / range_mink)

wm.range_maxk(start=1, end=9, k=2)
# [{'value': 6, 'count': 1}, {'value': 5, 'count': 3}]
wm.range_mink(start=1, end=9, k=2)
# [{'value': 1, 'count': 2}, {'value': 2, 'count': 1}]

Boundary Queries

wm.prev_value(start=1, end=9, upper=7)
# 6
wm.next_value(start=1, end=9, lower=4)
# 4

DynamicWaveletMatrix

DynamicWaveletMatrix supports mutable sequences with insert/remove/update.

Trade-off:

  • Higher overhead
  • Values must fit within max_bit
from wavelet_matrix import DynamicWaveletMatrix

dwm = DynamicWaveletMatrix(data, max_bit=4)

Insert

dwm.insert(index=4, value=8)

Remove

dwm.remove(index=4)

Update

dwm.update(index=4, value=5)
# or dwm[4] = 5

Development

Running Tests

pip install -e ".[test]"
cargo test --all --release
pytest

Formating Code

pip install -e ".[dev]"
cargo fmt
ruff format

Generating Docs

pdoc wavelet_matrix \
      --output-directory docs \
      --no-search \
      --docformat markdown \
      --template-directory pdoc_templates

References

  • Francisco Claude, Gonzalo Navarro, Alberto Ordóñez,
    The wavelet matrix: An efficient wavelet tree for large alphabets,
    Information Systems,
    Volume 47,
    2015,
    Pages 15-32,
    ISSN 0306-4379,
    https://doi.org/10.1016/j.is.2014.06.002.

Release files for wavelet-matrix 3.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for wavelet-matrix 3.0.0
File Size Uploaded
wavelet_matrix-3.0.0.tar.gz 71.0 kB Details

Built distributions (wheels)

Table of built distributions (wheels) for wavelet-matrix 3.0.0
File
wavelet_matrix-3.0.0-cp39-abi3-win_amd64.whl CPython 3.9 abi3 Windows x86-64 Details
wavelet_matrix-3.0.0-cp39-abi3-win32.whl CPython 3.9 abi3 Windows x86-32 Details
wavelet_matrix-3.0.0-cp39-abi3-musllinux_1_2_x86_64.whl CPython 3.9 abi3 Linux musl 1.2+ x86-64 Details
wavelet_matrix-3.0.0-cp39-abi3-musllinux_1_2_i686.whl CPython 3.9 abi3 Linux musl 1.2+ x86-32 Details
wavelet_matrix-3.0.0-cp39-abi3-musllinux_1_2_armv7l.whl CPython 3.9 abi3 Linux musl 1.2+ ARMv7l Details
wavelet_matrix-3.0.0-cp39-abi3-musllinux_1_2_aarch64.whl CPython 3.9 abi3 Linux musl 1.2+ ARM64 Details
wavelet_matrix-3.0.0-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.9 abi3 Linux glibc 2.17+ x86-64 Details
wavelet_matrix-3.0.0-cp39-abi3-manylinux_2_17_s390x.manylinux2014_s390x.whl CPython 3.9 abi3 Linux glibc 2.17+ IBM System/390x Details
wavelet_matrix-3.0.0-cp39-abi3-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl CPython 3.9 abi3 Linux glibc 2.17+ PowerPC 64-le Details
wavelet_matrix-3.0.0-cp39-abi3-manylinux_2_17_i686.manylinux2014_i686.whl CPython 3.9 abi3 Linux glibc 2.17+ x86-32 Details
wavelet_matrix-3.0.0-cp39-abi3-manylinux_2_17_armv7l.manylinux2014_armv7l.whl CPython 3.9 abi3 Linux glibc 2.17+ ARMv7l Details
wavelet_matrix-3.0.0-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl CPython 3.9 abi3 Linux glibc 2.17+ ARM64 Details
wavelet_matrix-3.0.0-cp39-abi3-macosx_11_0_arm64.whl CPython 3.9 abi3 macOS 11.0+ ARM64 Details
wavelet_matrix-3.0.0-cp39-abi3-macosx_10_12_x86_64.whl CPython 3.9 abi3 macOS 10.12+ x86-64 Details

Total release size: 14.3 MB

Release files / wavelet_matrix-3.0.0.tar.gz

Download URL wavelet_matrix-3.0.0.tar.gz
Size 71.0 kB
Tags Source
SHA-256 checksum
How to use checksums
fcbfd3729bac8055ff416a64e85416e1df334e2aa68549e3a81afc64a1f04ab2
BLAKE2b-256 checksum
How to use checksums
40cc4dd49a4f0f6bbe15383e7adf68e6bde95fd20fa5ad75938b3fbd55799ad3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 30, 2026.

Transparency log

Release files / wavelet_matrix-3.0.0-cp39-abi3-win_amd64.whl

Download URL wavelet_matrix-3.0.0-cp39-abi3-win_amd64.whl
Size 643.2 kB
Tags CPython 3.9 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
2040d2d234f920ab68c77aa4b8a9b0f9d9b5518268b0084d5ac861cf6b3404d3
BLAKE2b-256 checksum
How to use checksums
57f8d0e932cbe5d88f24563f04262f1049d0e6d2f931c1a6b29939e52d3cca87
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 30, 2026.

Transparency log

Release files / wavelet_matrix-3.0.0-cp39-abi3-win32.whl

Download URL wavelet_matrix-3.0.0-cp39-abi3-win32.whl
Size 620.9 kB
Tags CPython 3.9 Windows x86-32 abi3
SHA-256 checksum
How to use checksums
792e9c71d449a01aab42691fe5bf2943c4b5b05a59ec0a80267ecf7ad992257c
BLAKE2b-256 checksum
How to use checksums
c41cc7addc9223a9dff84cf6b590801ee5eb136fa75ad71da848d9c4d0bfb581
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 30, 2026.

Transparency log

Release files / wavelet_matrix-3.0.0-cp39-abi3-musllinux_1_2_x86_64.whl

Download URL wavelet_matrix-3.0.0-cp39-abi3-musllinux_1_2_x86_64.whl
Size 1.2 MB
Tags CPython 3.9 Linux musl 1.2+ x86-64 abi3
SHA-256 checksum
How to use checksums
80ef107ef69ab42071e071499d63747e3c06127cceb0270866c79790e6c63c49
BLAKE2b-256 checksum
How to use checksums
7c14feca70398669a00ca3d16e55ee0208a0bde14fd8f61e23dfe37627459dc1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 30, 2026.

Transparency log

Release files / wavelet_matrix-3.0.0-cp39-abi3-musllinux_1_2_i686.whl

Download URL wavelet_matrix-3.0.0-cp39-abi3-musllinux_1_2_i686.whl
Size 1.3 MB
Tags CPython 3.9 Linux musl 1.2+ x86-32 abi3
SHA-256 checksum
How to use checksums
b0a0d5a3334502e75bc0f3200b06413e1cccdf4cbff39e7aa91f35d925757082
BLAKE2b-256 checksum
How to use checksums
e618779a9b4bfddb796b4a96855b32e340ed1d2d4e34df210b1f70fa12a9ba4f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 30, 2026.

Transparency log

Release files / wavelet_matrix-3.0.0-cp39-abi3-musllinux_1_2_armv7l.whl

Download URL wavelet_matrix-3.0.0-cp39-abi3-musllinux_1_2_armv7l.whl
Size 1.3 MB
Tags CPython 3.9 Linux musl 1.2+ ARMv7l abi3
SHA-256 checksum
How to use checksums
be7edcef58d20376c8a603ddedb1dfb27a6be198569ca4e4a17ef53c50e51d67
BLAKE2b-256 checksum
How to use checksums
0d957821d8b680023552a905783eb9aa643fba5731ec3f359f6d6348a95aaa09
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 30, 2026.

Transparency log

Release files / wavelet_matrix-3.0.0-cp39-abi3-musllinux_1_2_aarch64.whl

Download URL wavelet_matrix-3.0.0-cp39-abi3-musllinux_1_2_aarch64.whl
Size 1.1 MB
Tags CPython 3.9 Linux musl 1.2+ ARM64 abi3
SHA-256 checksum
How to use checksums
32e92a1810c88e5439c486e97489af9b45757509dca1a3190b98f3f9da59406f
BLAKE2b-256 checksum
How to use checksums
76634dbcbd6dfcd596fb1d6d92ff211d9886641e09bb51d77edc2f441930111a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 30, 2026.

Transparency log

Release files / wavelet_matrix-3.0.0-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL wavelet_matrix-3.0.0-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 934.3 kB
Tags CPython 3.9 Linux glibc 2.17+ x86-64 abi3
SHA-256 checksum
How to use checksums
ef5f2ea2eab8d4d7d5483374619a6e7de0fe4feb97b2fb75c9b9adbca4979432
BLAKE2b-256 checksum
How to use checksums
06f19660e8a35c41f7056de5c798348681fb22b4bb4923ca911b9da49749c6df
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 30, 2026.

Transparency log

Release files / wavelet_matrix-3.0.0-cp39-abi3-manylinux_2_17_s390x.manylinux2014_s390x.whl

Download URL wavelet_matrix-3.0.0-cp39-abi3-manylinux_2_17_s390x.manylinux2014_s390x.whl
Size 1.0 MB
Tags CPython 3.9 Linux glibc 2.17+ IBM System/390x abi3
SHA-256 checksum
How to use checksums
dc8bfe1c7dd25a7f792c3adbc864d9ba2899fa3b5e8d1adb2288ad2fd986612f
BLAKE2b-256 checksum
How to use checksums
c5b4cc9aa12ed09b0852ffb3cdcd5092a25e724a8a8cc4c1f5133ad7df75f6a2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 30, 2026.

Transparency log

Release files / wavelet_matrix-3.0.0-cp39-abi3-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl

Download URL wavelet_matrix-3.0.0-cp39-abi3-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl
Size 1.1 MB
Tags CPython 3.9 Linux glibc 2.17+ PowerPC 64-le abi3
SHA-256 checksum
How to use checksums
a1f4baf9a1ba2f73db7c5979710b468f2d59bccb3c2533579d393f074875d5d4
BLAKE2b-256 checksum
How to use checksums
f9553ebc728eff66467bbdf0939d6680ab17d285befb15db7f46a4455e0bc901
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 30, 2026.

Transparency log

Release files / wavelet_matrix-3.0.0-cp39-abi3-manylinux_2_17_i686.manylinux2014_i686.whl

Download URL wavelet_matrix-3.0.0-cp39-abi3-manylinux_2_17_i686.manylinux2014_i686.whl
Size 1.1 MB
Tags CPython 3.9 Linux glibc 2.17+ x86-32 abi3
SHA-256 checksum
How to use checksums
92624fbf1e40bef0f5dc33a597fdefd70a5abe7d49dc2b01ea32390d00c83f46
BLAKE2b-256 checksum
How to use checksums
6883b84b9337d9a10267b20f4ea7d568cb927459e65ffc155c375dad894744ee
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 30, 2026.

Transparency log

Release files / wavelet_matrix-3.0.0-cp39-abi3-manylinux_2_17_armv7l.manylinux2014_armv7l.whl

Download URL wavelet_matrix-3.0.0-cp39-abi3-manylinux_2_17_armv7l.manylinux2014_armv7l.whl
Size 1.1 MB
Tags CPython 3.9 Linux glibc 2.17+ ARMv7l abi3
SHA-256 checksum
How to use checksums
0fde87bb2b46b2afee565c8726a7bcfe7fd9da9ee1ef483f8cd8febf5f9f2cd5
BLAKE2b-256 checksum
How to use checksums
5bf3618416b6735ea95149d92506ee355e5876f7ab54a7c9d535a404c0b20013
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 30, 2026.

Transparency log

Release files / wavelet_matrix-3.0.0-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl

Download URL wavelet_matrix-3.0.0-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Size 954.7 kB
Tags CPython 3.9 Linux glibc 2.17+ ARM64 abi3
SHA-256 checksum
How to use checksums
7dd7c2dd5abf9079b5aad4252f709863625363f06da3059a93e1503ca6eb1422
BLAKE2b-256 checksum
How to use checksums
c8fc5d375d49ff1abb707acb29e19f6d4d1188244ff482bc849626c855a08b67
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 30, 2026.

Transparency log

Release files / wavelet_matrix-3.0.0-cp39-abi3-macosx_11_0_arm64.whl

Download URL wavelet_matrix-3.0.0-cp39-abi3-macosx_11_0_arm64.whl
Size 841.9 kB
Tags CPython 3.9 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
80a5be814b355a456b0eb6c2b9ba0b5a13fdf6954f371bb8937eb51315d23645
BLAKE2b-256 checksum
How to use checksums
2a8e1745d43ffbeed6142a3391a6d9dec70377f0db9b76c7613c623a3b146f9e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 30, 2026.

Transparency log

Release files / wavelet_matrix-3.0.0-cp39-abi3-macosx_10_12_x86_64.whl

Download URL wavelet_matrix-3.0.0-cp39-abi3-macosx_10_12_x86_64.whl
Size 880.0 kB
Tags CPython 3.9 abi3 macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
ae6f3bafae96e33f9f9cd59283567b18bb3cd57d42df0de84a80ac94c8116d63
BLAKE2b-256 checksum
How to use checksums
d3e0607dff417431ccf4253fa5168b2ed3e7cb0d49cb02c90bac36656ccb5836
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 30, 2026.

Transparency log
Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page