Skip to content

Use BTreeMap with u128 values for sparse bit sets/"vectors" (in dataflow etc.). #47575

Closed
@eddyb

Description

@eddyb

According to our current implementation of B-trees:

const B: usize = 6;
pub const MIN_LEN: usize = B - 1;
pub const CAPACITY: usize = 2 * B - 1;

it would appear that up to 11 key-value pairs can be stored in each node.

For u128 values representing 128 set elements each, 1408 set elements can be stored in a single allocation, with an overhead of around 50% compared to Vec<u128> in the dense case.

Such sparse bitsets would be really useful for (e.g. dataflow) analysis algorithms, in situations where the bitset elements tend to be localized, with multi-"word" gaps in between local groups.

cc @nikomatsakis @pnkfelix

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-collectionsArea: `std::collections`C-enhancementCategory: An issue proposing an enhancement or a PR with one.I-compilememIssue: Problems and improvements with respect to memory usage during compilation.I-compiletimeIssue: Problems and improvements with respect to compile times.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions