Stuff a pair of size_t into an uint32_t

Discussion in 'C++' started by Giuseppe:G:, Jul 12, 2008.

  1. Giuseppe:G:

    Giuseppe:G: Guest

    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
     
    Giuseppe:G:, Jul 12, 2008
    #1
    1. Advertising

  2. Giuseppe:G:

    Giuseppe:G: Guest

    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?

    Regards
    Giuseppe
     
    Giuseppe:G:, Jul 12, 2008
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Alex Vinokur
    Replies:
    9
    Views:
    817
    James Kanze
    Oct 13, 2008
  2. Francois Grieu

    [C99] how to test if type uint32_t exists?

    Francois Grieu, Feb 19, 2010, in forum: C Programming
    Replies:
    10
    Views:
    4,830
    Francois Grieu
    Feb 20, 2010
  3. David Mathog
    Replies:
    8
    Views:
    3,964
    Keith Thompson
    Jan 26, 2011
  4. Alex Vinokur
    Replies:
    1
    Views:
    595
  5. A. Farber
    Replies:
    11
    Views:
    320
    Jens Thoms Toerring
    Apr 4, 2009
Loading...

Share This Page