paged-collections
Paged sparse sets, maps, a priority queue and stable-address containers for
Rust (no_std + alloc), with Python bindings built on PyO3 and NumPy.
- Paged index: a key-indexed table split into pages allocated on first
use, so index pages follow the occupied key ranges. The default
Flatdirectory still holds one pointer per page up to the largest key; for keys spread over a wide range, theRadixandTreedirectories avoid that. - Paged storage: elements keep their addresses as the container grows.
Install
Wheels cover CPython 3.10+ (abi3) and free-threaded 3.14t and 3.15t+.
See Installation.
Example
Rust:
use PagedDirectMap;
use Hive;
use Id;
let mut hive: = new;
let a = hive.insert;
let b = hive.insert;
let mut score: = new;
score.insert;
score.insert;
// Removing frees the slot; its next occupant gets a new generation, so the
// stale id misses in the hive, and the new id misses the side-table entry
// left by the old one. Side tables are not cleaned up automatically.
hive.remove;
let c = hive.insert;
assert_eq!;
assert_eq!;
assert_eq!;
assert_eq!;
// A direct map iterates in slot order and answers range queries.
let in_range: = score.range.map.collect;
assert_eq!;
Python:
=
# batch insert
= 2.5
# array([2.5, 1. ])
= # zero-copy, writeable
*= 2 # updates the map in place
del # resizing raises BufferError while a view is alive
Containers
| Rust | Python | Paging | Purpose |
|---|---|---|---|
PagedSparseSet<K> |
SparseSet |
index | Integer set: O(1) insert, remove, contains, clear; dense iteration |
PagedSparseMap<K, V> |
SparseMap, SparseMapF64, ... |
index | Sparse set with a dense value array |
PagedDirectMap<K, V> |
DirectMap, DirectMapF64, ... |
index | Values in place; key order and range queries |
PagedPriorityQueue<K, P> |
PriorityQueue, PriorityQueueF64 |
index | Indexed heap: priority changes and removal by key |
PagedVec<T> |
PagedList, PagedListF64, ... |
storage | Growable vector with stable addresses |
PagedDeque<T> |
PagedDeque |
storage | Double-ended queue with stable addresses |
Hive<T> |
Hive |
storage | Unordered slots with generational ids |
IdAllocator |
IdAllocator, IdMap |
none | Generational ids for use as keys |
The concurrent feature adds thread-safe variants: ConcurrentHive,
ConcurrentAppendHive, ConcurrentPagedVec, ConcurrentSparseSet/Map,
ConcurrentDirectMap, AtomicDirectMap, AtomicIdMap and
ConcurrentIdAllocator. Python binds the primitive-valued concurrent sets and
maps.
Documentation
- Paging model:
page sizes,
Flat/Radix/Treedirectories, memory behaviour. - Choosing a container: when each container fits, and when a standard one is better.
- Benchmarks: reference measurements and the commands to reproduce them.
- API: docs.rs (Rust),
_core.pyi(Python).
Layout
paged-collections/
├── crates/
│ ├── paged-collections/ # Rust library (no_std + alloc)
│ ├── paged-collections-python/ # PyO3 bindings for the _core extension
│ └── bench/ # Rust benchmarks outside the default build
├── python/
│ └── paged_collections/ # Python sources and type stubs
├── tests/ # Python tests
├── benchmarks/
│ └── python/ # Python benchmarks
└── docs/
└── site/ # mdBook documentation
Development commands are in CONTRIBUTING.md.
License
Licensed under either of
- Apache License, Version 2.0 (LICENSE-APACHE)
- MIT license (LICENSE-MIT)
at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in this work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.