News for hackers. Stuff that matters.
Re:Accidentally quadratic: When Python is faster than C++ by brundolf on Thursday March 04, 2021 @11:20AM (#26344322)
Why is the default set implementation ordered in the first place? The formal data structure is unordered, which probably informs people's assumptions about its performance characteristics. Should it not be "set" and "ordered_set"?
Re:Accidentally quadratic: When Python is faster than C++ by hashingroll on Thursday March 04, 2021 @11:46AM (#26344706)
One reason would be because std::set guarantees O(log n) complexity for each operation on the worst case. std::unordered_set has average complexity O(1) and O(size) for the worst case (it being a hash table) which can be unexpected to debug in those rare cases.
Re:Accidentally quadratic: When Python is faster than C++ by mannerheim on Thursday March 04, 2021 @12:13PM (#26345049)
Probably because the underlying implementation is a binary search tree which requires a comparison operator. Haskell likewise has Data.Set which requires an Ord instance. There's HashSet which requires a Hashable instance which can be automatically derived for any data type, so in principle you don't need ordering, but I would imagine in C++ you would have to provide your own hashing function from whatever data type you're trying to put in a hash set.
Re:Accidentally quadratic: When Python is faster than C++ by masklinn on Thursday March 04, 2021 @11:50AM (#26344750)
> Why is the default set implementation ordered in the first place?

"Sorted" rather than ordered (an order can be arbitrary and I'd personally associate the word with insertion order).

> The formal data structure is unordered

The formal data structure doesn't have complexity bounds, the STL does.

Re:Accidentally quadratic: When Python is faster than C++ by einpoklum on Saturday March 06, 2021 @05:42PM (#26371188)
It's a mis-feature. And since C++ is very committed to backwards compatibility, they didn't change it later on.

If/when `std2::` happens, this is one of the things I assume would change.