14
votes
Accepted
Bit array implementation
Don't write a function to return a constant
You don't need uint_size(), as the returned value never changes (for a given target platform). You can replace it with
...
10
votes
Bitmasking and searching consecutive 1's
<bits/stdc++.h> (like everything in your compiler's bits/ subtree) is not a standard header and therefore not portable. ...
10
votes
FlagSet with C++ templates
IndexOf can probably be a nested type of FlagSet, unless you intend for that to be part of the public interface.
...
10
votes
Huffman coding, using vector<bool>
std::vector<bool>
I wrote the code assuming vector represents each bool with a single bit. Is there a standard way to check whether the STL used by the ...
8
votes
Bit array implementation
I have a number of comments, so I'll just sort of spray them out.
Using a proxy reference type is tricky, and can lead to some interesting problems. For example, a class that provides proxy ...
8
votes
Accepted
Counting the number of 1 bits in a sorted bit array
I agree with your assessment of the code being unnecessarily long and awkward. It looks like the root cause is an opportunistic optimization.
The bad news is that most of the secondary tests (like <...
8
votes
C++ data type to store and manipulate individual bits
not directly answering your question, but just a notice:
I would say the more elegant way would be just extending the std::bitset and add the extra methods you need,...
8
votes
A Dynamic Bitset that I wrote and will use in my compression algortithm. This will be used to store the chars as bits from fstream
Advice 1 - std::size_t for indexing and counting
Instead of the following:
unsigned int arrayLength;
unsigned int bitLength;
I ...
7
votes
Counting the number of 1 bits in a sorted bit array
This removes the learning part of this (if your goal is to try to learn to implement a binary search in this context), but I contend the most pythonic solution would be to use ...
7
votes
Accepted
C++ data type to store and manipulate individual bits
Here are some things that may help you improve your program.
Use all required #includes
The templated class uses CHAR_BIT but ...
7
votes
Accepted
Type-safe flag sets (bit fields) that make sense
You're not the first to be frustrated at the bitmasks we've inherited from K&R - it would be really nice if the language provided better support in this area, and many libraries have given us ...
6
votes
Accepted
Bitmask adapter
The test for enable_if_all_same_as_T seems a bit over-restrictive - surely all the arguments only need to be assignable to ...
6
votes
Bitmasking and searching consecutive 1's
When you post code to be reviewed:
If your code asks for input, provide a set of valid and invalid inputs.
If your code output a result, show the expected output.
Since you present your code, it may ...
6
votes
Accepted
A Dynamic Bitset that I wrote and will use in my compression algortithm. This will be used to store the chars as bits from fstream
Use namespaces
DynamicBitset might be a sufficiently unique name, but if you put it inside a namespace, you're much less likely to collide with some other class ...
5
votes
How to make my “custom integer type” perform better?
A significant performance drain is bit-by-bit computation loops such as
...
5
votes
Bitmasking and searching consecutive 1's
Don't declare multiple variables on a single line. it is error prone and more difficult to read.
int n,q,k,count;
should be:
...
5
votes
Macros for bitsets / bit-flags in C
Most severe issue:
Never invent secret macro languages! This is about the single-worst thing a C programmer can ever do, all categories.
You are perfectly free to assume that any C programmer will ...
5
votes
Accepted
Macros for bitsets / bit-flags in C
Small portability bug: if we're using false in the macros, then bflags.h should include ...
5
votes
Optimize memory and disk usage for sequences of n-bit values
Design review
Your requirements are a bit vague; or rather, a bit contradictory. You say you want maximum memory efficiency (in the first paragraph)… but then you say you don’t, really (in the first ...
4
votes
Bit string builder for Java
It looks like you want to optimize something but you did not define what are your performance requirements. Your tests do not justify your implementation.
Why the state of builder is stored in array ...
4
votes
Accepted
FlagSet with C++ templates
It's a great idea to provide a type-safe bit-mask, I like your idea a lot. That said, I feel like your code is in great need of modernization and simplification.
Recursion through inheritance is now ...
4
votes
Emulating Virtual Registers Part 3
Here are some thoughts on how to further improve your program.
Use all required #includes
The program refers to CHAR_BIT which ...
4
votes
Individual bit access in C
This code is not portable. The order of bit-fields within a word is completely compiler-dependent, so the test that appears to work on one platform may give completely different results on another.
...
4
votes
Huffman coding, using vector<bool>
Missing I/O error checking
Your code does not check whether reading from or writing to files has succeeded, with the worst possible outcome being silent data corruption.
The proper way to check for ...
4
votes
Optimize memory and disk usage for sequences of n-bit values
Consider using a proper compression algorithm
Your method saves 25% of storage space, and is relatively simple to implement, but if the goal is to reduce memory and disk usage as much as possible, you ...
4
votes
Optimize memory and disk usage for sequences of n-bit values
You're missing the header includes to provide std::array, std::pair, std::addressof(), ...
4
votes
A Dynamic Bitset that I wrote and will use in my compression algortithm. This will be used to store the chars as bits from fstream
operator++ increments the whole thing as a BigInt? It's incredibly inefficient to do this one bit at a time; you're running on a CPU with ALUs that can propagate ...
3
votes
Accepted
Program containing several bitset based classes including chars, strings, ints and a base bitset class
I'm not sure how to review your code, because I don't understand what you're aiming for. There is a std::bitset class but it's different from yours: its size is ...
3
votes
Mixed-width operations for std::bitset
One aspect that could surprise users is that operator & always narrows types to match. That's a departure from the usual guidance of "do what the integers do".
...
3
votes
Accepted
Creating and storing binary arrays
I see a number of things that may help you improve your program.
Understand const
In a number of places in the code we have function declarations like this:
<...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
bitset × 62c++ × 25
bitwise × 15
java × 12
c × 10
performance × 6
algorithm × 6
python × 5
c# × 4
array × 4
python-3.x × 3
programming-challenge × 3
primes × 3
c++17 × 3
template × 3
c++14 × 3
io × 3
vectors × 3
sieve-of-eratosthenes × 3
beginner × 2
multithreading × 2
sorting × 2
rust × 2
memory-optimization × 2
set × 2