Need Hashmap in C AND C++

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • lbrtchx@gmail.com

    Need Hashmap in C AND C++

    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, IntegerHMSI = 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.prin tln("// __ HMSI.size(): |" + HMSI.size() + "|");
    Iterator<String IT = HMSI.keySet().i terator();
    while(IT.hasNex t()){
    aK = IT.next();
    System.out.prin tln("// __ |" + iIxCnt + "|" + aK + "|" +
    HMSI.get(aK) + "|");
    ++iIxCnt;
    }
    }
    }
    ~
    I was wondering if there are plain ANSI C hashmaps?

    Thansk
    lbrtchx
  • user923005

    #2
    Re: Need Hashmap in C AND C++

    On Apr 24, 7:18 pm, lbrt...@gmail.c om 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, IntegerHMSI = 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.prin tln("// __ HMSI.size(): |" + HMSI.size() + "|");
      Iterator<String IT = HMSI.keySet().i terator();
      while(IT.hasNex t()){
       aK = IT.next();
       System.out.prin tln("// __ |" + 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.

    Comment

    • kasthurirangan.balaji@gmail.com

      #3
      Re: Need Hashmap in C AND C++

      On Apr 25, 7:18 am, lbrt...@gmail.c om 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, IntegerHMSI = 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.prin tln("// __ HMSI.size(): |" + HMSI.size() + "|");
        Iterator<String IT = HMSI.keySet().i terator();
        while(IT.hasNex t()){
         aK = IT.next();
         System.out.prin tln("// __ |" + 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.

      Comment

      • user923005

        #4
        Re: Need Hashmap in C AND C++

        On Apr 24, 7:18 pm, lbrt...@gmail.c om 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, IntegerHMSI = 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.prin tln("// __ HMSI.size(): |" + HMSI.size() + "|");
          Iterator<String IT = HMSI.keySet().i terator();
          while(IT.hasNex t()){
           aK = IT.next();
           System.out.prin tln("// __ |" + iIxCnt + "|" + aK + "|" +
        HMSI.get(aK) + "|");
           ++iIxCnt;
          }
         }}
        >
        ~
         I was wondering if there are plain ANSI C hashmaps?
        This one has a friendly hashmap name:

        Comment

        • asterisc

          #5
          Re: Need Hashmap in C AND C++

          On Apr 25, 5:18 am, lbrt...@gmail.c om 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, IntegerHMSI = 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.prin tln("// __ HMSI.size(): |" + HMSI.size() + "|");
          Iterator<String IT = HMSI.keySet().i terator();
          while(IT.hasNex t()){
          aK = IT.next();
          System.out.prin tln("// __ |" + 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.

          Comment

          • Juha Nieminen

            #6
            Re: Need Hashmap in C AND C++

            lbrtchx@gmail.c om wrote:
            I was wondering if there are plain ANSI C hashmaps?
            Standard C has no data containers whatsoever, so no such luck.

            Comment

            • Sam

              #7
              Re: Need Hashmap in C AND C++

              lbrtchx@gmail.c om 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.


              -----BEGIN PGP SIGNATURE-----
              Version: GnuPG v1.4.7 (GNU/Linux)

              iD8DBQBIEbxKx9p 3GYHlUOIRAtV1AJ 4+28z4mFqkEhtBM D9XqQEgmnQqiQCf YMI5
              6BtpLJMFN1zq1cD KX/aY3vM=
              =xhqa
              -----END PGP SIGNATURE-----

              Comment

              • Flash Gordon

                #8
                Re: Need Hashmap in C AND C++

                Sam wrote, On 25/04/08 12:11:
                lbrtchx@gmail.c om 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

                Comment

                • alasham.said@gmail.com

                  #9
                  Re: Need Hashmap in C AND C++

                  On Apr 25, 4:18 am, lbrt...@gmail.c om 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, IntegerHMSI = 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.prin tln("// __ HMSI.size(): |" + HMSI.size() + "|");
                  Iterator<String IT = HMSI.keySet().i terator();
                  while(IT.hasNex t()){
                  aK = IT.next();
                  System.out.prin tln("// __ |" + 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.

                  Comment

                  • Richard

                    #10
                    Re: Need Hashmap in C AND C++

                    Flash Gordon <spam@flash-gordon.me.ukwri tes:
                    Sam wrote, On 25/04/08 12:11:
                    >lbrtchx@gmail.c om 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"?

                    Comment

                    • Flash Gordon

                      #11
                      Re: Need Hashmap in C AND C++

                      Richard wrote, On 25/04/08 22:44:
                      Flash Gordon <spam@flash-gordon.me.ukwri tes:
                      >
                      >Sam wrote, On 25/04/08 12:11:
                      >>lbrtchx@gmail.c om 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

                      Comment

                      • Malcolm McLean

                        #12
                        Re: Need Hashmap in C AND C++


                        <lbrtchx@gmail. comwrote in message
                        I was wondering if there are plain ANSI C hashmaps?
                        >
                        In C++ there is one in the standard template library. In C you have to use a
                        third party one, and as far as I know nothing has become a de facto
                        standard. So the alternative uis to write one yourself.

                        There's a hashtable on my website, in the Basic Algorithms example code.
                        However it is meant as teaching code about how the hash table works.

                        --
                        Free games and programming goodies.


                        Comment

                        • CBFalconer

                          #13
                          Re: Need Hashmap in C AND C++

                          lbrtchx@gmail.c om wrote:
                          >
                          .... snip ...
                          >
                          I was wondering if there are plain ANSI C hashmaps?
                          Yes. See hashlib at: <http://cbfalconer.home .att.net/download/>

                          --
                          [mail]: Chuck F (cbfalconer at maineline dot net)
                          [page]: <http://cbfalconer.home .att.net>
                          Try the download section.

                          ** Posted from http://www.teranews.com **

                          Comment

                          • CBFalconer

                            #14
                            Re: Need Hashmap in C AND C++

                            Juha Nieminen wrote:
                            lbrtchx@gmail.c om wrote:
                            >
                            >I was wondering if there are plain ANSI C hashmaps?
                            >
                            Standard C has no data containers whatsoever, so no such luck.
                            I thought I answered this already. At any rate, there are
                            libraries written in Standard C, and thus highly portable. One is
                            my hashlib package, released under GPL. See:

                            <http://cbfalconer.home .att.net/download/>

                            --
                            [mail]: Chuck F (cbfalconer at maineline dot net)
                            [page]: <http://cbfalconer.home .att.net>
                            Try the download section.


                            ** Posted from http://www.teranews.com **

                            Comment

                            • Dann Corbit

                              #15
                              Re: Need Hashmap in C AND C++

                              "Flash Gordon" <spam@flash-gordon.me.ukwro te in message
                              news:ein9e5xbcd .ln2@news.flash-gordon.me.uk...
                              Sam wrote, On 25/04/08 12:11:
                              >lbrtchx@gmail.c om 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
                              It's not topical in news:comp.lang. c++ either. If it needs to work in both
                              C and C++, then a C implementation is a good idea. You can find hundreds of
                              them (like the one that I found upthread) with a web search.

                              I can't really think of an appropriate newsgroup to find an answer for the
                              question, which is why I went ahead and answered it. The FAQ answer of
                              news:comp.sourc es.wanted is really pointing to a dead newsgroup that nobody
                              bothers with any more (I see one valid post in the past several months).


                              ** Posted from http://www.teranews.com **

                              Comment

                              Working...