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 functions for counting the results of a set operation #116

Merged
merged 2 commits into from Mar 20, 2024

Conversation

james7132
Copy link
Collaborator

@james7132 james7132 commented Mar 20, 2024

Using count_ones with a set operation either requires mutating the underlying FixedBitset with union_with, etc, or using Iterator::count on the set operation iterators, which can be very slow on dense bitsets. This PR adds non-mutating options for computing the size of a union, intersection, difference, and symmetric difference between two bitsets.

Added a few benchmarks to measure the difference:

clear/1m                              1.00   1121.6±5.57ns        ? ?/sec
count_ones/1m                         1.00      7.8±0.01µs        ? ?/sec
difference_count/1m                   1.00      8.8±0.01µs        ? ?/sec
difference_with/1m                    1.00      2.9±0.01µs        ? ?/sec
grow_and_insert                       1.00      2.4±0.01ms        ? ?/sec
insert/1m                             1.00    967.5±3.45µs        ? ?/sec
insert_range/1m                       1.00   1116.8±7.00ns        ? ?/sec
intersect_with/1m                     1.00      2.9±0.01µs        ? ?/sec
intersection_count/1m                 1.00      8.8±0.08µs        ? ?/sec
iter_difference_count/1m              1.00   915.3±26.40µs        ? ?/sec
iter_intersection_count/1m            1.00   1706.6±4.52µs        ? ?/sec
iter_ones/all_ones                    1.00      2.3±0.00ms        ? ?/sec
iter_ones/all_zeros                   1.00      4.4±0.34µs        ? ?/sec
iter_ones/contains_all_ones           1.00    408.3±8.22µs        ? ?/sec
iter_ones/contains_all_zeros          1.00    406.7±2.59µs        ? ?/sec
iter_ones/sparse                      1.00    210.6±2.28µs        ? ?/sec
iter_symmetric_difference_count/1m    1.00      2.8±0.24ms        ? ?/sec
iter_union_count/1m                   1.00  1618.6±54.83µs        ? ?/sec
symmetric_difference_count/1m         1.00      8.8±0.02µs        ? ?/sec
symmetric_difference_with/1m          1.00      2.7±0.01µs        ? ?/sec
union_count/1m                        1.00      8.8±0.02µs        ? ?/sec
union_with/1m                         1.00      2.8±0.01µs        ? ?/sec

Comparing iter_union_count and union_count, on denser bitsets, using union_count is almost 200x faster, with the speed of union_count being only a bit behind count_ones.

@james7132 james7132 merged commit 7507a73 into petgraph:master Mar 20, 2024
14 checks passed
james7132 added a commit to james7132/fixedbitset that referenced this pull request Mar 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant