Skip to content

unordered_set::count #199

Closed
TravelMapping/DataProcessing
#507

Description

@yakra

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions