So I am working on a project that needs to be absolutely efficient in terms of memory and runtime, and I've come up with a way to represent part of the problem by hundreds of 'sets' of Boolean switches (like 0101000100...), that reach lengths on the order of 20,000. I think I know from how a processor works that bitwise operations can manipulate entire regions of memory in O(1) time (or maybe just one CPU instruction), as bits literally flow through logic gates in parallel. I've considered using std::bitset, but I have decided that it's not a compact enough structure, and when doing bitwise operations it does search over the entire bitset in some kind of 'foreach' loop.
I want to manipulate 1's and 0's in memory. The best way I have thought of doing this is stringing together a bunch of meaningless uint64_t types (perhaps in an array) and, very much like a std::bitset, search over all uint64_t and do bitwise operations against another 20,000-long set of switches. I am well aware that this is not an O(1) operation, and I am essentially doing the same thing algorithmically as std::bitset or even std::vector<bool> and std::array<bool, 20000>, etc. But the extra compactness of using uint64_t results in speed and memory differences significant enough to affect my program's runtime and space-complexity within our sample spaces, even if we are in the same time complexity as the standard library operations. My question is, is this the optimal way to carry out operations over a 20,000-long set of switches? Is there a way to do bitwise operations on 20,000 bit-long regions of memory in O(1) time, or an O(n) method that is better than mine? I supremely doubt it, but if this is possible it would quite literally solve a huge challenge that has plagued our project.
DEMONSTRATION: We are trying to see if this O(n) operation can be performed in O(1) by doing bitwise AND over the entire switch structure instead of plugging 64-bit chunks one at a time. Each individual bitwise AND here is an O(1) operation by the CPU instruction on a 64-bit processor, I presume, but can I somehow do 20,000-long bitwise AND?
uint64_t switch1[313]; //20,032 meaningful switches e.g. 100...101
uint64_t switch2[313]; //20,032 meaningful switches e.g. 110...010
uint64_t result[313]; //result of 20,032-long bitwise AND
for (int i = 0; i < 313; ++i) {
result[i] = switch1[i] & switch2[i];
}
Thanks!