Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 5ae7bc1

Browse files
committed
mention bitset in eratosthenes article
1 parent af4961a commit 5ae7bc1

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

src/algebra/sieve-of-eratosthenes.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,11 @@ However, for the simple implementations of the Sieve of Eratosthenes using a `ve
125125
You are limited by how fast you can load the data into the cache, and therefore using less memory gives a big advantage.
126126
A benchmark ([link](https://gist.github.com/jakobkogler/e6359ea9ced24fe304f1a8af3c9bee0e)) shows, that using a `vector<bool>` is between 1.4x and 1.7x faster than using a `vector<char>`.
127127

128+
The same considerations also apply to `bitset`.
129+
It's also an efficient way of storing bits, similar to `vector<bool>`, so it takes only $\frac{N}{8}$ bytes of memory, but is a bit slower in accessing the elements.
130+
In the benchmark above `bitset` performs a bit worse than `vector<bool>`.
131+
Another drawback from `bitset` is that you need to know the size at compile time.
132+
128133
### Segmented Sieve
129134

130135
It follows from the optimization "sieving till root" that there is no need to keep the whole array `is_prime[1...n]` at all time.

0 commit comments

Comments
 (0)