-
July 10th, 2015, 11:03 PM
#1
About C++ HashSet and unordered_set
I am creating a container of std::set, but I need to search it in logarithmic time or constant time.
Sets don't provide such capabilities, so I look into hash sets,
I discover the C++ standard library provides something called unordered_set
But it needs to provide some comparator or override for the contained objects.
As before, I've a class which already implemented the
Code:
bool operator < (const AABB& other) const;
But this isn't enough, I still get some errors like these.
Error 1 error C2338: The C++ Standard doesn't provide a hash for this type. c:\program files (x86)\microsoft visual studio 12.0\vc\include\xstddef 328 1 Perfectsim
What other stuff do I need in order to compile for the unordered_set? I can't find good examples on the net.
Thanks
Jack
Last edited by lucky6969b; July 10th, 2015 at 11:10 PM.
-
July 11th, 2015, 12:42 AM
#2
Re: About C++ HashSet and unordered_set
Hello, I think I should have added a hashing function,
But how do I define a good hashing function for my need?
How do I design one to make the access time good?
Thanks
Jack
Code:
struct AABBHasher {
size_t operator()(const AABB& aabb) const {
return 0;
}
size_t operator()(const boost::shared_ptr<AABB>& aabb) const {
return 0;
}
};
The elements I need to look up are just x and z coordinates, probably add y later.
Last edited by lucky6969b; July 11th, 2015 at 01:14 AM.
-
July 11th, 2015, 03:34 AM
#3
Re: About C++ HashSet and unordered_set
All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!
C++23 Compiler: Microsoft VS2022 (17.6.5)
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|