dart-lang / sdk

The Dart SDK, including the VM, JS and Wasm compilers, analysis, core libraries, and more.
https://dart.dev
BSD 3-Clause "New" or "Revised" License
10.08k stars 1.56k forks source link

Add BitSet (bit vector) to Dart library #1053

Open DartBot opened 12 years ago

DartBot commented 12 years ago

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 commented 12 years ago

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

DartBot commented 10 years ago

This comment was originally written by sk...@gmail.com


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 commented 10 years ago

This comment was originally written by @arhad


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

lrhn commented 4 years ago

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

modulovalue commented 1 year ago

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:

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:


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 commented 1 year ago

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.