unordered-set Questions

3

Solved

I want to use an unordered_set with a custom struct. In my case, the custom struct represents a 2D point in an euclidean plane. I know that one should define a hash function and comparator operator...
Blasphemous asked 16/6, 2018 at 12:56

2

Solved

I have an array of integers stored contiguously in memory and I want to add them all to a unordered_set collection. Right now, I am adding them one at a time. for (int i = 0; i < count; i++) ...
Sclerometer asked 12/4, 2019 at 13:23

2

Solved

I understand a set is ordered, thus adding an object without overloading the < operator doesn't allow to say which object is smaller to keep the container sorted. However, I don't understand why...
Tiannatiara asked 22/11, 2016 at 21:0

2

Solved

I'm using a std::unordered_set for the first time and have a question about the hash function. As far as I understand, if you don't specify a hash function it will default to std::hash<Key>. ...
Indention asked 21/11, 2012 at 3:39

2

Solved

What is the time complexity of find method in unordered_set<int>? And also is it possible to change the hash functions ?
Presence asked 27/2, 2017 at 14:2

2

Solved

I have the following code to make an unordered_set<Interval>. This compiles fine. struct Interval { unsigned int begin; unsigned int end; bool updated; //true if concat. initially false ...
Guardado asked 7/4, 2013 at 23:24

2

Solved

Suppose I have an unordered_set<int> S and I wanna to check if it contains a certain int x. Is there a way for me to write something like if(S.contains(x)){ /* code */ } that works like if(S...
Outport asked 15/12, 2018 at 18:35

4

Solved

Here is my code, wondering any ideas to make it faster? My implementation is brute force, which is for any elements in a, try to find if it also in b, if so, put in result set c. Any smarter ...
Ambur asked 20/12, 2017 at 8:2

4

Solved

I've seen people mention that a random element can be grabbed from an unordered_set in O(1) time. I attempted to do so with this: std::unordered_set<TestObject*> test_set; //fill with data ...
Inconsequent asked 6/10, 2012 at 15:58

1

Solved

Let's say you have an std::unordered_set<std::string> . You have an std::string_view object that you want to search for in the container. Problem is, you don't want to create a std::s...
Reducer asked 8/8, 2018 at 14:22

5

Solved

In my custom physics engine, the biggest bottleneck is a method that gets all bodies from the spatial partitioning (a 2D grid), and returns a collection containing only unique pointers to body. te...
Rickierickman asked 8/4, 2013 at 13:13

2

Solved

For ex, unordered_set<int> s ; s.insert(100); How do I get value 100 from s? From http://www.cplusplus.com/reference/unordered_set/unordered_set/begin/, Notice that an unordered_set o...
Sigmon asked 5/7, 2018 at 9:18

1

Solved

I have an unordered_set<shared_ptr<T>> us and I would like to know whether a needle k is in us, but k has type shared_ptr<T const> so unordered_set<shared_ptr<T>>::fin...
Irresistible asked 8/6, 2018 at 10:16

2

I'm brand new to C++ and have been asked to convert a Java program to C++. I'm trying to write a method to check that all elements in an unordered_set exist in another unordered_set. I found the ex...
Frantz asked 17/1, 2018 at 10:56

4

Solved

The Question What is a good specialization of std::hash for use in the third template parameter of std::unordered_map or std::unordered_set for a user defined type for which all member data types ...
Hypsometer asked 23/6, 2014 at 8:53

4

Solved

What is the purpose of 3rd parameter KeyEqual in std::unordered_set? Isn't hash uniqueness enough? template< class Key, class Hash = std::hash<Key>, class KeyEqual = std::equal_to<K...
Relator asked 23/8, 2016 at 17:33

3

I want to store a floating point value for an unordered pair of an integers. I am unable to find any kind of easy to understand tutorials for this. E.g for the unordered pair {i,j} I want to store ...
Reminiscence asked 21/3, 2015 at 7:23

5

Solved

I started to use the unordered_set class from the tr1 namespace to speed-up access against the plain (tree-based) STL map. However, I wanted to store references to threads ID in boost (boost::threa...
Waw asked 21/4, 2009 at 11:49

2

Solved

I have a relatively large file that I needed to ensure contained only unique lines. The file is only 500MB. I understand that there is plenty of overhead, but I was seeing nearly 5GB of RAM usage. ...
Coulee asked 12/5, 2016 at 4:16

1

Solved

If iterate over the elements of std::unordered_set multiple times without changing the contents of the set (but potentially reading from it, calculating its size, etc.), is it guaranteed that the e...
Saddlebacked asked 26/3, 2016 at 23:26

2

Solved

The following program does not compile. But If I do not comment out operator==, it compiles. Why operator== is still needed when I already provide FooEqual #include <cstddef> #include <u...
Rhone asked 23/3, 2016 at 0:32

2

Solved

What's a concise way to iterate on unordered-pairs of elements in unordered_set? (So order doesn't matter and elements should be different) e.g. {1, 2, 3} => (1, 2) (2, 3) (1, 3) My initial a...
Obit asked 25/1, 2016 at 17:55

4

Solved

I have an unordered_set of chars std::unordered_set<char> u_setAlphabet; Then I want to get a content from the set as std::string. My implementation now looks like this: std::string getAl...
Megillah asked 30/12, 2015 at 11:40

3

Solved

I've got an enumeration type defined inside of a class, and I want to create an unordered_set of those objects as a member of the class: #include <unordered_set> class Foo { public: enum B...
Abingdon asked 26/9, 2015 at 17:38

2

Solved

I'd like to find a value in unordered_set, but failed: typedef std::shared_ptr<int> IntPtr; std::unordered_set<IntPtr> s; s.insert(std::make_shared<int>(42)); bool found = s.fi...
Formal asked 16/9, 2015 at 15:50

© 2022 - 2024 — McMap. All rights reserved.