mapping in C++

This is a discussion on mapping in C++ within the C++ Programming forums, part of the General Programming Boards category; how do i map two numbers in C++ ? i mean : gcd[23,32]=1 gcd[100,100]=100 how do i do this ??? ...

  1. #1
    Registered User
    Join Date
    Jan 2009
    Posts
    71

    mapping in C++

    how do i map two numbers in C++ ?

    i mean :

    gcd[23,32]=1
    gcd[100,100]=100

    how do i do this ???

    note: i cannot use a two dimensional array since i need to store values upto 10000 & i cannot create such a huge array(gcd[10000][10000])
    i.e., gcd[10000,10000]=10000;

    any suggestions ??

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Not sure, but would
    Code:
    std::map<std::pair<int, int> > gcd;
    do the work.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  3. #3
    Registered User
    Join Date
    Jan 2009
    Posts
    71

    thanks

    oh..will have to read up about pair

    thank u !

  4. #4
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Another option would be to use math:
    gcd[x * 10000 + y] - that will make a unique number in the 0..100000000 range, which can be used with map. It is possibly faster and easier than using a pair. But if the range grows much more than 10000, you'd struggle.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  5. #5
    Registered User
    Join Date
    Jan 2009
    Posts
    71

    x,y ??

    gcd[x * 10000 + y]

    if x=10000 & y=10000 then array size would become too large ?

    isn't it ?

  6. #6
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by jack_carver View Post
    gcd[x * 10000 + y]

    if x=10000 & y=10000 then array size would become too large ?

    isn't it ?
    No, not a regular large array, I meant to still use map, like this:
    Code:
    std::map<int> gcd;
    
    gcd[300 *10000 + 432] = ...
    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. OpenGL texture mapping with texCoordArray
    By nempo in forum Game Programming
    Replies: 1
    Last Post: 08-24-2008, 04:00 AM
  2. MapServer and other mapping tools
    By DavidP in forum A Brief History of Cprogramming.com
    Replies: 0
    Last Post: 12-29-2007, 01:27 AM
  3. OpenGL Shadow Mapping Issues
    By animeaholic in forum Game Programming
    Replies: 0
    Last Post: 06-05-2007, 09:49 AM
  4. O/R Mapping tool like Apple has.....for .NET?!?!
    By gicio in forum C# Programming
    Replies: 0
    Last Post: 08-29-2003, 04:20 AM
  5. Terrain mapping problem
    By DavidP in forum Windows Programming
    Replies: 1
    Last Post: 11-26-2001, 09:08 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21