wavelet-matrix 2.0.9__pp311-pypy311_pp73-musllinux_1_2_x86_64.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- wavelet_matrix/__init__.py +5 -0
- wavelet_matrix/__init__.pyi +64 -0
- wavelet_matrix/py.typed +0 -0
- wavelet_matrix/wavelet_matrix.pypy311-pp73-x86_64-linux-gnu.so +0 -0
- wavelet_matrix-2.0.9.dist-info/METADATA +212 -0
- wavelet_matrix-2.0.9.dist-info/RECORD +9 -0
- wavelet_matrix-2.0.9.dist-info/WHEEL +4 -0
- wavelet_matrix-2.0.9.dist-info/licenses/LICENSE +7 -0
- wavelet_matrix.libs/libgcc_s-6d2d9dc8.so.1 +0 -0
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
from typing import Iterable
|
|
2
|
+
|
|
3
|
+
class WaveletMatrix:
|
|
4
|
+
def __init__(self, data: Iterable[int]) -> None: ...
|
|
5
|
+
def __getitem__(self, index: int) -> int: ...
|
|
6
|
+
def __len__(self) -> int: ...
|
|
7
|
+
def __str__(self) -> str: ...
|
|
8
|
+
def __repr__(self) -> str: ...
|
|
9
|
+
def __copy__(self) -> WaveletMatrix: ...
|
|
10
|
+
def __deepcopy__(self, memo) -> WaveletMatrix: ...
|
|
11
|
+
def values(self) -> list[int]: ...
|
|
12
|
+
def access(self, index: int) -> int: ...
|
|
13
|
+
def rank(self, value: int, end: int) -> int: ...
|
|
14
|
+
def select(self, value: int, kth: int) -> int | None: ...
|
|
15
|
+
def quantile(self, start: int, end: int, kth: int) -> int: ...
|
|
16
|
+
def topk(self, start: int, end: int, k: int | None = None) -> list[dict[str, int]]: ...
|
|
17
|
+
def range_sum(self, start: int, end: int) -> int: ...
|
|
18
|
+
def range_intersection(
|
|
19
|
+
self, start1: int, end1: int, start2: int, end2: int
|
|
20
|
+
) -> list[dict[str, int]]: ...
|
|
21
|
+
def range_freq(
|
|
22
|
+
self, start: int, end: int, lower: int | None = None, upper: int | None = None
|
|
23
|
+
) -> int: ...
|
|
24
|
+
def range_list(
|
|
25
|
+
self, start: int, end: int, lower: int | None = None, upper: int | None = None
|
|
26
|
+
) -> list[dict[str, int]]: ...
|
|
27
|
+
def range_maxk(self, start: int, end: int, k: int | None = None) -> list[dict[str, int]]: ...
|
|
28
|
+
def range_mink(self, start: int, end: int, k: int | None = None) -> list[dict[str, int]]: ...
|
|
29
|
+
def prev_value(self, start: int, end: int, upper: int | None = None) -> int | None: ...
|
|
30
|
+
def next_value(self, start: int, end: int, lower: int | None = None) -> int | None: ...
|
|
31
|
+
|
|
32
|
+
class DynamicWaveletMatrix:
|
|
33
|
+
def __init__(self, data: Iterable[int], max_bit: int | None = None) -> None: ...
|
|
34
|
+
def __getitem__(self, index: int) -> int: ...
|
|
35
|
+
def __setitem__(self, index: int, value: int) -> None: ...
|
|
36
|
+
def __len__(self) -> int: ...
|
|
37
|
+
def __str__(self) -> str: ...
|
|
38
|
+
def __repr__(self) -> str: ...
|
|
39
|
+
def __copy__(self) -> DynamicWaveletMatrix: ...
|
|
40
|
+
def __deepcopy__(self, memo) -> DynamicWaveletMatrix: ...
|
|
41
|
+
def values(self) -> list[int]: ...
|
|
42
|
+
def access(self, index: int) -> int: ...
|
|
43
|
+
def rank(self, value: int, end: int) -> int: ...
|
|
44
|
+
def select(self, value: int, kth: int) -> int | None: ...
|
|
45
|
+
def quantile(self, start: int, end: int, kth: int) -> int: ...
|
|
46
|
+
def topk(self, start: int, end: int, k: int | None = None) -> list[dict[str, int]]: ...
|
|
47
|
+
def range_sum(self, start: int, end: int) -> int: ...
|
|
48
|
+
def range_intersection(
|
|
49
|
+
self, start1: int, end1: int, start2: int, end2: int
|
|
50
|
+
) -> list[dict[str, int]]: ...
|
|
51
|
+
def range_freq(
|
|
52
|
+
self, start: int, end: int, lower: int | None = None, upper: int | None = None
|
|
53
|
+
) -> int: ...
|
|
54
|
+
def range_list(
|
|
55
|
+
self, start: int, end: int, lower: int | None = None, upper: int | None = None
|
|
56
|
+
) -> list[dict[str, int]]: ...
|
|
57
|
+
def range_maxk(self, start: int, end: int, k: int | None = None) -> list[dict[str, int]]: ...
|
|
58
|
+
def range_mink(self, start: int, end: int, k: int | None = None) -> list[dict[str, int]]: ...
|
|
59
|
+
def prev_value(self, start: int, end: int, upper: int | None = None) -> int | None: ...
|
|
60
|
+
def next_value(self, start: int, end: int, lower: int | None = None) -> int | None: ...
|
|
61
|
+
def max_bit(self) -> int: ...
|
|
62
|
+
def insert(self, index: int, value: int) -> None: ...
|
|
63
|
+
def remove(self, index: int) -> int: ...
|
|
64
|
+
def update(self, index: int, value: int) -> int: ...
|
wavelet_matrix/py.typed
ADDED
|
File without changes
|
|
Binary file
|
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: wavelet-matrix
|
|
3
|
+
Version: 2.0.9
|
|
4
|
+
Classifier: Intended Audience :: Developers
|
|
5
|
+
Classifier: Intended Audience :: Science/Research
|
|
6
|
+
Classifier: Intended Audience :: Information Technology
|
|
7
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
8
|
+
Classifier: Programming Language :: Python :: 3
|
|
9
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
10
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
11
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
15
|
+
Classifier: Programming Language :: Python :: Implementation :: CPython
|
|
16
|
+
Classifier: Programming Language :: Python :: Implementation :: PyPy
|
|
17
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
18
|
+
Classifier: Topic :: Scientific/Engineering :: Information Analysis
|
|
19
|
+
Classifier: Topic :: Scientific/Engineering :: Mathematics
|
|
20
|
+
Classifier: Typing :: Typed
|
|
21
|
+
Requires-Dist: pdoc>=16.0 ; extra == 'dev'
|
|
22
|
+
Requires-Dist: ruff>=0.14 ; extra == 'dev'
|
|
23
|
+
Requires-Dist: pytest>=7.0 ; extra == 'test'
|
|
24
|
+
Requires-Dist: pytest-benchmark>=4.0 ; extra == 'test'
|
|
25
|
+
Provides-Extra: dev
|
|
26
|
+
Provides-Extra: test
|
|
27
|
+
License-File: LICENSE
|
|
28
|
+
Summary: High-performance indexed sequence data structure powered by Rust, supporting fast rank/select and range queries.
|
|
29
|
+
Keywords: wavelet matrix,data structure,algorithm,sequence index,rank,select,quantile,top-k,range query,dynamic update,indexing,succinct
|
|
30
|
+
Author: Koki Watanabe
|
|
31
|
+
Requires-Python: >=3.9
|
|
32
|
+
Description-Content-Type: text/markdown; charset=UTF-8; variant=GFM
|
|
33
|
+
Project-URL: documentation, https://math-hiyoko.github.io/wavelet-matrix
|
|
34
|
+
Project-URL: homepage, https://github.com/math-hiyoko/wavelet-matrix
|
|
35
|
+
Project-URL: repository, https://github.com/math-hiyoko/wavelet-matrix
|
|
36
|
+
|
|
37
|
+
# Wavelet Matrix
|
|
38
|
+
|
|
39
|
+
[](https://github.com/math-hiyoko/wavelet-matrix/actions/workflows/CI.yml)
|
|
40
|
+
[](https://codecov.io/gh/math-hiyoko/wavelet-matrix)
|
|
41
|
+

|
|
42
|
+

|
|
43
|
+

|
|
44
|
+

|
|
45
|
+

|
|
46
|
+
[](https://pepy.tech/projects/wavelet-matrix)
|
|
47
|
+

|
|
48
|
+

|
|
49
|
+

|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
High-performance Wavelet Matrix implementation powered by Rust,
|
|
53
|
+
supporting fast rank / select / range queries over indexed sequences
|
|
54
|
+
|
|
55
|
+
- PyPI: https://pypi.org/project/wavelet-matrix
|
|
56
|
+
- Document: https://math-hiyoko.github.io/wavelet-matrix
|
|
57
|
+
- Repository: https://github.com/math-hiyoko/wavelet-matrix
|
|
58
|
+
|
|
59
|
+
## Features:
|
|
60
|
+
- Fast rank, select, quantile
|
|
61
|
+
- Rich range queries (freq / sum / top-k / min / max)
|
|
62
|
+
- Optional dynamic updates (insert / remove / update)
|
|
63
|
+
- Safe Rust (no unsafe)
|
|
64
|
+
|
|
65
|
+
## Installation
|
|
66
|
+
```bash
|
|
67
|
+
pip install wavelet-matrix
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
## WaveletMatrix
|
|
71
|
+
WaveletMatrix indexes a static sequence of integers,
|
|
72
|
+
enabling fast queries where runtime depends on bit-width, not data size.
|
|
73
|
+
```python
|
|
74
|
+
from wavelet_matrix import WaveletMatrix
|
|
75
|
+
|
|
76
|
+
data = [5, 4, 5, 5, 2, 1, 5, 6, 1, 3, 5, 0]
|
|
77
|
+
wm = WaveletMatrix(data)
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
### Frequency Queries
|
|
81
|
+
#### Count occurrences (rank)
|
|
82
|
+
```python
|
|
83
|
+
wm.rank(value=5, end=9)
|
|
84
|
+
# 4
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
#### Find position (select)
|
|
88
|
+
```python
|
|
89
|
+
wm.select(value=5, kth=4)
|
|
90
|
+
# 6
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
### Order Statistics
|
|
94
|
+
#### k-th smallest value (quantile)
|
|
95
|
+
```python
|
|
96
|
+
wm.quantile(start=2, end=12, kth=8)
|
|
97
|
+
# 5
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
### Range Aggregation
|
|
101
|
+
#### Sum values (range_sum)
|
|
102
|
+
```python
|
|
103
|
+
wm.range_sum(start=2, end=8)
|
|
104
|
+
# 24
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
#### Count values in [lower, upper) (range_freq)
|
|
108
|
+
```python
|
|
109
|
+
wm.range_freq(start=1, end=9, lower=4, upper=6)
|
|
110
|
+
# 4
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
#### List values with counts (range_list)
|
|
114
|
+
```python
|
|
115
|
+
wm.range_list(start=1, end=9, lower=4, upper=6)
|
|
116
|
+
# [{'value': 4, 'count': 1}, {'value': 5, 'count': 3}]
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
### Top-K Queries
|
|
120
|
+
#### Most frequent values (topk)
|
|
121
|
+
```python
|
|
122
|
+
wm.topk(start=1, end=10, k=2)
|
|
123
|
+
# [{'value': 5, 'count': 3}, {'value': 1, 'count': 2}]
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
#### Extreme values (range_maxk / range_mink)
|
|
127
|
+
```python
|
|
128
|
+
wm.range_maxk(start=1, end=9, k=2)
|
|
129
|
+
# [{'value': 6, 'count': 1}, {'value': 5, 'count': 3}]
|
|
130
|
+
wm.range_mink(start=1, end=9, k=2)
|
|
131
|
+
# [{'value': 1, 'count': 2}, {'value': 2, 'count': 1}]
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
### Boundary Queries
|
|
135
|
+
```python
|
|
136
|
+
wm.prev_value(start=1, end=9, upper=7)
|
|
137
|
+
# 6
|
|
138
|
+
wm.next_value(start=1, end=9, lower=4)
|
|
139
|
+
# 4
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
## DynamicWaveletMatrix
|
|
143
|
+
DynamicWaveletMatrix supports mutable sequences with insert/remove/update.
|
|
144
|
+
|
|
145
|
+
### Trade-off:
|
|
146
|
+
- Higher overhead
|
|
147
|
+
- Values must fit within max_bit
|
|
148
|
+
|
|
149
|
+
```python
|
|
150
|
+
from wavelet_matrix import DynamicWaveletMatrix
|
|
151
|
+
|
|
152
|
+
dwm = DynamicWaveletMatrix(data, max_bit=4)
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
### Insert
|
|
156
|
+
```python
|
|
157
|
+
dwm.insert(index=4, value=8)
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
#### Remove
|
|
161
|
+
```python
|
|
162
|
+
dwm.remove(index=4)
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
#### Update
|
|
166
|
+
```python
|
|
167
|
+
dwm.update(index=4, value=5)
|
|
168
|
+
# or dwm[4] = 5
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
## Safety
|
|
172
|
+
- Powered by safe Rust
|
|
173
|
+
- Memory-safe by design
|
|
174
|
+
|
|
175
|
+
## Development
|
|
176
|
+
|
|
177
|
+
### Running Tests
|
|
178
|
+
|
|
179
|
+
```bash
|
|
180
|
+
pip install -e ".[test]"
|
|
181
|
+
cargo test --all --release
|
|
182
|
+
pytest
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
### Formating Code
|
|
186
|
+
```bash
|
|
187
|
+
pip install -e ".[dev]"
|
|
188
|
+
cargo fmt
|
|
189
|
+
ruff format
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
### Generating Docs
|
|
193
|
+
```bash
|
|
194
|
+
pdoc wavelet_matrix \
|
|
195
|
+
--output-directory docs \
|
|
196
|
+
--no-search \
|
|
197
|
+
--no-show-source \
|
|
198
|
+
--docformat markdown \
|
|
199
|
+
--footer-text "© 2026 Koki Watanabe"
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
## References
|
|
203
|
+
|
|
204
|
+
- Francisco Claude, Gonzalo Navarro, Alberto Ordóñez,
|
|
205
|
+
The wavelet matrix: An efficient wavelet tree for large alphabets,
|
|
206
|
+
Information Systems,
|
|
207
|
+
Volume 47,
|
|
208
|
+
2015,
|
|
209
|
+
Pages 15-32,
|
|
210
|
+
ISSN 0306-4379,
|
|
211
|
+
https://doi.org/10.1016/j.is.2014.06.002.
|
|
212
|
+
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
wavelet_matrix/__init__.py,sha256=bY2bBHUr5LI7lsksSDxTm_ZQY6vJGBV63B5ryuJVa-U,139
|
|
2
|
+
wavelet_matrix/__init__.pyi,sha256=ZhfsOeBaakGgxmBuCTPYIOsdUPw15Inu2Iilq6DIzRw,3372
|
|
3
|
+
wavelet_matrix/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
4
|
+
wavelet_matrix/wavelet_matrix.pypy311-pp73-x86_64-linux-gnu.so,sha256=cBSS_NsBbcmWCp6Ld7ZLLsCwAreG1j3rjiKnnZal1wk,1612817
|
|
5
|
+
wavelet_matrix-2.0.9.dist-info/METADATA,sha256=nEoDk370GapDkV9S6tuKslPSxATy3kO8sdbnwhLuCwk,6076
|
|
6
|
+
wavelet_matrix-2.0.9.dist-info/WHEEL,sha256=AB_wCyK6eMCl2NJbf2L4OumdNgjcLIWsUEFQdaYvsxE,115
|
|
7
|
+
wavelet_matrix-2.0.9.dist-info/licenses/LICENSE,sha256=RLItjifD2pjpecDwt0BdQ7bFR6517amHYtkEENvrPac,1060
|
|
8
|
+
wavelet_matrix.libs/libgcc_s-6d2d9dc8.so.1,sha256=K3sghe0OS1atTYJSB8m0plft2csyIC36q20Ii8UMudc,536145
|
|
9
|
+
wavelet_matrix-2.0.9.dist-info/RECORD,,
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
Copyright 2025 Koki Watanabe
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
4
|
+
|
|
5
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
6
|
+
|
|
7
|
+
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
Binary file
|