yakra / DataProcessing

Data Processing Scripts and Programs for Travel Mapping Project
0 stars 0 forks source link

unordered_set::count #199

Closed yakra closed 2 years ago

yakra commented 2 years ago

https://www.cplusplus.com/reference/unordered_set/unordered_set/count/

Count elements with a specific key Searches the container for elements with a value of k and returns the number of elements found. Because unordered_set containers do not allow for duplicate values, this means that the function actually returns 1 if an element with that value exists in the container, and zero otherwise.

haystack.find(needle) != haystack.end() -> haystack.count(needle) With longer variable names, this adds up. More intuitive: 1 if found, 0 if not; more in line with Python's needle in haystack.

There's no reason this should perform any slower, right?

grep 'find.*end()' `find . -name \*.cpp` | wc -l