Re:Comparison of C++17, Go, and Java for a next-generation s...
by WesternStar on Thursday April 23, 2020 @06:08PM
(#22962126)
<unpopular opinion>We should break ABI on unordered map just to stop embarrassing ourselves in public and in front of new users.</unpopular opinion>
[ Parent
| on HN ]
Re:Comparison of C++17, Go, and Java for a next-generation s...
by alexhutcheson on Thursday April 23, 2020 @09:55PM
(#22963840)
It’s unfortunately not just ABI, but also API. The standard specifies that you can get iterations to specific buckets in O(1)[1], and also specifies bucket_count(), max_bucket_count(), bucket_size() (which is specified to be O(n)), and bucket(). Those functions and their specified performance make it effectively impossible to implement a standards-compliant std::unordered_map without using separate chaining.
[1] https://en.cppreference.com/w/cpp/container/unordered_map/be...
Re:Comparison of C++17, Go, and Java for a next-generation s...
by SamReidHughes on Friday April 24, 2020 @12:11PM
(#22969614)
You can just remove those functions. The real problem is that the API break would invalidate iterators and create undefined behavior.
Re:Comparison of C++17, Go, and Java for a next-generation s...
by UncleMeat on Friday April 24, 2020 @12:15AM
(#22964562)
I'm not even sure that is an unpopular opinion. Its a minority opinion, but people on the committee have been grumbling about how ABI consistency is hamstringing C++ for a while now.
Re:Comparison of C++17, Go, and Java for a next-generation s...
by RantyDave on Thursday April 23, 2020 @06:22PM
(#22962252)
What's wrong with unordered map?
Re:Comparison of C++17, Go, and Java for a next-generation s...
by ezoe on Thursday April 23, 2020 @06:37PM
(#22962369)
It's implementation is buckets divided node based hash map. Theoretically, its order is good, but not that efficient in modern hardware where the memory access is heavily cached so the data locality is more important than saving the memory copy or memory size. Using the linked list to save some memory copy doesn't benefit at all and the overhead is far greater than simply copying the contagious large chunk of memory. Especially so if the data type is trivial so the simple byte by byte memcpy is suffice.
Re:Comparison of C++17, Go, and Java for a next-generation s...
by gpderetta on Thursday April 23, 2020 @06:49PM
(#22962471)
> contagious
normally I wouldn't point out an obvious autocorrect mistake, but this is really season-appropriate (or, better, inappropriate) :).
Re:Comparison of C++17, Go, and Java for a next-generation s...
by ezoe on Thursday April 23, 2020 @07:27PM
(#22962827)
Oh that's... not intended really.
Re:Comparison of C++17, Go, and Java for a next-generation s...
by TwoBit on Friday April 24, 2020 @01:14AM
(#22964872)
So use unordered_map with an allocator that returns nodes from a small local memory?
Re:Comparison of C++17, Go, and Java for a next-generation s...
by josefx on Friday April 24, 2020 @02:19AM
(#22965209)
To be useful that would require that the nodes are allocated in the order they appear in the map (and still has pointer overhead). Is that a given with an unordered map or does it break down the moment the map is rehashed?
Re:Comparison of C++17, Go, and Java for a next-generation s...
by cozzyd on Thursday April 23, 2020 @06:56PM
(#22962541)
why not just define std::dict or something like that that is better?
Re:Comparison of C++17, Go, and Java for a next-generation s...
by WesternStar on Thursday April 23, 2020 @07:48PM
(#22962997)
Because you should be able to find a good hash data structure for your language. You shouldn't be able to accidentally get a bad one. It should arguably be the first data structure you reach for.
Re:Comparison of C++17, Go, and Java for a next-generation s...
by imtringued on Friday April 24, 2020 @07:57AM
(#22967019)
Deprecate the old data structure. Even Java did that. Originally it had the Vector class as primary List type. Nowadays everyone uses the List interface and ArrayLists as default implementation.
You can even find this in the javadoc of the Vector class:
>As of the Java 2 platform v1.2, this class was retrofitted to implement the List interface, making it a member of the Java Collections Framework. Unlike the new collection implementations, Vector is synchronized. If a thread-safe implementation is not needed, it is recommended to use ArrayList in place of Vector.
Re:Comparison of C++17, Go, and Java for a next-generation s...
by gpderetta on Friday April 24, 2020 @04:21AM
(#22965773)
I think the parent is proposing adding a better hash map to the standard library but with a different name to preserve backward compatibility.
Re:Comparison of C++17, Go, and Java for a next-generation s...
by ezoe on Thursday April 23, 2020 @06:32PM
(#22962320)
The problem is, hash map isn't that effective in modern hardware, the overhead cost is greater than the benefit. If it's consists of clustered network connected computers, it may be, but not for the single local computer for the most of problem.