Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add std.DynamicBitSet.setAll & unsetAll #22288

Open
nurpax opened this issue Dec 22, 2024 · 2 comments
Open

Add std.DynamicBitSet.setAll & unsetAll #22288

nurpax opened this issue Dec 22, 2024 · 2 comments
Labels
bug Observed behavior contradicts documented or intended behavior

Comments

@nurpax
Copy link
Contributor

nurpax commented Dec 22, 2024

Zig Version

0.14.0-dev.2384+cbc05e0b1

Steps to Reproduce and Observed Behavior

var map = std.DynamicBitSet.initEmpty(allocator, 100);
map.unsetAll(); // error

However, unsetAll and setAll functions exist but they're not exposed in the DynamicBitSet although they can be called through map.unmanaged.unsetAll/setAll.

I think it'd make sense to have wrappers for these just like there are for most other operations, like f.ex. toggleAll:

    pub fn toggleAll(self: *Self) void {
        self.unmanaged.toggleAll();
    }

Expected Behavior

var map = std.DynamicBitSet.initEmpty(allocator, 100);
map.unsetAll(); // compiles
map.setAll(); // compiles
@nurpax nurpax added the bug Observed behavior contradicts documented or intended behavior label Dec 22, 2024
@nurpax
Copy link
Contributor Author

nurpax commented Dec 22, 2024

The setAll() method is actually buggy:

    const sizes = [_]usize{ 1, 63, 192, 256, 257 };
    for (sizes) |size| {
        var a = try std.DynamicBitSet.initEmpty(allocator, size);
        a.unmanaged.unsetAll();
        const cleared_count = a.count();
        a.unmanaged.setAll();
        const set_count = a.count();
        std.debug.print("{d} {d} {d}\n", .{ size, cleared_count, set_count });
    }

This prints:

1 0 64
63 0 64
192 0 192
256 0 256
257 0 320

I'd expect the first and last columns to have the same value. And looking at the setAll() implementation, it doesn't seem to handle the last padded bitset word.

nurpax added a commit to nurpax/zig that referenced this issue Dec 22, 2024
nurpax added a commit to nurpax/zig that referenced this issue Dec 22, 2024
@travisstaloch
Copy link
Contributor

duplicate of #19933

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Observed behavior contradicts documented or intended behavior
Projects
None yet
Development

No branches or pull requests

2 participants