File: unordered_set.inc

package info (click to toggle)
stdgpu-contrib 1.3.0%2Bgit20220507.32e0517-3
  • links: PTS, VCS
  • area: contrib
  • in suites: forky, sid, trixie
  • size: 2,524 kB
  • sloc: cpp: 7,818; pascal: 1,893; xml: 214; sh: 181; makefile: 16
file content (114 lines) | stat: -rw-r--r-- 2,957 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
/*
 *  Copyright 2022 Patrick Stotko
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */

#include <stdgpu/unordered_set.cuh>

#include <cstddef>

#include <stdgpu/platform.h>

struct vec3int16
{
    vec3int16() = default;

    STDGPU_HOST_DEVICE
    vec3int16(const std::int16_t new_x, const std::int16_t new_y, const std::int16_t new_z)
      : x(new_x)
      , y(new_y)
      , z(new_z)
    {
    }

    std::int16_t x = 0; // NOLINT(misc-non-private-member-variables-in-classes)
    std::int16_t y = 0; // NOLINT(misc-non-private-member-variables-in-classes)
    std::int16_t z = 0; // NOLINT(misc-non-private-member-variables-in-classes)
};

inline STDGPU_HOST_DEVICE bool
operator==(const vec3int16& lhs, const vec3int16& rhs)
{
    return lhs.x == rhs.x && lhs.y == rhs.y && lhs.z == rhs.z;
}

struct less
{
    inline STDGPU_HOST_DEVICE bool
    operator()(const vec3int16& lhs, const vec3int16& rhs) const
    {
        if (lhs.x < rhs.x)
        {
            return true;
        }
        if (lhs.x > rhs.x)
        {
            return false;
        }

        if (lhs.y < rhs.y)
        {
            return true;
        }
        if (lhs.y > rhs.y)
        {
            return false;
        }

        if (lhs.z < rhs.z)
        {
            return true;
        }
        if (lhs.z > rhs.z)
        {
            return false;
        }

        return true;
    }
};

struct vec_hash
{
    using is_transparent = void;

    inline STDGPU_HOST_DEVICE std::size_t
    operator()(const vec3int16& key) const
    {
        const std::size_t prime_x = static_cast<std::size_t>(73856093U);
        const std::size_t prime_y = static_cast<std::size_t>(19349669U);
        const std::size_t prime_z = static_cast<std::size_t>(83492791U);

        return (static_cast<std::size_t>(key.x) * prime_x) ^ (static_cast<std::size_t>(key.y) * prime_y) ^
               (static_cast<std::size_t>(key.z) * prime_z);
    }
};

inline STDGPU_HOST_DEVICE vec3int16
key_to_value(const vec3int16& key)
{
    return key;
}

inline STDGPU_HOST_DEVICE vec3int16
value_to_key(const vec3int16& key)
{
    return key;
}

#define STDGPU_UNORDERED_DATASTRUCTURE_BENCHMARK_CLASS stdgpu_unordered_set
#define STDGPU_UNORDERED_DATASTRUCTURE_TYPE stdgpu::unordered_set<vec3int16, vec_hash>
#define STDGPU_UNORDERED_DATASTRUCTURE_KEY2VALUE key_to_value
#define STDGPU_UNORDERED_DATASTRUCTURE_VALUE2KEY value_to_key

#include "unordered_datastructure.inc"