Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > Need Hashmap in C AND C++

Reply
Thread Tools

Need Hashmap in C AND C++

 
 
lbrtchx@gmail.com
Guest
Posts: n/a
 
      04-25-2008
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
 
Reply With Quote
 
 
 
 
user923005
Guest
Posts: n/a
 
      04-25-2008
On Apr 24, 7:18*pm, (E-Mail Removed) 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.
 
Reply With Quote
 
 
 
 
kasthurirangan.balaji@gmail.com
Guest
Posts: n/a
 
      04-25-2008
On Apr 25, 7:18*am, (E-Mail Removed) 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.
 
Reply With Quote
 
user923005
Guest
Posts: n/a
 
      04-25-2008
On Apr 24, 7:18*pm, (E-Mail Removed) 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/...src_index.html
 
Reply With Quote
 
asterisc
Guest
Posts: n/a
 
      04-25-2008
On Apr 25, 5:18 am, (E-Mail Removed) 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.
 
Reply With Quote
 
Juha Nieminen
Guest
Posts: n/a
 
      04-25-2008
http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:
> I was wondering if there are plain ANSI C hashmaps?


Standard C has no data containers whatsoever, so no such luck.
 
Reply With Quote
 
Flash Gordon
Guest
Posts: n/a
 
      04-25-2008
Sam wrote, On 25/04/08 12:11:
> (E-Mail Removed) 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
 
Reply With Quote
 
alasham.said@gmail.com
Guest
Posts: n/a
 
      04-25-2008
On Apr 25, 4:18 am, (E-Mail Removed) 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.
 
Reply With Quote
 
Richard
Guest
Posts: n/a
 
      04-25-2008
Flash Gordon <(E-Mail Removed)> writes:

> Sam wrote, On 25/04/08 12:11:
>> (E-Mail Removed) 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"?

 
Reply With Quote
 
Flash Gordon
Guest
Posts: n/a
 
      04-25-2008
Richard wrote, On 25/04/08 22:44:
> Flash Gordon <(E-Mail Removed)> writes:
>
>> Sam wrote, On 25/04/08 12:11:
>>> (E-Mail Removed) 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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
reuse HashMap$Entry (or HashMap in total) to avoid millions of allocations Vince Darley Java 4 03-02-2010 07:48 AM
need clarification on HashMap storage-retrieval Lew Java 7 09-04-2008 04:55 AM
Need Hashmap in C AND C++ lbrtchx@gmail.com C++ 0 04-25-2008 02:18 AM
java.util.Properties extending from HashMap<Object, Object> insteadof HashMap<String, String> Rakesh Java 10 04-08-2008 04:22 AM
do I need "volatile" for HashMap? when I apply ReentrantReadWriteLock on it. easy Java 2 09-30-2007 08:41 PM



Advertisments