Skip to main content

weighted-gss

CI

A persistent weighted graph-structured stack.

WeightedGss<S, W> represents a finite collection of stack alternatives. Each stack carries a weight. When stack operations make alternatives denote the same concrete stack, their weights are joined.

The graph representation is private. The default Rust API is deliberately limited to construction, merging, ordinary stack operations, top selection, and bounded materialisation. High-performance parser engines can opt into a small advanced module without exposing graph internals.

Installation

The current release is version 0.2.0.

[dependencies]
weighted-gss = { git = "https://github.com/IsaacBreen/weighted-gss", branch = "rewrite/from-scratch-20260725" }

Python 3.8 or later:

python -m pip install "git+https://github.com/IsaacBreen/weighted-gss@rewrite/from-scratch-20260725"

Rust

Stacks are supplied and returned bottom-to-top.

use weighted_gss::{Weight, WeightedGss};

#[derive(Clone, Copy, Debug, PartialEq, Eq)]
struct Possibilities(u32);

impl Weight for Possibilities {
    fn join(&self, other: &Self) -> Self {
        Self(self.0 | other.0)
    }
}

let left = WeightedGss::from_stack([0_u32, 1, 2], Possibilities(0b001));
let right = WeightedGss::from_stack([0_u32, 1, 3], Possibilities(0b100));
let stacks = left.merge(&right);

assert_eq!(stacks.top(), None);
assert_eq!(
    stacks.tops().collect::<std::collections::BTreeSet<_>>(),
    [2, 3].into(),
);

let reduced = stacks.pop_top(&2).push(9);
assert_eq!(
    reduced.to_stacks(8).unwrap(),
    vec![(vec![0, 1, 9], Possibilities(0b001))],
);

A weight must implement ordinary equality. join must be associative, commutative, and idempotent.

The exported Rust names are only:

Weight
WeightedGss
Gss
PathLimitExceeded

The core methods are:

  • construction: new, from_stack, from_stacks, from_stacks_with_weight;
  • alternatives: merge;
  • stack operations: push, pop, popn;
  • top selection: top, tops, has_empty_stack, retain_top, retain_empty, pop_top;
  • weights: weights, map_weights, filter_map_weights, joined_weight;
  • observations: is_empty, max_depth, to_stacks.

to_stacks(max_paths) returns canonical (stack, weight) pairs and fails rather than silently exceeding the requested structural traversal bound.

weights() iterates stored factored weight regions, not concrete stacks. One weight may cover many stacks, equal weights may appear more than once, and count/order are unspecified. map_weights and filter_map_weights transform those regions without materialising stacks; see Semantics and invariants for the representation-independence condition.

Optional engine API

Parser and state-machine implementations can enable a compact set of operations that avoid materialising shared stack languages:

[dependencies]
weighted-gss = { version = "0.2", features = ["engine"] }

The opt-in weighted_gss::engine module contains only:

  • for_each_stack_top_first for bounded, allocation-light concrete-stack inspection;
  • linear_prefix and LinearPrefix for mutating a homogeneous linear top prefix while retaining its hidden floor;
  • StackLanguageInterner and StackLanguageId for exact stack-language IDs in fixpoint visited sets.

Batched parser actions, depth filters, representation IDs, structural statistics, and graph nodes remain application-local or private. See Engine API.

Python

from dataclasses import dataclass
from weighted_gss import WeightedGSS

@dataclass(frozen=True)
class Possibilities:
    bits: int

    def join(self, other: "Possibilities") -> "Possibilities":
        return Possibilities(self.bits | other.bits)

stacks = WeightedGSS.from_stacks([
    ([0, 1, 2], Possibilities(0b001)),
    ([0, 1, 3], Possibilities(0b100)),
])

assert stacks.tops() == {2, 3}
assert stacks.pop_top(2).to_stacks() == [
    ([0, 1], Possibilities(0b001)),
]

Python weights need not be hashable. Exceptions raised by join() are propagated normally. See the Python API.

Semantics and validation

The implementation is tested against an explicit stack-to-weight map under randomized sequences of construction, merge, push, pop, top selection, and branch selection. Rust 1.85 is the declared minimum version.

The opt-in engine API is validated by adapting GLRMask without exposing graph nodes or restoring its historical convenience surface. The ordinary default API remains independent of parser-engine concerns.

See Semantics and invariants.

Licensed under either Apache-2.0 or MIT, 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

weighted_gss-0.2.0.tar.gz (41.9 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

weighted_gss-0.2.0-cp38-abi3-win_amd64.whl (222.4 kB view details)

Uploaded CPython 3.8+Windows x86-64

weighted_gss-0.2.0-cp38-abi3-musllinux_1_2_x86_64.whl (523.9 kB view details)

Uploaded CPython 3.8+musllinux: musl 1.2+ x86-64

weighted_gss-0.2.0-cp38-abi3-musllinux_1_2_aarch64.whl (479.8 kB view details)

Uploaded CPython 3.8+musllinux: musl 1.2+ ARM64

weighted_gss-0.2.0-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (316.2 kB view details)

Uploaded CPython 3.8+manylinux: glibc 2.17+ x86-64

weighted_gss-0.2.0-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (303.7 kB view details)

Uploaded CPython 3.8+manylinux: glibc 2.17+ ARM64

weighted_gss-0.2.0-cp38-abi3-macosx_11_0_arm64.whl (285.8 kB view details)

Uploaded CPython 3.8+macOS 11.0+ ARM64

weighted_gss-0.2.0-cp38-abi3-macosx_10_12_x86_64.whl (289.1 kB view details)

Uploaded CPython 3.8+macOS 10.12+ x86-64

File details

Details for the file weighted_gss-0.2.0.tar.gz.

File metadata

  • Download URL: weighted_gss-0.2.0.tar.gz
  • Upload date:
  • Size: 41.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.14

File hashes

Hashes for weighted_gss-0.2.0.tar.gz
Algorithm Hash digest
SHA256 a7c1a2417f2d51531132f623d1cfbc57aabb4ec3a1950bf0552e244a65061702
MD5 70f22e62b4194aad57bccf7094270594
BLAKE2b-256 c7cbd56c79e2e49927cbb0b5c186760e390b3c039b5286644f8f3335cb46478b

See more details on using hashes here.

File details

Details for the file weighted_gss-0.2.0-cp38-abi3-win_amd64.whl.

File metadata

  • Download URL: weighted_gss-0.2.0-cp38-abi3-win_amd64.whl
  • Upload date:
  • Size: 222.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

Hashes for weighted_gss-0.2.0-cp38-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 14587f000646438afd736c3561eb60b298f325daae2e24abedefe63b840083f0
MD5 e776b7059e5c63d1d29a92ad8bce8311
BLAKE2b-256 a95a6e320730c94e187e21e43dcbeda20c40b4c6c660860c10612aa9f1eb3932

See more details on using hashes here.

File details

Details for the file weighted_gss-0.2.0-cp38-abi3-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for weighted_gss-0.2.0-cp38-abi3-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 791025eb744e99bfa8019c130c52004d1e3ebe939f33d6ee4f52b02b5efa0b78
MD5 1dd964da47dcd8b70fc47f13cf8a9f4f
BLAKE2b-256 6dc02bdee7bbd565403cc29fdc457a1b6ad89d1f87292f4044abea5c53138274

See more details on using hashes here.

File details

Details for the file weighted_gss-0.2.0-cp38-abi3-musllinux_1_2_aarch64.whl.

File metadata

File hashes

Hashes for weighted_gss-0.2.0-cp38-abi3-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 27e6757e90b1a1016fd4891d4616826b7b24fd9ae1d0968e72e478ad6881841c
MD5 fe8a58684a3b4fe1f0b64aae488bf05d
BLAKE2b-256 ee807c3ef69da0787021bab159ef390db3720222d2ecf81f91f4deb8843e409a

See more details on using hashes here.

File details

Details for the file weighted_gss-0.2.0-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for weighted_gss-0.2.0-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 8d044ba94d3b5b733603fc5bac327c3b38bc3794802fa0366fad29135a5379f6
MD5 c15bdd912be9ed4f89d9c1236f3d0cba
BLAKE2b-256 b94f3f5737b1f162ac1d073b8f63e20b5598c985dfad36d10059ef71cdc13171

See more details on using hashes here.

File details

Details for the file weighted_gss-0.2.0-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for weighted_gss-0.2.0-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 de575f29a1d92d00c1e0df4c49328a0c8f59dee305bff4c32cd87127fcc8feb2
MD5 42c70091ca872e4a8e40aee5a559c601
BLAKE2b-256 00ad06506f70a0ae72e8e6d64c9bd9c0b9dc6e5fda41243d33079d393c86adb9

See more details on using hashes here.

File details

Details for the file weighted_gss-0.2.0-cp38-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for weighted_gss-0.2.0-cp38-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 0acf9a7b04fd0ac53dc830629642bbb8442f3770741286aa8e18a59b88d01989
MD5 44e0de5cc70c0856dce43a6f6c259ff7
BLAKE2b-256 38000fc2227b6f69b829a2b621d72a5afe319673c904df409dd95da87c21888e

See more details on using hashes here.

File details

Details for the file weighted_gss-0.2.0-cp38-abi3-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for weighted_gss-0.2.0-cp38-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 b26d5fb63d115f619bd751b3c5594e748fbb4aa64d7b813cb5a003ab93a494f1
MD5 878e8f7a6329107e053fae889847a088
BLAKE2b-256 e2ff1bd4a5159b6eee1bb008849f57cdc4f79fddeff2500a38c565fc65aa9a64

See more details on using hashes here.

Release history Release notifications | RSS feed

0.2.2

8 files

0.2.1

8 files

This release

0.2.0 This release

8 files

0.1.0

8 files

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