map template error? , default template

76 views
Skip to first unread message

drax325

unread,
May 5, 2015, 3:31:31 PM5/5/15
to std-dis...@isocpp.org
I can only seem to only allow derived types of std::less<T>  to use as comparator with map  

template <typename _Key, typename _Tp, typename _Compare = std::less<_Key>,
            typename _Alloc = std::allocator<std::pair<const _Key, _Tp> > >
    class map
    {


Old post on other sites indicate that it should handle std::greater<T> 
And that template type can have default values.

So, I'm wondering if the rules changed where _Compare = std::less<_Key>  not defined parent class.

So, what are the rules for this situation? Is this compiler error?

or is it intentional to have the comparator derive from std::less.

sghe...@gmail.com

unread,
May 5, 2015, 3:42:36 PM5/5/15
to std-dis...@isocpp.org
Of course the rules didn't change.

It's simple PEBCAK


#include <map>


std
::map<int, int, std::greater<int> > voila;

int main(){}



Also, this list is not a QA site. It's for discussing the current standard/future directions

Sehe

drax325

unread,
May 5, 2015, 4:06:00 PM5/5/15
to std-dis...@isocpp.org
I swore I tried that configuration, but it couldn't resolve it with using just the parameter. 
So, Template would define the parent class, that parameter must be of.
I thought it used parameter to resolve type , I guess not with default values?

i.e. this didn't work:
std::map<int,int> mm( table.begin(), table.end(), std::greater<int>());


Sorry about the post then. I just want to ask people who more likely would know the standard in case it was wrong, most people don't.

Daniel Krügler

unread,
May 5, 2015, 4:08:20 PM5/5/15
to std-dis...@isocpp.org
2015-05-05 22:06 GMT+02:00 drax325 <drax...@gmail.com>:
> I swore I tried that configuration, but it couldn't resolve it with using
> just the parameter.
> So, Template would define the parent class, that parameter must be of.
> I thought it used parameter to resolve type , I guess not with default
> values?
>
> i.e. this didn't work:
> std::map<int,int> mm( table.begin(), table.end(), std::greater<int>());

Write

std::map<int,int, std::greater<int>> mm(table.begin(), table.end());

instead. You only need to provide the comparator to the constructor,
if it isn't default-constructible or needs to keep state.

- Daniel

1971 powerChina

unread,
May 8, 2015, 9:11:29 PM5/8/15
to std-dis...@isocpp.org
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 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 addition, my algorithms are perfect hash algorithms with zero collision probability.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
Reply all
Reply to author
Forward
0 new messages