Skip to content

Commit afae18c

Browse files
Add occs_range in README.md
1 parent 71f85f7 commit afae18c

File tree

5 files changed

+27
-1
lines changed

5 files changed

+27
-1
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "qwt"
3-
version = "0.3.2"
3+
version = "0.3.4"
44
edition = "2021"
55
authors = ["Rossano Venturini <rossano.venturini@unipi.it>"]
66
readme = "README.md"

README.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,29 @@ assert_eq!(qwt.select(4, 0), Some(5));
165165
assert_eq!(qwt.select(1, 3), None);
166166
```
167167

168+
The data structure also supports an efficient `occs_range` operation:
169+
- `occs_range(range)` returns an iterator over pairs `(symbol, count)` for all symbols occurring in the given range of positions.
170+
171+
This operation efficiently computes the distribution of symbol occurrences within a range by traversing only the tree nodes corresponding to symbols actually present, achieving O(k log σ) time complexity where k is the number of distinct symbols in the range. This feature was contributed by Eric Izoita ([@nytopop](https://github.com/nytopop)).
172+
173+
```rust
174+
use qwt::{QWT256, OccsRangeUnsigned};
175+
176+
let data = vec![1u8, 0, 1, 0, 2, 4, 5, 3];
177+
let qwt = QWT256::from(data);
178+
179+
// Count occurrences of each symbol in the range [2..6)
180+
let occs: Vec<_> = qwt.occs_range(2..6).unwrap().collect();
181+
// Returns: [(0, 1), (1, 1), (2, 1), (4, 1)] - symbols 0,1,2,4 each appear once
182+
183+
// Full sequence distribution
184+
let occs: Vec<_> = qwt.occs_range(..).unwrap().collect();
185+
// Returns: [(0, 2), (1, 2), (2, 1), (3, 1), (4, 1), (5, 1)]
186+
187+
// Out-of-bounds ranges return None
188+
assert!(qwt.occs_range(0..100).is_none());
189+
```
190+
168191
In the following example, we use [`QWT256`] to index a sequence over a larger alphabet.
169192

170193
```rust

src/binwt/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -445,6 +445,7 @@ where
445445
{
446446
type Item = (T, usize);
447447

448+
#[inline]
448449
fn next(&mut self) -> Option<Self::Item> {
449450
while let Some(cur) = self.stack.pop() {
450451
// have we reached the bottom of the tree? huffman tree needs slightly different logic to check

src/quadwt/huffqwt.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -755,6 +755,7 @@ where
755755
{
756756
type Item = (T, usize);
757757

758+
#[inline]
758759
fn next(&mut self) -> Option<Self::Item> {
759760
while let Some(cur) = self.stack.pop() {
760761
// SAFETY: assumes tree depth corresponds exactly to max code length in codes_decode

src/quadwt/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -590,6 +590,7 @@ where
590590
{
591591
type Item = (T, usize);
592592

593+
#[inline]
593594
fn next(&mut self) -> Option<Self::Item> {
594595
while let Some(cur) = self.stack.pop() {
595596
// have we reached the bottom of the tree?

0 commit comments

Comments
 (0)