Unique key for 3D interger coordinates to insert into a std::unordered_set

Unique key for 3D interger coordinates to insert into a std::unordered_set

I have a stream of 3D integer coordinates that correspond to voxels and thus are aligned on a grid. I want to figure out if the current processed triplet is already existing in order to filter duplicates. I was able to build a simple solution to my problem with a std::set. Let x y z be 3 int and registrybe a std::set< std::array<int, 3> >. I made a function that return a bool like that

I have a stream of 3D integer coordinates that correspond to voxels and thus are aligned on a grid. I want to figure out if the current processed triplet is already existing in order to filter duplicates. I was able to build a simple solution to my problem with a std::set. Let x y z be 3 int and registrybe a std::set< std::array<int, 3> >. I made a function that return a bool like that

std::array<int, 3> key = {x, y, z};
return registry.insert(key).second;

But this is far to be optimized in term of computation time. Reading documentation and SO topics I understand that an unordered_set should be more appropriated. Indeed there is no need to sort anything here. In addition I guess that using a array<int,3> as key is not efficient for comparison at insert time.

An unordered_set requires a hash function. Studying hash functions I found boost::hash_combineas well as other options but the problem of hash is the collisions. In fact I need to build unique keys on 96 bits to ensure that I won't have collision.

How can I use an unordered_set efficiently in my situation? The key point is being as fast as possible. I don't need to access to values and I don't need to make any special computations.

c++

Bootstrap 5 Complete Course with Examples

Bootstrap 5 Tutorial - Bootstrap 5 Crash Course for Beginners

Nest.JS Tutorial for Beginners

Hello Vue 3: A First Look at Vue 3 and the Composition API

Building a simple Applications with Vue 3

Deno Crash Course: Explore Deno and Create a full REST API with Deno

How to Build a Real-time Chat App with Deno and WebSockets

Convert HTML to Markdown Online

HTML entity encoder decoder Online

Loops in C++ | For, While, and Do While Loops in C++

In this Video We are going to see how to use Loops in C++. We will see How to use For, While, and Do While Loops in C++.

Using isdigit() in C/C++

In this article, we'll take a look at using the isdigit() function in C/C++. This is a very simple way to check if any value is a digit or not. Let's look

C++ Tutorial for Beginners 19 - C++ Structures | Struct declaration | C++ Data Structures

Welcome to this course on C++ Tutorial for Beginners. In this video we will see How to use C++ Structures.

Object Oriented Programming in C++ | C++ OOPs Concepts | Learn Object Oriented C++

C++ is general purpose, compiled, object-oriented programming language and its concepts served as the basis for several other languages such as Java, Python, Ruby, Perl etc.

A Complete Guide to fread() in C/C++

In this article, we’ll take a look at using fread() in C/C++.