Skip to content

Commit 883454e

Browse files
committed
Add experimental compact hashset
1 parent f400d32 commit 883454e

File tree

59 files changed

+3766
-4
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+3766
-4
lines changed
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
// This file is auto-generated. Do not edit manually.
2+
// Structure: Auto (HashTableCompact)
3+
#pragma once
4+
#include <array>
5+
#include <cstdint>
6+
#include <limits>
7+
#include <string_view>
8+
9+
class HashTableCompactStructure_Byte_3 final {
10+
struct e {
11+
uint8_t key;
12+
13+
14+
e(const uint8_t key)
15+
: key(key) {}
16+
};
17+
18+
static constexpr std::array<uint8_t, 3> bucket_starts = {
19+
0, 2, 3
20+
};
21+
22+
static constexpr std::array<uint8_t, 3> bucket_counts = {
23+
2, 1, 0
24+
};
25+
26+
inline static const std::array<e, 3> entries = {
27+
e(0), e(std::numeric_limits<uint8_t>::max()), e(1)
28+
};
29+
30+
static constexpr uint64_t get_hash(const uint8_t value) noexcept
31+
{
32+
return static_cast<uint64_t>(value);
33+
}
34+
35+
public:
36+
[[nodiscard]]
37+
static constexpr bool contains(const uint8_t key) noexcept {
38+
if (key < 0 || key > std::numeric_limits<uint8_t>::max())
39+
return false;
40+
41+
const uint64_t hash = get_hash(key);
42+
const size_t index = hash % 3;
43+
const size_t start = static_cast<size_t>(bucket_starts[index]);
44+
const size_t count = static_cast<size_t>(bucket_counts[index]);
45+
const size_t end = start + count;
46+
47+
for (size_t i = start; i < end; i++) {
48+
const auto& entry = entries[i];
49+
50+
if (entry.key == key)
51+
return true;
52+
}
53+
54+
return false;
55+
}
56+
57+
static constexpr size_t item_count = 3;
58+
static constexpr uint8_t min_key = 0;
59+
static constexpr uint8_t max_key = std::numeric_limits<uint8_t>::max();
60+
};
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
// This file is auto-generated. Do not edit manually.
2+
// Structure: Auto (HashTableCompact)
3+
#pragma once
4+
#include <array>
5+
#include <cstdint>
6+
#include <limits>
7+
#include <string_view>
8+
9+
class HashTableCompactStructure_Char_3 final {
10+
struct e {
11+
char key;
12+
13+
14+
e(const char key)
15+
: key(key) {}
16+
};
17+
18+
static constexpr std::array<uint8_t, 3> bucket_starts = {
19+
0, 1, 3
20+
};
21+
22+
static constexpr std::array<uint8_t, 3> bucket_counts = {
23+
1, 2, 0
24+
};
25+
26+
inline static const std::array<e, 3> entries = {
27+
e(0), e(97), e(127)
28+
};
29+
30+
static constexpr uint64_t get_hash(const char value) noexcept
31+
{
32+
return static_cast<uint64_t>(value);
33+
}
34+
35+
public:
36+
[[nodiscard]]
37+
static constexpr bool contains(const char key) noexcept {
38+
if (key < 0 || key > 127)
39+
return false;
40+
41+
const uint64_t hash = get_hash(key);
42+
const size_t index = hash % 3;
43+
const size_t start = static_cast<size_t>(bucket_starts[index]);
44+
const size_t count = static_cast<size_t>(bucket_counts[index]);
45+
const size_t end = start + count;
46+
47+
for (size_t i = start; i < end; i++) {
48+
const auto& entry = entries[i];
49+
50+
if (entry.key == key)
51+
return true;
52+
}
53+
54+
return false;
55+
}
56+
57+
static constexpr size_t item_count = 3;
58+
static constexpr char min_key = 0;
59+
static constexpr char max_key = 127;
60+
};
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
// This file is auto-generated. Do not edit manually.
2+
// Structure: Auto (HashTableCompact)
3+
#pragma once
4+
#include <array>
5+
#include <cstdint>
6+
#include <limits>
7+
#include <string_view>
8+
9+
class HashTableCompactStructure_Double_4 final {
10+
struct e {
11+
double key;
12+
uint64_t hash_code;
13+
14+
e(const double key, const uint64_t hash_code)
15+
: key(key), hash_code(hash_code) {}
16+
};
17+
18+
static constexpr std::array<uint8_t, 4> bucket_starts = {
19+
0, 2, 2, 2
20+
};
21+
22+
static constexpr std::array<uint8_t, 4> bucket_counts = {
23+
2, 0, 0, 2
24+
};
25+
26+
inline static const std::array<e, 4> entries = {
27+
e(0.0, 0), e(1.0, 4607182418800017408), e(std::numeric_limits<double>::lowest(), 18442240474082181119), e(std::numeric_limits<double>::max(), 9218868437227405311)
28+
};
29+
30+
static uint64_t get_hash(const double value) noexcept
31+
{
32+
uint64_t bits;
33+
std::memcpy(&bits, &value, sizeof(bits));
34+
if (((bits - 1) & ~0x8000000000000000ull) >= 0x7FF0000000000000ull)
35+
bits &= 0x7FF0000000000000ull;
36+
return bits;
37+
}
38+
39+
public:
40+
[[nodiscard]]
41+
static constexpr bool contains(const double key) noexcept {
42+
if (key < std::numeric_limits<double>::lowest() || key > std::numeric_limits<double>::max())
43+
return false;
44+
45+
const uint64_t hash = get_hash(key);
46+
const size_t index = hash % 4;
47+
const size_t start = static_cast<size_t>(bucket_starts[index]);
48+
const size_t count = static_cast<size_t>(bucket_counts[index]);
49+
const size_t end = start + count;
50+
51+
for (size_t i = start; i < end; i++) {
52+
const auto& entry = entries[i];
53+
54+
if (entry.hash_code == hash && entry.key == key)
55+
return true;
56+
}
57+
58+
return false;
59+
}
60+
61+
static constexpr size_t item_count = 4;
62+
static constexpr double min_key = std::numeric_limits<double>::lowest();
63+
static constexpr double max_key = std::numeric_limits<double>::max();
64+
};
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
// This file is auto-generated. Do not edit manually.
2+
// Structure: Auto (HashTableCompact)
3+
#pragma once
4+
#include <array>
5+
#include <cstdint>
6+
#include <limits>
7+
#include <string_view>
8+
9+
class HashTableCompactStructure_Int16_5 final {
10+
struct e {
11+
int16_t key;
12+
13+
14+
e(const int16_t key)
15+
: key(key) {}
16+
};
17+
18+
static constexpr std::array<uint8_t, 5> bucket_starts = {
19+
0, 2, 3, 4, 5
20+
};
21+
22+
static constexpr std::array<uint8_t, 5> bucket_counts = {
23+
2, 1, 1, 1, 0
24+
};
25+
26+
inline static const std::array<e, 5> entries = {
27+
e(-1), e(0), e(1), e(std::numeric_limits<int16_t>::max()), e(std::numeric_limits<int16_t>::lowest())
28+
};
29+
30+
static constexpr uint64_t get_hash(const int16_t value) noexcept
31+
{
32+
return static_cast<uint64_t>(value);
33+
}
34+
35+
public:
36+
[[nodiscard]]
37+
static constexpr bool contains(const int16_t key) noexcept {
38+
if (key < std::numeric_limits<int16_t>::lowest() || key > std::numeric_limits<int16_t>::max())
39+
return false;
40+
41+
const uint64_t hash = get_hash(key);
42+
const size_t index = hash % 5;
43+
const size_t start = static_cast<size_t>(bucket_starts[index]);
44+
const size_t count = static_cast<size_t>(bucket_counts[index]);
45+
const size_t end = start + count;
46+
47+
for (size_t i = start; i < end; i++) {
48+
const auto& entry = entries[i];
49+
50+
if (entry.key == key)
51+
return true;
52+
}
53+
54+
return false;
55+
}
56+
57+
static constexpr size_t item_count = 5;
58+
static constexpr int16_t min_key = std::numeric_limits<int16_t>::lowest();
59+
static constexpr int16_t max_key = std::numeric_limits<int16_t>::max();
60+
};
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
// This file is auto-generated. Do not edit manually.
2+
// Structure: Auto (HashTableCompact)
3+
#pragma once
4+
#include <array>
5+
#include <cstdint>
6+
#include <limits>
7+
#include <string_view>
8+
9+
class HashTableCompactStructure_Int32_100 final {
10+
struct e {
11+
int32_t key;
12+
13+
14+
e(const int32_t key)
15+
: key(key) {}
16+
};
17+
18+
static constexpr std::array<uint8_t, 100> bucket_starts = {
19+
0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
20+
10, 11, 12, 13, 14, 15, 16, 17, 18, 19,
21+
20, 21, 22, 23, 24, 25, 26, 27, 28, 29,
22+
30, 31, 32, 33, 34, 35, 36, 37, 38, 39,
23+
40, 41, 42, 43, 44, 45, 46, 47, 48, 49,
24+
50, 51, 52, 53, 54, 55, 56, 57, 58, 59,
25+
60, 61, 62, 63, 64, 65, 66, 67, 68, 69,
26+
70, 71, 72, 73, 74, 75, 76, 77, 78, 79,
27+
80, 81, 82, 83, 84, 85, 86, 87, 88, 89,
28+
90, 91, 92, 93, 94, 95, 96, 97, 98, 99
29+
};
30+
31+
static constexpr std::array<uint8_t, 100> bucket_counts = {
32+
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
33+
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
34+
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
35+
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
36+
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
37+
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
38+
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
39+
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
40+
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
41+
1, 1, 1, 1, 1, 1, 1, 1, 1, 1
42+
};
43+
44+
inline static const std::array<e, 100> entries = {
45+
e(0), e(1), e(2), e(3), e(4), e(5), e(6), e(7), e(8), e(9),
46+
e(10), e(11), e(12), e(13), e(14), e(15), e(16), e(17), e(18), e(19),
47+
e(20), e(21), e(22), e(23), e(24), e(25), e(26), e(27), e(28), e(29),
48+
e(30), e(31), e(32), e(33), e(34), e(35), e(36), e(37), e(38), e(39),
49+
e(40), e(41), e(42), e(43), e(44), e(45), e(46), e(47), e(48), e(49),
50+
e(50), e(51), e(52), e(53), e(54), e(55), e(56), e(57), e(58), e(59),
51+
e(60), e(61), e(62), e(63), e(64), e(65), e(66), e(67), e(68), e(69),
52+
e(70), e(71), e(72), e(73), e(74), e(75), e(76), e(77), e(78), e(79),
53+
e(80), e(81), e(82), e(83), e(84), e(85), e(86), e(87), e(88), e(89),
54+
e(90), e(91), e(92), e(93), e(94), e(95), e(96), e(97), e(98), e(99)
55+
};
56+
57+
static constexpr uint64_t get_hash(const int32_t value) noexcept
58+
{
59+
return static_cast<uint64_t>(value);
60+
}
61+
62+
public:
63+
[[nodiscard]]
64+
static constexpr bool contains(const int32_t key) noexcept {
65+
if (key < 0 || key > 99)
66+
return false;
67+
68+
const uint64_t hash = get_hash(key);
69+
const size_t index = hash % 100;
70+
const size_t start = static_cast<size_t>(bucket_starts[index]);
71+
const size_t count = static_cast<size_t>(bucket_counts[index]);
72+
const size_t end = start + count;
73+
74+
for (size_t i = start; i < end; i++) {
75+
const auto& entry = entries[i];
76+
77+
if (entry.key == key)
78+
return true;
79+
}
80+
81+
return false;
82+
}
83+
84+
static constexpr size_t item_count = 100;
85+
static constexpr int32_t min_key = 0;
86+
static constexpr int32_t max_key = 99;
87+
};

0 commit comments

Comments
 (0)