weighted-gss
A persistent weighted graph-structured stack, implemented in Rust with Python bindings.
weighted-gss represents a finite map from complete stacks to weights. Stack suffixes are shared in a compact graph, and whenever stack operations make two stacks identical, their weights are joined. The implementation uses leveled sharing, weight-free shared suffixes, compact deterministic segments, and persistent path copying.
The implementation was extracted from the graph-structured stack used by GLRMask. Version 0.1 is suitable for evaluation and integration; later 0.x releases may make breaking API changes.
Installation
Rust:
cargo add weighted-gss
Python 3.8 or later:
python -m pip install weighted-gss
Install the unreleased Git head:
[dependencies]
weighted-gss = { git = "https://github.com/IsaacBreen/weighted-gss" }
python -m pip install "git+https://github.com/IsaacBreen/weighted-gss"
Rust example
Stacks are ordered bottom-to-top.
use weighted_gss::{Weight, WeightedGss};
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
struct Cost(u32);
impl Weight for Cost {
fn join(&self, other: &Self) -> Self {
Cost(self.0.min(other.0))
}
}
let left = WeightedGss::from_single_stack(vec![0_u32, 1, 2], Cost(7));
let right = WeightedGss::from_single_stack(vec![0_u32, 1, 3], Cost(4));
let gss = left.merge(&right).push(9);
let mut stacks = gss.to_stacks(8).expect("materialization limit exceeded");
stacks.sort_by(|a, b| a.0.cmp(&b.0));
assert_eq!(
stacks,
vec![
(vec![0, 1, 2, 9], Cost(7)),
(vec![0, 1, 3, 9], Cost(4)),
],
);
Weight::join must be associative, commutative, and idempotent. Set union, bitwise OR, minimum, and maximum are valid examples. Addition generally is not.
The Rust API reference is generated on docs.rs.
Python example
Unweighted use stores None as the weight:
from weighted_gss import WeightedGSS
gss = WeightedGSS.from_unweighted([[0, 1, 2], [0, 1, 3]])
pushed = gss.push(9)
assert {tuple(stack) for stack, _ in pushed.to_stacks()} == {
(0, 1, 2, 9),
(0, 1, 3, 9),
}
Weighted values must be immutable and hashable and must define join(other):
from dataclasses import dataclass
from weighted_gss import WeightedGSS
@dataclass(frozen=True)
class Bits:
value: int
def join(self, other: "Bits") -> "Bits":
return Bits(self.value | other.value)
gss = WeightedGSS.from_stacks([
([0, 1], Bits(0b001)),
([0, 1], Bits(0b100)),
])
assert gss.to_stacks() == [([0, 1], Bits(0b101))]
The Python distribution is typed (py.typed) and provides runtime docstrings. See the Python API guide.
Semantics
- A value denotes a finite map from bottom-to-top stacks to weights.
- Operations are persistent: inputs remain valid and results retain structural sharing where possible.
push(value)pushes onto every represented stack.popn(n)discards stacks shorter thann; stacks of length exactlynbecome empty stacks.- When two represented stacks become identical, their weights are joined.
to_stacks(limit)is bounded and never silently truncates.path_count_at_mostcounts structural graph paths, which can exceed the number of distinct stack keys.
See Semantics and invariants for the complete contract.
Main types
WeightedGss<T, W>: persistent compressed map from stacks to weights.Weight: join operation for weights on coincident stacks.VirtualStack<T, W>: mutable fast path for a deterministic stack prefix.WeightedGssSummary: structural diagnostics without path materialization.
The Python equivalents are WeightedGSS and WeightedGSSSummary.
Testing
The repository tests:
- the production regression suite inherited from GLRMask;
- both segment backends (
vecandarc); - 40,000 randomized operation steps against an explicit stack-to-weight map;
- a compressed graph representing 262,144 stacks;
- Rust examples and doctests;
- Python weighted and unweighted APIs from built wheels and source distributions;
- package metadata and publication dry runs;
- Linux, macOS, and Windows in GitHub Actions.
Provenance
The initial standalone extraction tracks glrmask commit 58c24ff44e3a796172a0ea532b3d66affa188d9e. The standalone crate changes the inherited parser-floor underflow behavior so popn follows ordinary stack semantics.
Contributing and license
See CONTRIBUTING.md for development instructions.
Licensed under either the Apache License, Version 2.0 or the MIT License, at your option.
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file weighted_gss-0.1.0.tar.gz.
File metadata
- Download URL: weighted_gss-0.1.0.tar.gz
- Upload date:
- Size: 58.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/6.1.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e6d034ee0ed2fc0ea168338563fcd1fbe700e9ad5211ccb4788f5a700b3bdf59
|
|
| MD5 |
39ef4ab925e2321096de857207abddc4
|
|
| BLAKE2b-256 |
b013dc271a47fc73c29f413ac3cad01c99088ec01e4e9bc54aa5257c91908875
|
File details
Details for the file weighted_gss-0.1.0-cp38-abi3-win_amd64.whl.
File metadata
- Download URL: weighted_gss-0.1.0-cp38-abi3-win_amd64.whl
- Upload date:
- Size: 266.4 kB
- Tags: CPython 3.8+, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/6.1.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
78979edc0d68c55a22404c91b57783319fe0104114c466fc5124ca11855fd5ab
|
|
| MD5 |
9bc93559aa47f27a3cf87d491051e4d4
|
|
| BLAKE2b-256 |
565c9a53fe3b8708155a7c35473344be1252b9000cbc74f481216beb151ea273
|
File details
Details for the file weighted_gss-0.1.0-cp38-abi3-musllinux_1_2_x86_64.whl.
File metadata
- Download URL: weighted_gss-0.1.0-cp38-abi3-musllinux_1_2_x86_64.whl
- Upload date:
- Size: 566.2 kB
- Tags: CPython 3.8+, musllinux: musl 1.2+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/6.1.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c4b99a09d871784e71eee62c33fd79cb531ebc33cec83ed2489610946ed83c6c
|
|
| MD5 |
9e0a0f6c2153bad023bde32c6a2bda0e
|
|
| BLAKE2b-256 |
d04df26e110c974721bfdf8015dada0e99c3e05b6baa0d18771b5cf9df566b71
|
File details
Details for the file weighted_gss-0.1.0-cp38-abi3-musllinux_1_2_aarch64.whl.
File metadata
- Download URL: weighted_gss-0.1.0-cp38-abi3-musllinux_1_2_aarch64.whl
- Upload date:
- Size: 521.4 kB
- Tags: CPython 3.8+, musllinux: musl 1.2+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/6.1.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d17fa4e2260d840291ec6c9f8cc9cb9c50063925956a7aadb73deacb15bb9a4b
|
|
| MD5 |
fa0af8a833a1f66845b1d42c0a4fd0ae
|
|
| BLAKE2b-256 |
f29468e714a093adf99dc37315c3a76bab3f08e762b6bff88f6941115dbed934
|
File details
Details for the file weighted_gss-0.1.0-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.
File metadata
- Download URL: weighted_gss-0.1.0-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 358.3 kB
- Tags: CPython 3.8+, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/6.1.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
459f331c97b8e9e78a24a210c16d40148fd25997b5a659472c4439a2c98db993
|
|
| MD5 |
3c6f82eeec31fa38b058351e168e022c
|
|
| BLAKE2b-256 |
c5e99a28af15c1e0aaf16e9ad2d9c542426539e23aab07a4abd319e89b295d3e
|
File details
Details for the file weighted_gss-0.1.0-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.
File metadata
- Download URL: weighted_gss-0.1.0-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
- Upload date:
- Size: 345.2 kB
- Tags: CPython 3.8+, manylinux: glibc 2.17+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/6.1.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d022000de27d442f1310f9a9973797c9854137a8b2d2dc2cd9d1c373bde257e0
|
|
| MD5 |
5ef1aee47f5e357c69564d5b4d1c3373
|
|
| BLAKE2b-256 |
afeb8fe87195ef7095738bd33c0ed533cb035041c3a371481dba470bb39359ce
|
File details
Details for the file weighted_gss-0.1.0-cp38-abi3-macosx_11_0_arm64.whl.
File metadata
- Download URL: weighted_gss-0.1.0-cp38-abi3-macosx_11_0_arm64.whl
- Upload date:
- Size: 324.5 kB
- Tags: CPython 3.8+, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/6.1.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
615c15b85bb8d04833db291b74b487ed1caad12b8fc7153cb96d667c1efec58c
|
|
| MD5 |
1bf1e1af98b80f33489b2565c9dc3fb8
|
|
| BLAKE2b-256 |
09650595064c310813709aab4d499167a472701ebcb8a68fb511feea2248b631
|
File details
Details for the file weighted_gss-0.1.0-cp38-abi3-macosx_10_12_x86_64.whl.
File metadata
- Download URL: weighted_gss-0.1.0-cp38-abi3-macosx_10_12_x86_64.whl
- Upload date:
- Size: 329.9 kB
- Tags: CPython 3.8+, macOS 10.12+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/6.1.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e111c9a0e32d2a5f15ec03da40ae0894c4e977fa5be8dfb296bf453c4345ac89
|
|
| MD5 |
b2adc191d69e6222bc5347b7a1b0d502
|
|
| BLAKE2b-256 |
9266a62a4f7bbc06f59ab1beb6f7187db66622e9a22e612545739e7313cfb8bd
|