5 ms·
As someone who does not work with Javascript, I'm shocked that any language would have sets and not support these three operations.
by 7734128 3y ago
As someone who does not work with Javascript, I'm shocked that any language would have sets and not support these three operations.
- Aardwolf 3y agoC++ sets didn't even support 'contains' in the past
- nyrikki 3y agoC++ 'sets' are ordered mutable binary search trees in most implementations. Not the ties and hashtables of other languages. With strict weak ordering, you really only have the ordering of to elements. Ada took care of that polysemy between ordered and hash sets a long time ago. But ya it took them to long to implement 'contains', but JavaScript requiring ordered sets while allowing multiple implementation details complicated it IMHO. Had they chosen a structure vs a time complexity it would have been easier to extend. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe...
- Calavar 3y agoThat's just objectively untrue. C++ sets have always supported membership testing. bool set_contains_x = set.find(x) != set.end();
- Aardwolf 3y agoI know that, but that's a rather elaborate way of doing the main thing sets do, and you have to repeat the name of the set twice. Fortunately C++20 added set.contains(x). Of course set.count(x) also already existed but some would prefer set.find(x) != set.end() anyway for <reasons>, and it's the fault of the language's design to cause such opinions in the first place imho.
- qarl 3y agoI hate to be pedantic, but since you started it: That is not a contains() function. That is a search followed by a test for not not-found.
- Calavar 3y agoThat's a valid distinction for a vector or a list. For a set, contains and search are one and the same.
- qarl 3y agoNo, they are not the same thing. They are logically equivalent, which is not the same thing as same thing. 1+3 is logically equivalent to 4, but they are not the same. As just one example, the former contains an operation.
- BurningFrog 3y agoYeah, it seems like something you can code up in an afternoon.