Need Hashmap in C AND C++

L

lbrtchx

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
 
U

user923005

 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.
 
K

kasthurirangan.balaji

 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.
 
U

user923005

 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
 
A

asterisc

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.
 
F

Flash Gordon

Sam wrote, On 25/04/08 12:11:
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
 
A

alasham.said

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.
 
R

Richard

Flash Gordon said:
Sam wrote, On 25/04/08 12:11:

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"?
 
F

Flash Gordon

Richard wrote, On 25/04/08 22:44:
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?
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,020
Latest member
GenesisGai

Latest Threads

Top