Question

I want to store integers with greater than 64 bits in length. Number of bits per integer can go up to millions as each entry gets added in the application. And then for 64 such integers (of equal length) bit-wise AND operation has to be performed.

So what would be the best C++ data structure for operations to be time efficient? Earlier i had considered vectors for it as it would allow to increase the length dynamically. Other option is to use std:bitset.

But i am not sure how to performs bit-wise ANDs with both these approaches so that its done in most time-efficient manner.

Thanks

Was it helpful?

Solution

The GNU Multiprecision Library is a good arbitrary-precision integer library. It is most likely heavily optimized down to specifics for your compiler/CPU, so I'd go with that as a first start and if it's not fast enough roll your own specific implementation.

OTHER TIPS

It is quite expensive to reallocate memory for vector when taking large data, so i would define

struct int_node{
    bitset<256> holder; 
    int_node *next_node;
}

I think this approach would save time on memory management and save some cycles on bitwise ops.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top