Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are some uses of local iterator for STL unordered containers?

In §23.2.7 Unordered associative containers [unord.req] of the C++ standard table 91 describes the additional requirements a STL unordered associative container must meet. In this table the standard dictates that the STL unordered containers (i.e., unordered_set, unordered_map, unordered_multiset and unordered_multimap) must provide as member types local_iterator and const_local_iterator.

enter image description here

  • local_iterator is an iterator type whose category, value, difference, pointer and reference types are the same as the unordered container's iterator. This iterator can be used to iterate through a single bucket but not across buckets.
  • const_local_iterator is an iterator type whose category, value, difference, pointer and reference types are the same as the unordered container's const_iterator. This iterator can be used to iterate through a single bucket but not across buckets.

Q

What are some uses for these iterators?

like image 649
101010 Avatar asked Feb 14 '17 12:02

101010


People also ask

What does unordered map do?

unordered_map is an associated container that stores elements formed by the combination of a key value and a mapped value. The key value is used to uniquely identify the element and the mapped value is the content associated with the key. Both key and value can be of any type predefined or user-defined.

What does unordered map ++ do in C++?

In an unordered_map in c++, an unordered map is a dictionary-type data structure that stores elements. It has a (key, value) pair sequence that allows for quick retrieval of individual elements based on their specific key.

Which STL collection guarantees the uniqueness of the stored content?

set::begin() and set::end() in C++ STL. Sets are a type of associative container in which each element has to be unique because the value of the element identifies it.

Are sets unordered containers?

Unlike with lists, we cannot insert an element at a given index, since sets are unordered containers, meaning elements have not a particular position inside a set.


1 Answers

The main thing I can see it being used for is to check how many collisions you have. Using bucket you can get what bucket a key is stored in. You can then pass that bucket value to begin which will return a local_iterator to the items in that bucket. Now you can iterate that bucket and see if you collide with any other elements and if you do, what those elements are. This, in turn, allows you to tune your hashing function.

like image 78
NathanOliver Avatar answered Oct 20 '22 00:10

NathanOliver