Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to remove elements from an std::unordered_set through bucket iterators?

Like the question says, can you remove an element from a std::unordered_set using a bucket iterator (local_iterator)? I can see two possible solutions:

  • Since erase() does only accept global iterators, is there equivalent functionality for local_iterator?
  • Is it possible to obtain the equivalent global iterator for a local_iterator?

If it's not feasible, please elaborate on why it's not.

like image 728
Tom De Caluwé Avatar asked Aug 29 '13 07:08

Tom De Caluwé


People also ask

How do you remove an element from an unordered set?

The unordered_set::erase() function is a built-in function in C++ STL which is used to remove either a single element or a group of elements ranging from start(inclusive) to end(exclusive). This decreases the size of a container by the number of elements removed.

What is Bucket Unordered_set?

The unordered_set::bucket() method is a builtin function in C++ STL which returns the bucket number of a specific element. That is, this function returns the bucket number where a specific element is stored in the unordered_set container.

What is unsorted set?

Unordered set is an associative container that contains a set of unique objects of type Key. Search, insertion, and removal have average constant-time complexity. Internally, the elements are not sorted in any particular order, but organized into buckets.

What is a Hashset in C++?

Definition of C++ hashset. Hashset can be defined as an unordered collection that consists of unique elements. Hashset consists of standard operation collection such as Contains, Remove, Add; it also constitutes of the standard set-based operations like symmetric difference, intersection, and union.


1 Answers

The obvious answer is no, since there is no function in the interface which supports this. There is also no way to get to an iterator from a local_iterator, for the obvious reason that a local_iterator contains a lot less information. (For most implementations, I suspect that it would be fairly simple to implement erase( local_iterator ), had the standard required it. On the other hand, I can't think of a conceivable use for it, which may be why the standard didn't require it.)

like image 57
James Kanze Avatar answered Nov 12 '22 05:11

James Kanze