unordered-set Questions

3

Solved

I am storing the ownership of some objects inside an unordered_set, using unique_ptrs. But I don't know a good way to erase one of them from the set, when the time comes. Code looks something like...
Kodok asked 14/2, 2020 at 4:57

4

Solved

I know that people use unordered_set when they don't care about the order of the elements in the set. However, when I run the sample program on C++ Shell #include <iostream> #include <uno...
Synovia asked 26/12, 2016 at 18:26

4

Solved

I need some class/interface name that describes an immutable, ordered set (in input order, like LinkedHashSet). I can of course just use the class like this: class Foo { public final Set<Long&...
Leaflet asked 28/7, 2014 at 22:53

15

Solved

C++0x is introducing unordered_set, which is available in boost and many other places. What I understand is that unordered_set is hash table with O(1) lookup complexity. On the other hand, set is n...
Copepod asked 28/8, 2009 at 22:42

3

Solved

I have two unordered_set and want the intersection of those. I can't find a library function to do that. Essentially, what I want is this: unordered_set<int> a = {1, 2, 3}; unordered_set<i...
Enteric asked 8/1, 2018 at 22:13

10

Solved

The following program does not compile an unordered set of pairs of integers, but it does for integers. Can unordered_set and its member functions be used on user-defined types, and how can I defin...
Funchal asked 1/3, 2013 at 15:11

3

Solved

How can I preserve the order of elements within an unordered set after using insert (or emplace) without allocating during construction? For details into this problem, here's an example: An unor...
Vichyssoise asked 31/12, 2016 at 4:5

3

Solved

I'm trying to create a Dictionary is C# that takes an Unordered Pair of Indices as its Key. For example: exampleDictionary[new UnorderedPair(x,y)] and exampleDictionary[new UnorderedPair(y,x)] shou...
Fakir asked 13/10, 2022 at 6:55

5

Solved

Why doesn't std::unordered_map<tuple<int, int>, string> just work out of the box? It is tedious to have to define a hash function for tuple<int, int>, e.g. template<> str...
Saltworks asked 18/8, 2011 at 15:49

2

Solved

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 standar...

5

It seems like when I try to define an unordered_set of vector, I get an error saying: "Call to implicitly-deleted default constructor of unordered_set< vector<int> > ." This d...
Finney asked 13/7, 2020 at 5:10

2

Solved

Why the worst case complexity of insert into set is linear constant of size of container and not the size of element itself? I am specifically talking about string. If I have a string set of size m...
Flyspeck asked 20/5, 2022 at 19:36

4

Solved

I have a set like this: set<weak_ptr<Node>, owner_less<weak_ptr<Node> > > setName; It works fine. But I would like to change it to an unordered set. However, I get about si...
Lactam asked 4/12, 2012 at 3:30

6

Solved

Assume I have a set of unique_ptr: std::unordered_set <std::unique_ptr <MyClass>> my_set; I'm not sure what's the safe way to check if a given pointer exists in the set. The normal w...
Wage asked 25/7, 2013 at 6:56

5

How can I store objects of a class in an unordered_set? My program needs to frequently check if an object exists in this unordered_set and if it does, then do some update on that object. I have lo...
Lashondalashonde asked 24/7, 2016 at 16:11

6

Solved

Given any character, what's the fastest way for me to determine if that character belongs to a set (not the container-type) of known characters. In other words, what's the fastest elegant way to i...
Scenarist asked 16/3, 2015 at 0:58

2

I'd like to use a std::pmr::unordered_map with a std::pmr::monotonic_buffer_resource. The two fit well together, because the set's nodes are stable, so I don't create a lot of holes in the buffer r...
Tresa asked 17/11, 2020 at 14:22

1

Solved

As pointed out in Using a std::unordered_set of std::unique_ptr, it is not easy to find a pointer T* in std::unordered_set<std::unique_ptr<T>>. Prior to C++20 we were forced to construc...
Resa asked 7/10, 2020 at 11:40

1

Solved

I have a vector<T> that I would like to initialize unordered_set<T> with. vector<T> will never be used again afterwards. How I've been doing it is the following std::vector<T&g...
Lamont asked 18/9, 2020 at 13:36

5

Solved

For testing purposes I created a little unordered_set and tried to iterate over the set. The set holds an own class: class Student { private: int matrNr; string name; public: Student( const int&...
Commendatory asked 9/9, 2013 at 17:55

2

Solved

I was solving the basic problem of finding the number of distinct integers in a given array. My idea was to declare an std::unordered_set, insert all given integers into the set, then output the si...
Halfbeak asked 21/8, 2020 at 2:30

1

Solved

http://www.cplusplus.com/reference/unordered_set/unordered_set/find/ The time complexity of find in an unordered_set has been given to be constant on average for an unordered_set. If I have an uno...
Augmentation asked 18/4, 2020 at 4:48

2

Solved

Basically my question is, why won't this compile? #include <iostream> #include <vector> #include <unordered_set> using namespace std; int main() { vector<int> v{1,2,3}; ...
Marshallmarshallese asked 11/3, 2020 at 3:12

2

Solved

I want to calculate some stats about my hash function (like max/avg amount of collision). I wrote dummy hash function (which mapped all keys to 1) and waited to see number of max/avg collisio...
Carce asked 26/2, 2020 at 12:1

1

Is there an insert iterator in std:: for unordered sets? As far as I can see, std::inserter requires an iterator argument. This is unsafe for unordered containers (at least for boost::unordered_set...
Rensselaerite asked 11/12, 2014 at 18:15

© 2022 - 2024 — McMap. All rights reserved.