Questions tagged [bitvector]

A data structure for an array of single bit values, usually with emphasis on memory-efficient storage and performance.

A bit Vector stores an array of single bit values (0,1) usually in a memory-efficient (i.e. packed) way. Typical operations on a bit vector are

  • access to single bits
  • boolean operations between two bit vectors (AND, OR, XOR, NOT)
  • vector-like operations (append/prepend, insertion of bits)
  • shift operations

Implementation are often optimized to use operations provided by the CPU to perform these operations in an performant way.

References

137 questions
8
votes
1 answer

Binary operation != cannot be applied when using generics for a bit vector

I'm in the process of implementing a Bit Vector class as an exercise, however only knowing Rust for less than a week I run into trouble with the following code: use std::cmp::Eq; use std::ops::BitAnd; use std::ops::Index; use std::ops::Not; struct…
skiwi
  • 59,273
  • 29
  • 118
  • 198
8
votes
7 answers

Determining a string has all unique characters without using additional data structures and without the lowercase characters assumption

This is one of the questions in the Cracking the Coding Interview book by Gayle Laakmann McDowell: Implement an algorithm to determine if a string has all unique characters. What if you can not use additional data structures? The author wrote: We…
user3184017
  • 115
  • 1
  • 1
  • 5
7
votes
1 answer

In perl, how do I count bits in a bit vector which has bits set higher than 2_147_483_639?

Perl is pretty great at doing bit strings/vectors. Setting bits is as easy as vec($bit_string, 123, 1) = 1; Getting the count of set bits is lightning quick $count = unpack("%32b*", $bit_string); But if you set a bit above 2_147_483_639, your…
TomWitt2
  • 197
  • 1
  • 6
7
votes
1 answer

Efficient way to encode bit-vectors?

Currently using the run length encoding for encoding bit-vectors, and the current run time is 2log(i), where is the size of the run. Is there another way of doing it to bring it down to log(i)? Thanks.
7
votes
3 answers

Fast code for searching bit-array for contiguous set/clear bits?

Is there some reasonably fast code out there which can help me quickly search a large bitmap (a few megabytes) for runs of contiguous zero or one bits? By "reasonably fast" I mean something that can take advantage of the machine word size and…
user541686
  • 189,354
  • 112
  • 476
  • 821
6
votes
3 answers

How to calculate the number of positive bits without using any shifts?

During a job interview I had some time ago I was asked to calculate the number of positive (i.e. set to "1") bits in a bitvector-structure (like unsigned integer or long). My solution was rather straightforward in C#: int CountBits(uint input) { …
Alexander Galkin
  • 10,800
  • 9
  • 56
  • 111
6
votes
1 answer

Palindrome Permutation (Cracking the Coding Interview 1.4)

I'm having trouble understanding the bit logic in these two functions. I don't know why we are checking for the condition (bitVector & mask) == 0. Also, why do we OR the bitVector with the mask when the condition is satisfied and AND the bitVector…
Decimal
  • 83
  • 1
  • 7
6
votes
2 answers

java micro-optimization: combine set of boolean instance variables to bit vector based on int

We have a class with many instances and run into memory problems. Therefore, we try to reduce the memory requirements of this class. One idea would be the following. The class has many boolean instance variables, each of which would take up one…
Ulrich Scholz
  • 1,701
  • 4
  • 24
  • 44
5
votes
2 answers

When should I use a BitVector32?

I am working on a project where at a certain moment I need to show for one month which days are still available. There is a function that calculates which days are available. My colleagues said:"Oh we know, you should return a BitVector32. That's…
Matthijs Wessels
  • 6,234
  • 6
  • 54
  • 97
5
votes
1 answer

How to implement array of bitvectors in z3's Python APIs

I am new to z3py and was going through the Z3 API in Python, but couldn't figure out how to define an array of bitvectors. I want something like: DOT__mem[16] = BitVec('DOT__mem[16]', 8) but this syntax didn't work, even on the practice panel in…
Sharad
  • 393
  • 2
  • 16
5
votes
2 answers

How does vector deal with references and iterators?

As we all probably know the C++ 98 vector specialization stores boolean values as bits rather than as bool variables. vector's elements aren't addressable because C++ doesn't have pointers and references to bits, is there a workaround to…
iKlsR
  • 2,482
  • 6
  • 25
  • 43
4
votes
1 answer

BitVec incorrectly appends 0s instead of 1s

I am a beginner at Rust. I am trying to use the BitVec library to represent an array of bits. I started playing with it by appending sequences of 0s or 1s, but I am having some problems at doing so. When I append a sequence of x 0s then a sequence…
Xito Dev
  • 55
  • 5
4
votes
2 answers

how to implement a really efficient bitvector sorting in python

Actually this is an interesting topic from programming pearls, sorting 10 digits telephone numbers in a limited memory with an efficient algorithm. You can find the whole story here What I am interested in is just how fast the implementation could…
xiao 啸
  • 5,732
  • 8
  • 37
  • 49
3
votes
2 answers

Data structure to manipulate long strings of bits

In Python, what is the best data structure of n bits (where n is about 10000) on which performing the usual binary operations (&, |, ^) with other such data structures is fast?
Randomblue
  • 98,379
  • 133
  • 328
  • 526
3
votes
1 answer

select on a bit vector in C++ complexity and implementation

I'm implementing a matrix reduction algorithm, I'm a math student. Obviously I've searched and read around internet but didn't find exactly what I was looking for (I list at the end what I've found and the papers that I've read.) Quick overview of…
joerg91
  • 31
  • 3
1
2
3
9 10