Skip to content

Commit 6767ad6

Browse files
committed
Add string encoding support in hashes
1 parent 991aa54 commit 6767ad6

File tree

110 files changed

+1440
-661
lines changed

Some content is hidden

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

110 files changed

+1440
-661
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,11 +216,12 @@ of different data structures, indexing, and comparison methods that are tailor-b
216216

217217
There are many benefits gained from generating data structures at compile time:
218218

219-
* Data as code means you can compile the data into your assembly
219+
* _Data as code_ means you can compile the data into your assembly
220220
* Enables otherwise time-consuming data analysis (e.g. zero runtime overhead)
221221
* No defensive copying of data (takes time and needs double the memory)
222222
* No virtual dispatching (virtual method calls & inheritance) and no unnecessary branching
223223
* Modulo operations are known constants and compilers optimize it to bitwise operations
224+
* Data can be stored in smaller data types (e.g. `byte` instead of `int`) in values permit it
224225

225226
### Data analysis
226227

Src/FastData.Benchmarks/Benchmarks/AnalyzerBenchmarks.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ namespace Genbox.FastData.Benchmarks.Benchmarks;
99
[MemoryDiagnoser]
1010
public class AnalyzerBenchmarks
1111
{
12-
private readonly GPerfAnalyzer<string> _analyzer;
12+
private readonly GPerfAnalyzer _analyzer;
1313
private readonly string[] _data;
1414

1515
public AnalyzerBenchmarks()
@@ -18,7 +18,7 @@ public AnalyzerBenchmarks()
1818
_data = Enumerable.Range(1, 100).Select(_ => TestHelper.GenerateRandomString(rng, 50)).ToArray();
1919

2020
StringProperties props = DataAnalyzer.GetStringProperties(_data);
21-
_analyzer = new GPerfAnalyzer<string>(_data.Length, props, new GPerfAnalyzerConfig(), new Simulator<string>(_data.Length), NullLogger<GPerfAnalyzer<string>>.Instance);
21+
_analyzer = new GPerfAnalyzer(_data.Length, props, new GPerfAnalyzerConfig(), new Simulator(_data.Length, true), NullLogger<GPerfAnalyzer>.Instance);
2222
}
2323

2424
[Benchmark]

Src/FastData.Generator.CPlusPlus.Shared/CPlusPlusCompiler.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ private bool HasMSVC()
8484

8585
private int CompileMSVC(string src, string dst) =>
8686
RunProcess("cmd.exe", $"""
87-
/c ""{_path}" -arch=x86 && cl.exe "{src}" {(_release ? "/O2 /GL /GS-" : "/O1")} /std:c++17 /DNDEBUG /permissive- /MD /DBENCHMARK_STATIC_DEFINE /I "{_includesPath}" /Fe:"{dst}" "{_libsPath}\benchmark.lib" shlwapi.lib"
87+
/c ""{_path}" -arch=x86 && cl.exe "{src}" {(_release ? "/O2 /GL /GS-" : "/O1")} /utf-8 /std:c++20 /DNDEBUG /permissive- /MD /DBENCHMARK_STATIC_DEFINE /I "{_includesPath}" /Fe:"{dst}" "{_libsPath}\benchmark.lib" shlwapi.lib"
8888
""");
8989

9090
public string Compile(string fileId, string source)

Src/FastData.Generator.CPlusPlus.Tests/VectorTests.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@ await Verify(spec.Source)
3636
int main(int argc, char* argv[])
3737
{
3838
{{FormatList(data.Values, x => $"""
39-
if (!{spec.Identifier}::contains({helper.ToValueLabel(x)}))
40-
return false;
41-
""", "\n")}}
39+
if (!{spec.Identifier}::contains({helper.ToValueLabel(x)}))
40+
return false;
41+
""", "\n")}}
4242
4343
return 1;
4444
}

Src/FastData.Generator.CPlusPlus.Tests/Verify/ArrayStructure_String_100.verified.txt

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,22 @@
88

99
class ArrayStructure_String_100 final
1010
{
11-
static constexpr std::array<std::string_view, 100> entries = {
12-
"0", "1", "2", "3", "4", "5", "6", "7", "8", "9",
13-
"10", "11", "12", "13", "14", "15", "16", "17", "18", "19",
14-
"20", "21", "22", "23", "24", "25", "26", "27", "28", "29",
15-
"30", "31", "32", "33", "34", "35", "36", "37", "38", "39",
16-
"40", "41", "42", "43", "44", "45", "46", "47", "48", "49",
17-
"50", "51", "52", "53", "54", "55", "56", "57", "58", "59",
18-
"60", "61", "62", "63", "64", "65", "66", "67", "68", "69",
19-
"70", "71", "72", "73", "74", "75", "76", "77", "78", "79",
20-
"80", "81", "82", "83", "84", "85", "86", "87", "88", "89",
21-
"90", "91", "92", "93", "94", "95", "96", "97", "98", "99"
11+
static constexpr std::array<std::u32string_view, 100> entries = {
12+
U"0", U"1", U"2", U"3", U"4", U"5", U"6", U"7", U"8", U"9",
13+
U"10", U"11", U"12", U"13", U"14", U"15", U"16", U"17", U"18", U"19",
14+
U"20", U"21", U"22", U"23", U"24", U"25", U"26", U"27", U"28", U"29",
15+
U"30", U"31", U"32", U"33", U"34", U"35", U"36", U"37", U"38", U"39",
16+
U"40", U"41", U"42", U"43", U"44", U"45", U"46", U"47", U"48", U"49",
17+
U"50", U"51", U"52", U"53", U"54", U"55", U"56", U"57", U"58", U"59",
18+
U"60", U"61", U"62", U"63", U"64", U"65", U"66", U"67", U"68", U"69",
19+
U"70", U"71", U"72", U"73", U"74", U"75", U"76", U"77", U"78", U"79",
20+
U"80", U"81", U"82", U"83", U"84", U"85", U"86", U"87", U"88", U"89",
21+
U"90", U"91", U"92", U"93", U"94", U"95", U"96", U"97", U"98", U"99"
2222
};
2323

2424
public:
2525
[[nodiscard]]
26-
static bool contains(const std::string_view value) noexcept
26+
static bool contains(const std::u32string_view value) noexcept
2727
{
2828
if (const size_t len = value.length(); len < 1u || len > 2u)
2929
return false;
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
// This file is auto-generated. Do not edit manually.
2+
// Structure: Array
3+
#pragma once
4+
#include <array>
5+
#include <cstdint>
6+
#include <limits>
7+
#include <string_view>
8+
9+
class ArrayStructure_String_13 final
10+
{
11+
static constexpr std::array<std::u32string_view, 13> entries = {
12+
U"æ", U"à", U"ä", U"ö", U"ü", U"ß", U"é", U"è", U"ê", U"ç",
13+
U"ñ", U"ø", U"å"
14+
};
15+
16+
public:
17+
[[nodiscard]]
18+
static bool contains(const std::u32string_view value) noexcept
19+
{
20+
if (value.length() != 1u)
21+
return false;
22+
23+
for (size_t i = 0; i < 13; i++)
24+
{
25+
if (entries[i] == value)
26+
return true;
27+
}
28+
return false;
29+
}
30+
31+
static constexpr size_t item_count = 13;
32+
static constexpr size_t min_length = 1;
33+
static constexpr size_t max_length = 1;
34+
35+
public:
36+
ArrayStructure_String_13() = delete;
37+
ArrayStructure_String_13(const ArrayStructure_String_13&) = delete;
38+
ArrayStructure_String_13& operator=(const ArrayStructure_String_13&) = delete;
39+
ArrayStructure_String_13(ArrayStructure_String_13&&) = delete;
40+
ArrayStructure_String_13& operator=(ArrayStructure_String_13&&) = delete;
41+
};

Src/FastData.Generator.CPlusPlus.Tests/Verify/ArrayStructure_String_3.verified.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@
88

99
class ArrayStructure_String_3 final
1010
{
11-
static constexpr std::array<std::string_view, 3> entries = {
12-
"a", "item", "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
11+
static constexpr std::array<std::u32string_view, 3> entries = {
12+
U"a", U"item", U"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
1313
};
1414

1515
public:
1616
[[nodiscard]]
17-
static bool contains(const std::string_view value) noexcept
17+
static bool contains(const std::u32string_view value) noexcept
1818
{
1919
if (const size_t len = value.length(); len < 1u || len > 255u)
2020
return false;

Src/FastData.Generator.CPlusPlus.Tests/Verify/BinarySearchStructure_String_100.verified.txt

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,22 @@
88

99
class BinarySearchStructure_String_100 final
1010
{
11-
static constexpr std::array<std::string_view, 100> entries = {
12-
"0", "1", "10", "11", "12", "13", "14", "15", "16", "17",
13-
"18", "19", "2", "20", "21", "22", "23", "24", "25", "26",
14-
"27", "28", "29", "3", "30", "31", "32", "33", "34", "35",
15-
"36", "37", "38", "39", "4", "40", "41", "42", "43", "44",
16-
"45", "46", "47", "48", "49", "5", "50", "51", "52", "53",
17-
"54", "55", "56", "57", "58", "59", "6", "60", "61", "62",
18-
"63", "64", "65", "66", "67", "68", "69", "7", "70", "71",
19-
"72", "73", "74", "75", "76", "77", "78", "79", "8", "80",
20-
"81", "82", "83", "84", "85", "86", "87", "88", "89", "9",
21-
"90", "91", "92", "93", "94", "95", "96", "97", "98", "99"
11+
static constexpr std::array<std::u32string_view, 100> entries = {
12+
U"0", U"1", U"10", U"11", U"12", U"13", U"14", U"15", U"16", U"17",
13+
U"18", U"19", U"2", U"20", U"21", U"22", U"23", U"24", U"25", U"26",
14+
U"27", U"28", U"29", U"3", U"30", U"31", U"32", U"33", U"34", U"35",
15+
U"36", U"37", U"38", U"39", U"4", U"40", U"41", U"42", U"43", U"44",
16+
U"45", U"46", U"47", U"48", U"49", U"5", U"50", U"51", U"52", U"53",
17+
U"54", U"55", U"56", U"57", U"58", U"59", U"6", U"60", U"61", U"62",
18+
U"63", U"64", U"65", U"66", U"67", U"68", U"69", U"7", U"70", U"71",
19+
U"72", U"73", U"74", U"75", U"76", U"77", U"78", U"79", U"8", U"80",
20+
U"81", U"82", U"83", U"84", U"85", U"86", U"87", U"88", U"89", U"9",
21+
U"90", U"91", U"92", U"93", U"94", U"95", U"96", U"97", U"98", U"99"
2222
};
2323

2424
public:
2525
[[nodiscard]]
26-
static bool contains(const std::string_view value) noexcept
26+
static bool contains(const std::u32string_view value) noexcept
2727
{
2828
if (const size_t len = value.length(); len < 1u || len > 2u)
2929
return false;
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
// This file is auto-generated. Do not edit manually.
2+
// Structure: BinarySearch
3+
#pragma once
4+
#include <array>
5+
#include <cstdint>
6+
#include <limits>
7+
#include <string_view>
8+
9+
class BinarySearchStructure_String_13 final
10+
{
11+
static constexpr std::array<std::u32string_view, 13> entries = {
12+
U"ß", U"à", U"ä", U"å", U"æ", U"ç", U"è", U"é", U"ê", U"ñ",
13+
U"ö", U"ø", U"ü"
14+
};
15+
16+
public:
17+
[[nodiscard]]
18+
static bool contains(const std::u32string_view value) noexcept
19+
{
20+
if (value.length() != 1u)
21+
return false;
22+
23+
size_t lo = 0;
24+
size_t hi = 12;
25+
while (lo <= hi)
26+
{
27+
const size_t mid = lo + ((hi - lo) >> 1);
28+
29+
if (entries[mid] == value)
30+
return true;
31+
32+
if (entries[mid] < value)
33+
lo = mid + 1;
34+
else
35+
hi = mid - 1;
36+
}
37+
38+
return false;
39+
}
40+
41+
static constexpr size_t item_count = 13;
42+
static constexpr size_t min_length = 1;
43+
static constexpr size_t max_length = 1;
44+
45+
public:
46+
BinarySearchStructure_String_13() = delete;
47+
BinarySearchStructure_String_13(const BinarySearchStructure_String_13&) = delete;
48+
BinarySearchStructure_String_13& operator=(const BinarySearchStructure_String_13&) = delete;
49+
BinarySearchStructure_String_13(BinarySearchStructure_String_13&&) = delete;
50+
BinarySearchStructure_String_13& operator=(BinarySearchStructure_String_13&&) = delete;
51+
};

Src/FastData.Generator.CPlusPlus.Tests/Verify/BinarySearchStructure_String_3.verified.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@
88

99
class BinarySearchStructure_String_3 final
1010
{
11-
static constexpr std::array<std::string_view, 3> entries = {
12-
"a", "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "item"
11+
static constexpr std::array<std::u32string_view, 3> entries = {
12+
U"a", U"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", U"item"
1313
};
1414

1515
public:
1616
[[nodiscard]]
17-
static bool contains(const std::string_view value) noexcept
17+
static bool contains(const std::u32string_view value) noexcept
1818
{
1919
if (const size_t len = value.length(); len < 1u || len > 255u)
2020
return false;

0 commit comments

Comments
 (0)