Need Hashmap in C AND C++

Discussion in 'C Programming' started by lbrtchx@gmail.com, Apr 25, 2008.

  1. Guest

    Hi,
    ~
    I have found myself in need of some code resembling a Hashmap
    ~
    This is easily done in Java this way:
    ~
    import java.util.*;

    // __
    public class JMith00Test{
    public static void main(String[] aArgs){
    HashMap<String, Integer> HMSI = new HashMap<String, Integer>();
    HMSI.put("one", (new Integer(1)));
    HMSI.put("zwei", (new Integer(2)));
    HMSI.put("tres", (new Integer(3)));
    // __
    String aK;
    int iIxCnt = 0;
    System.out.println("// __ HMSI.size(): |" + HMSI.size() + "|");
    Iterator<String> IT = HMSI.keySet().iterator();
    while(IT.hasNext()){
    aK = IT.next();
    System.out.println("// __ |" + iIxCnt + "|" + aK + "|" +
    HMSI.get(aK) + "|");
    ++iIxCnt;
    }
    }
    }
    ~
    I was wondering if there are plain ANSI C hashmaps?

    Thansk
    lbrtchx
     
    , Apr 25, 2008
    #1
    1. Advertising

  2. user923005 Guest

    On Apr 24, 7:18 pm, wrote:
    >  Hi,
    > ~
    >  I have found myself in need of some code resembling a Hashmap
    > ~
    >  This is easily done in Java this way:
    > ~
    > import java.util.*;
    >
    > // __
    > public class JMith00Test{
    >  public static void main(String[] aArgs){
    >   HashMap<String, Integer> HMSI = new HashMap<String, Integer>();
    >   HMSI.put("one", (new Integer(1)));
    >   HMSI.put("zwei", (new Integer(2)));
    >   HMSI.put("tres", (new Integer(3)));
    > // __
    >   String aK;
    >   int iIxCnt = 0;
    >   System.out.println("// __ HMSI.size(): |" + HMSI.size() + "|");
    >   Iterator<String> IT = HMSI.keySet().iterator();
    >   while(IT.hasNext()){
    >    aK = IT.next();
    >    System.out.println("// __ |" + iIxCnt + "|" + aK + "|" +
    > HMSI.get(aK) + "|");
    >    ++iIxCnt;
    >   }
    >  }}
    >
    > ~
    >  I was wondering if there are plain ANSI C hashmaps?


    They tend to call them hash tables in ordinary C.
    Yes, there are lots of them.
     
    user923005, Apr 25, 2008
    #2
    1. Advertising

  3. Guest

    On Apr 25, 7:18 am, wrote:
    >  Hi,
    > ~
    >  I have found myself in need of some code resembling a Hashmap
    > ~
    >  This is easily done in Java this way:
    > ~
    > import java.util.*;
    >
    > // __
    > public class JMith00Test{
    >  public static void main(String[] aArgs){
    >   HashMap<String, Integer> HMSI = new HashMap<String, Integer>();
    >   HMSI.put("one", (new Integer(1)));
    >   HMSI.put("zwei", (new Integer(2)));
    >   HMSI.put("tres", (new Integer(3)));
    > // __
    >   String aK;
    >   int iIxCnt = 0;
    >   System.out.println("// __ HMSI.size(): |" + HMSI.size() + "|");
    >   Iterator<String> IT = HMSI.keySet().iterator();
    >   while(IT.hasNext()){
    >    aK = IT.next();
    >    System.out.println("// __ |" + iIxCnt + "|" + aK + "|" +
    > HMSI.get(aK) + "|");
    >    ++iIxCnt;
    >   }
    >  }}
    >
    > ~
    >  I was wondering if there are plain ANSI C hashmaps?
    >
    >  Thansk
    >  lbrtchx


    If it is in C, then is not the right group. you may google or post at
    clc. If you are looking for c++, then you may look at the new features
    in TR1.

    Thanks,
    Balaji.
     
    , Apr 25, 2008
    #3
  4. user923005 Guest

    On Apr 24, 7:18 pm, wrote:
    >  Hi,
    > ~
    >  I have found myself in need of some code resembling a Hashmap
    > ~
    >  This is easily done in Java this way:
    > ~
    > import java.util.*;
    >
    > // __
    > public class JMith00Test{
    >  public static void main(String[] aArgs){
    >   HashMap<String, Integer> HMSI = new HashMap<String, Integer>();
    >   HMSI.put("one", (new Integer(1)));
    >   HMSI.put("zwei", (new Integer(2)));
    >   HMSI.put("tres", (new Integer(3)));
    > // __
    >   String aK;
    >   int iIxCnt = 0;
    >   System.out.println("// __ HMSI.size(): |" + HMSI.size() + "|");
    >   Iterator<String> IT = HMSI.keySet().iterator();
    >   while(IT.hasNext()){
    >    aK = IT.next();
    >    System.out.println("// __ |" + iIxCnt + "|" + aK + "|" +
    > HMSI.get(aK) + "|");
    >    ++iIxCnt;
    >   }
    >  }}
    >
    > ~
    >  I was wondering if there are plain ANSI C hashmaps?


    This one has a friendly hashmap name:
    http://www2.informatik.hu-berlin.de/~weber/slipOff/src_index.html
     
    user923005, Apr 25, 2008
    #4
  5. asterisc Guest

    On Apr 25, 5:18 am, wrote:
    > Hi,
    > ~
    > I have found myself in need of some code resembling a Hashmap
    > ~
    > This is easily done in Java this way:
    > ~
    > import java.util.*;
    >
    > // __
    > public class JMith00Test{
    > public static void main(String[] aArgs){
    > HashMap<String, Integer> HMSI = new HashMap<String, Integer>();
    > HMSI.put("one", (new Integer(1)));
    > HMSI.put("zwei", (new Integer(2)));
    > HMSI.put("tres", (new Integer(3)));
    > // __
    > String aK;
    > int iIxCnt = 0;
    > System.out.println("// __ HMSI.size(): |" + HMSI.size() + "|");
    > Iterator<String> IT = HMSI.keySet().iterator();
    > while(IT.hasNext()){
    > aK = IT.next();
    > System.out.println("// __ |" + iIxCnt + "|" + aK + "|" +
    > HMSI.get(aK) + "|");
    > ++iIxCnt;
    > }
    > }}
    >
    > ~
    > I was wondering if there are plain ANSI C hashmaps?
    >
    > Thansk
    > lbrtchx


    In C++ you might find map/multimap, which are implemented in terms of
    balanced trees as far as I know (red/black trees).
    In plain C you won't find anything like this. You have to write them
    by your own.
     
    asterisc, Apr 25, 2008
    #5
  6. wrote:
    > I was wondering if there are plain ANSI C hashmaps?


    Standard C has no data containers whatsoever, so no such luck.
     
    Juha Nieminen, Apr 25, 2008
    #6
  7. Flash Gordon Guest

    Sam wrote, On 25/04/08 12:11:
    > writes:
    >
    >> Hi,
    >> ~
    >> I have found myself in need of some code resembling a Hashmap

    >
    > std::map
    >
    > Not actually a hash-based map, but you won't care.


    To find out whether this and the other C++ answers are correct ask in
    comp.lang.c++ where C++ is topical and there are rather more C++
    experts. It is not topical here in comp.lang.c
    --
    Flash Gordon
     
    Flash Gordon, Apr 25, 2008
    #7
  8. Guest

    On Apr 25, 4:18 am, wrote:
    > Hi,
    > ~
    > I have found myself in need of some code resembling a Hashmap
    > ~
    > This is easily done in Java this way:
    > ~
    > import java.util.*;
    >
    > // __
    > public class JMith00Test{
    > public static void main(String[] aArgs){
    > HashMap<String, Integer> HMSI = new HashMap<String, Integer>();
    > HMSI.put("one", (new Integer(1)));
    > HMSI.put("zwei", (new Integer(2)));
    > HMSI.put("tres", (new Integer(3)));
    > // __
    > String aK;
    > int iIxCnt = 0;
    > System.out.println("// __ HMSI.size(): |" + HMSI.size() + "|");
    > Iterator<String> IT = HMSI.keySet().iterator();
    > while(IT.hasNext()){
    > aK = IT.next();
    > System.out.println("// __ |" + iIxCnt + "|" + aK + "|" +
    > HMSI.get(aK) + "|");
    > ++iIxCnt;
    > }
    > }}
    >
    > ~
    > I was wondering if there are plain ANSI C hashmaps?
    >
    > Thansk
    > lbrtchx


    For C++ you can try std::map.
    Regards.
     
    , Apr 25, 2008
    #8
  9. Richard Guest

    Flash Gordon <> writes:

    > Sam wrote, On 25/04/08 12:11:
    >> writes:
    >>
    >>> Hi,
    >>> ~
    >>> I have found myself in need of some code resembling a Hashmap

    >>
    >> std::map
    >>
    >> Not actually a hash-based map, but you won't care.

    >
    > To find out whether this and the other C++ answers are correct ask in
    > comp.lang.c++ where C++ is topical and there are rather more C++
    > experts. It is not topical here in comp.lang.c


    Seriously, do you not get bored constantly elevating yourself into the
    spotlight with such trite, repetitive "advice"?
     
    Richard, Apr 25, 2008
    #9
  10. Flash Gordon Guest

    Richard wrote, On 25/04/08 22:44:
    > Flash Gordon <> writes:
    >
    >> Sam wrote, On 25/04/08 12:11:
    >>> writes:
    >>>
    >>>> Hi,
    >>>> ~
    >>>> I have found myself in need of some code resembling a Hashmap
    >>> std::map
    >>>
    >>> Not actually a hash-based map, but you won't care.

    >> To find out whether this and the other C++ answers are correct ask in
    >> comp.lang.c++ where C++ is topical and there are rather more C++
    >> experts. It is not topical here in comp.lang.c

    >
    > Seriously, do you not get bored constantly elevating yourself into the
    > spotlight with such trite, repetitive "advice"?


    Are you suggesting that C++ is topical here?
    Don't you get bored complaining when people are redirected to a more
    appropriate place?
    --
    Flash Gordon
     
    Flash Gordon, Apr 25, 2008
    #10
    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. Vince Darley
    Replies:
    4
    Views:
    4,431
    emilchacko
    Mar 2, 2010
  2. easy
    Replies:
    2
    Views:
    687
  3. Rakesh
    Replies:
    10
    Views:
    12,182
    Mike Schilling
    Apr 8, 2008
  4. Replies:
    0
    Views:
    430
  5. Lew
    Replies:
    7
    Views:
    480
Loading...

Share This Page