Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Stuff a pair of size_t into an uint32_t

Thread Tools

Stuff a pair of size_t into an uint32_t

Posts: n/a

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.

Reply With Quote
Posts: n/a
Sam wrote:
> 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?


Reply With Quote

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
reinterpret_cast<std::size_t>(p) and reinterpret_cast<std::size_t&>() Alex Vinokur C++ 1 02-06-2011 07:48 AM
[C99] how to test if type uint32_t exists? Francois Grieu C Programming 10 02-20-2010 02:14 PM
Casting from const pair<const unsigned char*, size_t>* to constpair<unsigned char*, size_t>* Alex Vinokur C++ 9 10-13-2008 05:05 PM