Stuff a pair of size_t into an uint32_t

G

Giuseppe:G:

Hi,

I apologise for starting a new thread on a partially answered question.
My previous problem has gotten more serious :)

So I have a function defined as follows:

bool observe(const WordID* dataword);

where WordID is

typedef uint32_t WordID;


My purpose is to use this function with some different data I already
have: the problem is, this data is NOT in the WordID format.

What I have is *pairs* of values, that I would like to input together
into observe(). In other words, I have pairs of numbers whose type is size_t

(size_t, size_t), (size_t, size_t), ... etc.

How can I input one of these pairs into observe()? I've heard that on
gcc size_t can be bigger than one uint32_t, so stuffing two into that
would definitely be a problem. What if I redefine the typedef such that
WordID is

typedef uint64_t WordID;

? And then maybe I could concatenate the two size_t and cast them into
that uint64_t? Would a uint64_t be enough? I was thinking about this:

observe(uint64_t* wordid);

and then

uint64_t chain(uint32_t one, uint32_t two) {
// get two 32bit rands and concatenate
uint64_t longrand = one;
longrand <<= 32;
longrand |= two;
return longrand;
}

The problem is this is a global typedef, used by many more function and
I'm not sure if this would harm something.

Any ideas would be greatly appreciated.

Cheers
Giuseppe
 
G

Giuseppe:G:

Sam said:
Then you supply the required logic here. If the wordptr class member is
not null (presuming that observe(int64_t *) never receives a null ptr),
your code knows that it received a uint64_t ptr. If the wordptr class
member is null, your code uses the two size_t parameters.

Thanks Sam, I guess I get the philosophy behind this now.

Only thing is, how would you go about creating a unique piece of data
from the two size_t?

In my program, while size_t word1 may appear several times, and size_t
word2 may appear several times, the combination of the two is unique.

Observe() is part of a Bloom filter, and what I'm trying to do is
storing (size_t 1, size_t 2) into the filter, and then later test the
filter for membership of the pair.

Could I, for instance, append one size_t to the other?

Regards
Giuseppe
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,772
Messages
2,569,591
Members
45,101
Latest member
MarcusSkea
Top