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 BitSet (bit vector) to Dart library #1053

Open
DartBot opened this issue Jan 5, 2012 · 6 comments
Open

Add BitSet (bit vector) to Dart library #1053

DartBot opened this issue Jan 5, 2012 · 6 comments
Labels
area-core-library SDK core library issues (core, async, ...); use area-vm or area-web for platform specific libraries. core-n type-enhancement A request for a change that isn't a bug

Comments

@DartBot
Copy link

DartBot commented Jan 5, 2012

This issue was originally filed by @ahmetaa


Although it is not as commonly used as other collection types, an efficient bit vector (BitSet) implementation would be nice to have.

@dgrove
Copy link
Contributor

dgrove commented Jan 9, 2012

Removed Type-Defect label.
Added Type-Enhancement, Area-Library, Triaged labels.

@DartBot
Copy link
Author

DartBot commented May 9, 2014

This comment was originally written by [email protected]


I had a need for an efficient bitset and ended up implementing it myself (it was also an exercise in learing Dart, so I welcome comments on implementation): https://pub.dartlang.org/packages/bit_set

@DartBot
Copy link
Author

DartBot commented May 10, 2014

This comment was originally written by @arhad


I would say that border must be implemented as List<bool> template specialisation, like in C++.

@DartBot DartBot added Type-Enhancement area-core-library SDK core library issues (core, async, ...); use area-vm or area-web for platform specific libraries. labels May 10, 2014
@kevmoo kevmoo added P2 A bug or feature request we're likely to work on type-enhancement A request for a change that isn't a bug and removed triaged type-enhancement A request for a change that isn't a bug labels Feb 29, 2016
@lrhn lrhn added the core-m label Aug 11, 2017
@floitschG floitschG added core-n and removed core-m labels Aug 31, 2017
@lrhn
Copy link
Member

lrhn commented Oct 14, 2019

Not currently planned for the platform libraries. We may want to add it to a package like package:collection.

@lrhn lrhn removed the P2 A bug or feature request we're likely to work on label Oct 14, 2019
dart-bot pushed a commit that referenced this issue Apr 7, 2021
2021-04-07 [email protected] Fixes #535: more nnbd tests for constant evaluation added.
2021-04-07 [email protected] Fixes #1068. Remove excessive - in a SharedOptions
2021-04-05 [email protected] Fixes #535: more nnbd tests for constant evaluation added.
2021-04-05 [email protected] Fixes #996: more tests added.
2021-04-05 [email protected] Fixes #996: more tests added.
2021-04-05 [email protected] Fixes #1067: added checks for old and new dart versions.
2021-04-05 [email protected] Fixes #1066: added @Dart=2.12 to the initial version of the test, new test which checks recent dart behavior added.
2021-04-05 [email protected] Fixes #1057: Expected result doe the tests with mailformed types updated.
2021-04-02 [email protected] Fixes #1062. Remove unnecessary assignment
2021-04-01 [email protected] Fixes #1057: Expected result doe the tests with mailformed types updated.
2021-04-01 [email protected] Expected error code is fixed for Windows
2021-04-01 [email protected] Fixes #1060. Expected error message position updated
2021-04-01 [email protected] Fixes #1059. Expected error message updated
2021-04-01 [email protected] Fixes #1024. Adjust expected results for web platforms
2021-04-01 [email protected] #993. More Array tests added
2021-03-31 [email protected] Update LICENSE
2021-03-31 [email protected] #993. Array tests added
2021-03-31 [email protected] Issue #1053: Missing Issue tag added, test expectation updated.
2021-03-30 [email protected] Fixes #1054: Updated expectations for mailformed raw type variables.
2021-03-30 [email protected] Fixes #1050: Updated expectations for mailformed raw type variables.
2021-03-30 [email protected] Fixes #1050: Got rid of mailformed row type variable usage in i-2-b- tests.
2021-03-29 [email protected] Fixes #1043. Remove static warning as an expected result
2021-03-29 [email protected] Fixes #1049: Correct expectation adjusted
2021-03-29 [email protected] Fixes #1048. Move tests to correct folder and change the description
2021-03-29 [email protected] Fixes #1046: Test adjusted to work with the generic metadata feature enabled.
2021-03-29 [email protected] Fixes #1047. Change expected result to not to fail on JavaScript configurations
2021-03-29 [email protected] Fixes #1044. Change expected result to not to fail on JavaScript configurations
2021-03-26 [email protected] Fixes #1029: Missing Issue tag added to the test.
2021-03-26 [email protected] Fixes #1042. Add check that produces different results for triple and double shifts
2021-03-26 [email protected] Fixes #1042. Fix built-in_types_t11.dart to expect correct results
2021-03-25 [email protected] Fixes #1019. Don't use type aliases in legacy libraries
2021-03-25 [email protected] Fixes #1039: Old-style aliases corrected.
2021-03-25 [email protected] Fixes #988. Expect static type warning in a right way
2021-03-24 [email protected] Issues #1029: Static expectation corrected.
2021-03-24 [email protected] Issues #1035: Issue tag for the bug 45443 added.
2021-03-24 [email protected] Merge branch 'master' of https://github.com/dart-lang/co19
2021-03-24 [email protected] #1023. Change SplayTreeMap and SplayTreeSet tests according to the new behavior
2021-03-23 [email protected] #1021. Remove expecting errors on web configurations for some negative numbers
2021-03-23 [email protected] Fixes #1034. Missed experimental flag added
2021-03-23 [email protected] #1033. Perform runtime check on big values for non-JavaScript configurations only
2021-03-23 [email protected] Issues #1029: co19/Language/Generics/Superbounded_types/typedef3_A01_t06/02 corrected and does not expect a compile error now.

Cq-Include-Trybots: dart/try:analyzer-nnbd-linux-release-try,dart2js-nnbd-linux-x64-chrome-try,ddc-nnbd-linux-release-chrome-try,front-end-nnbd-linux-release-x64-try,vm-kernel-nnbd-linux-debug-x64-try,vm-kernel-nnbd-linux-release-simarm64-try,vm-kernel-nnbd-linux-release-x64-try,vm-kernel-nnbd-mac-release-x64-try,vm-kernel-nnbd-win-release-x64-try,vm-kernel-precomp-nnbd-linux-debug-x64-try,vm-kernel-precomp-nnbd-linux-release-simarm64-try,vm-kernel-precomp-nnbd-linux-release-x64-try
Change-Id: I5fae01c7b48aba502da04638430f4f6de79ac745
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/194241
Reviewed-by: William Hesse <[email protected]>
@modulovalue
Copy link
Contributor

modulovalue commented Jun 10, 2023

I think it would be great to have a stable and reliable Bitset implementation in [the] Dart [ecosystem].

If one considers Lists to be efficient Maps where the domain of the keys are integers, then Bitsets are efficient sets where the domain of the values are integers, but unfortunately, Dart doesn't come with a Bitset, and HashSets are absurdly suboptimal for Sets over some integral domains.


One usecase for Bitsets comes up when trying to optimize algorithms over finite domains, where the obvious improvements are:

  • normalize the domain to integers
  • use Lists instead of Maps
  • use Bitsets instead of Sets.

Sadly, the last step can't be done yet without reimplementing bitsets or relying on a third party (literally, only one third party).


It should be noted that Bitsets, in general, do not support efficient enumeration of set bits the way that HashSets do. I think that this is a useful operation and it could be surprising to some that Bitsets can't do that. I know two ways to deal with that:

  • use popcount/SIMD to skip/extract unset/set bits more efficiently. It appears that there are highly efficient popcount instructions (that don't pollute the cache with lookup tables), which Dart doesn't support. (I have filed: [sdk] Consider supporting popcnt, ctz & clz #52673) SIMD support is weak and integer SIMD support will hopefully receive some more love one day.

  • use an alternative Bitset design like this FASTSET (which seems to also be known as a sparse set, but I'm not entirely sure). It supports all important operations efficiently (not just some), but it is significantly less efficient memory-wise than a standard Bitset because it represents all integers explicitly twice, and not just one bit per integer, but it is still more efficient than a HashSet.


I believe Roaring bitmaps are considered to be the state of the art (when it comes to bitsets) and appear to be used by practically everybody. I was hoping to get roaring bitmaps to work in Dart (in a portable way across all platforms) via WASM, but the current experiment for running WASM inside of Dart is being discontinued :(.

@modulovalue
Copy link
Contributor

Note: there is a BoolList in package:collection. It doesn't have efficient bitset operations, but it appears to support the use-case of a memory efficient collection of bits.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-core-library SDK core library issues (core, async, ...); use area-vm or area-web for platform specific libraries. core-n type-enhancement A request for a change that isn't a bug
Projects
None yet
Development

No branches or pull requests

6 participants