Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Hashmap copy constructor

14 views
Skip to first unread message

David

unread,
May 13, 2005, 7:45:40 AM5/13/05
to
Hi,

I have created the following HashMap class.
class HashMap: public hash_map<string, string, HashString,
HashStringCompare>
{
public:
HashMap(): hash_map<string, string, HashString, HashStringCompare>() {}
};

If I want to clone another HashMap, what should I do?


Thanks
D

David

unread,
May 13, 2005, 7:50:58 AM5/13/05
to
David wrote:

> Hi,
>
> I have created the following HashMap class.
> class HashMap: public hash_map<string, string, HashString,
> HashStringCompare>
> {
> public:
> HashMap(): hash_map<string, string, HashString, HashStringCompare>() {}
> };
>

I also found that hash_map contains copy constructor, so if I write:
HashMap hash;
hash["key"] = "key";
hash["value"] = "value";

HashMap tmp;
tmp=hash;

tmp object should contains all items from hash?

Kai-Uwe Bux

unread,
May 13, 2005, 8:26:08 AM5/13/05
to
Kai-Uwe Bux wrote:

> David wrote:
>
>> David wrote:
>>
>>> Hi,
>>>
>>> I have created the following HashMap class.
>>> class HashMap: public hash_map<string, string, HashString,
>>> HashStringCompare>
>>> {
>>> public:
>>> HashMap(): hash_map<string, string, HashString, HashStringCompare>()
>>> {}
>>> };
>

> I do not quite see the point of this definition. What is the advantage
> compared to:
>
> typedef hash_map< string, string , HashString, HashStringCompare >
> HashMap;


>
>>>
>> I also found that hash_map contains copy constructor, so if I write:
>> HashMap hash;
>> hash["key"] = "key";
>> hash["value"] = "value";
>>
>> HashMap tmp;
>> tmp=hash;
>>
>> tmp object should contains all items from hash?
>

> No, since you defined your own class by inheriting, you would have to
> provide your own copy constructor for HashMap. If you use the typedef from
> above, things would work like you seem to expect.

Oops, on second thought: the compiler will provide the default copy
constructor and assignment operator, which in your case should work as
expected. Yet, I still dont see why you want to inherit.


Best

Kai-Uwe Bux

Kai-Uwe Bux

unread,
May 13, 2005, 8:22:30 AM5/13/05
to
David wrote:

> David wrote:
>
>> Hi,
>>
>> I have created the following HashMap class.
>> class HashMap: public hash_map<string, string, HashString,
>> HashStringCompare>
>> {
>> public:
>> HashMap(): hash_map<string, string, HashString, HashStringCompare>()
>> {}
>> };

I do not quite see the point of this definition. What is the advantage
compared to:

typedef hash_map< string, string , HashString, HashStringCompare > HashMap;

>>

> I also found that hash_map contains copy constructor, so if I write:
> HashMap hash;
> hash["key"] = "key";
> hash["value"] = "value";
>
> HashMap tmp;
> tmp=hash;
>
> tmp object should contains all items from hash?

No, since you defined your own class by inheriting, you would have to

provide your own copy constructor for HashMap. If you use the typedef from
above, things would work like you seem to expect.

Best

Kai-Uwe Bux

Richard Herring

unread,
May 19, 2005, 9:24:29 AM5/19/05
to
In message <d6260a$3ne$1...@news.hgc.com.hk>, David <david...@gmail.com>
writes

>David wrote:
>
>> Hi,
>> I have created the following HashMap class.
>> class HashMap: public hash_map<string, string, HashString,
>>HashStringCompare>
>> {
>> public:
>> HashMap(): hash_map<string, string, HashString, HashStringCompare>() {}
>> };
>>
>I also found that hash_map contains copy constructor, so if I write:
>HashMap hash;
>hash["key"] = "key";
>hash["value"] = "value";
>
>HashMap tmp;
>tmp=hash;

That's not copy construction. It's default construction followed by
assignment.


>
>tmp object should contains all items from hash?
>

--
Richard Herring

1971 powerChina

unread,
May 8, 2015, 2:41:33 AM5/8/15
to
Title: The core of the big data solutions -- Map
Author: pengwenwei
Email: pww71 foxmail.com
Language: c++
Platform: Windows, linux
Technology: Perfect hash algorithm
Level: Advanced
Description: A high performance map algorithm
Section MFC c++ map stl
SubSection c++ algorithm
License: (GPLv3)

Map is widely used in c++ programs. And the bottleneck of program performance is often the performance of map. especially in big data field and the scenarios which can't realize data distribution and parallel processing. Therefore, the performance of map becomes the most critical technology.

My many years of work experience in telecommunition and information security industry Is all about big data analysis. especially in the information security industry, the data analysis is the most complicated. They can't work without map. For example, ip table, mac table, telephone numbers table, dns table etc.


Currently, the STL map and Google's hash map are the most popular maps. But they have some disadvantages. The STL map utilizes binary chop, which causes a bad performance. Google Hash map has the best performance at present, but it has probability of repeat collision. For big data analysis, the probability of repeat collision is unacceptable.

Now I would like to publish my algorithms. It includes three different maps for different scenarios:
1. Memory Map(memMap): It resides in memory and has a good access speed. But its size is limited by memory size.
2. Harddisk Map(diskMap): It utilizes hard disk to store data. So it could accept much more data than memory map.
3. Hashmap(hashMap): It has the best performance and a great lookup speed, but it doesn't have 'insert' and 'delete' functionality.

memMap and diskMap could be converted to hashMap by function memMap2HashMap and diskMap2HashMap. According to the test result, my algorithms' collision probability is zero. About performance, memMap has a comparable performance with google, and hashMap's performance is 100 times better than Google's hashmap.

In summary, my algorithms are perfect zero collision probability hash algorithms.You can refer to following artical to find the key index and compress algorithm theory:
http://blog.csdn.net/chixinmuzi/article/details/1727195

Source code and documents:
https://sourceforge.net/projects/pwwhashmap/files/?source=navbar
0 new messages