So I have something like this
#define HASHSIZE 1010081
static struct nlist *hashtab[HASHSIZE];
Now I want to be able to change the HASHSIZE of my hashtab, because I want to test different primes numbers and see which would give me less collisions. But Arrays do not take variable sizes so HASHSIZE has to be a constant. Is there a way to go about this?
Why don't you use std::vector
instead of using arrays in C++?
Eg:
std::vector<nlist *> hashtab;
hashtab.resize(<some_value>);
But anyways you can do this if you are using g++
because g++
supports Variable Length Arrays(VLAs) as an extension.
Eg:
int HASHSIZE=<some_value>
static struct nlist *hashtab[HASHSIZE];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With