Skip to content

Commit 328647b

Browse files
committed
Fix templates to match verify
1 parent 2345d60 commit 328647b

393 files changed

Lines changed: 1850 additions & 1891 deletions

File tree

Some content is hidden

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

Src/FastData.Cli.Tests/CommandOutputs/cpp_-k UInt8_Files_Integers.input.verified.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#include <string_view>
1111

1212
class MyData final {
13-
public:
13+
public:
1414
[[nodiscard]]
1515
static constexpr bool contains(const uint8_t key) noexcept {
1616
if ((static_cast<uint8_t>(key) & 129) != 0)

Src/FastData.Cli.Tests/CommandOutputs/cpp_-s HashTable_Files_Strings.input.verified.txt

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,26 +13,25 @@ class MyData final {
1313
struct e {
1414
std::string_view key;
1515
uint64_t hash_code;
16-
17-
1816
constexpr e(const std::string_view key, const uint64_t hash_code) noexcept
1917
: key(key), hash_code(hash_code) {}
2018
};
19+
2120
inline static const std::array<e, 2> entries = {
22-
e(u8"test2", 0), e(u8"test1", 1)
21+
e(u8"test2", 0), e(u8"test1", 1ull)
2322
};
2423

2524
static constexpr uint64_t get_hash(const std::string_view value) noexcept
2625
{
27-
uint64_t hash = 352654597;
26+
uint64_t hash = 352654597;
2827

29-
for (unsigned char ch : value)
30-
hash = (((hash << 5) | (hash >> 27)) + hash) ^ static_cast<uint32_t>(ch);
28+
for (unsigned char ch : value)
29+
hash = (((hash << 5) | (hash >> 27)) + hash) ^ static_cast<uint32_t>(ch);
3130

32-
return 352654597 + (hash * 1566083941);
31+
return 352654597 + (hash * 1566083941);
3332
}
3433

35-
public:
34+
public:
3635
[[nodiscard]]
3736
static constexpr bool contains(const std::string_view key) noexcept {
3837
if (key.length() != 5u)

Src/FastData.Cli.Tests/CommandOutputs/cpp_Files_Strings.input.verified.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#include <string_view>
1111

1212
class MyData final {
13-
public:
13+
public:
1414
[[nodiscard]]
1515
static constexpr bool contains(const std::string_view key) noexcept {
1616
if (key.length() != 5u)

Src/FastData.Cli.Tests/CommandOutputs/csharp_-k UInt8_Files_Integers.input.verified.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ using System.Runtime.InteropServices;
1010

1111
internal static class MyData
1212
{
13-
1413
public static bool Contains(byte key)
1514
{
1615
if (((byte)key & 129) != 0)

Src/FastData.Cli.Tests/CommandOutputs/csharp_-s HashTable_Files_Strings.input.verified.txt

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,22 +16,20 @@ internal static class MyData
1616
internal string Key;
1717
internal sbyte Next;
1818
internal ulong HashCode;
19-
20-
internal E(string key, sbyte next, ulong hashCode )
19+
internal E(string key, sbyte next, ulong hashCode)
2120
{
2221
Key = key;
2322
Next = next;
2423
HashCode = hashCode;
25-
2624
}
2725
};
2826

2927
private static readonly sbyte[] _buckets = new sbyte[] {
3028
2, 0
31-
};
29+
};
3230

3331
private static readonly E[] _entries = {
34-
new E("test1", -1, 114), new E("test2", 0, 114)
32+
new E("test1", -1, 114ul), new E("test2", 0, 114ul)
3533
};
3634

3735

@@ -55,7 +53,7 @@ internal static class MyData
5553

5654
}
5755

58-
56+
5957
public static bool Contains(string key)
6058
{
6159
if (key.Length != 5u)

Src/FastData.Cli.Tests/CommandOutputs/csharp_Files_Strings.input.verified.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ using System.Runtime.InteropServices;
1010

1111
internal static class MyData
1212
{
13-
1413
public static bool Contains(string key)
1514
{
1615
if (key.Length != 5u)

Src/FastData.Cli.Tests/CommandOutputs/rust_-s HashTable_Files_Strings.input.verified.txt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,17 @@ pub struct MyData;
1212
pub struct e {
1313
pub key: &'static str,
1414
pub hash_code: u64,
15-
1615
}
16+
1717
impl e {
1818
pub const fn new (key: str, hash_code: u64) -> Self { Self { key, hash_code } }
1919
}
2020

21-
impl MyData {
2221

23-
const ENTRIES: [e; 2] = [
24-
e::new("test2", 0), e::new("test1", 1)
25-
];
22+
impl MyData {
23+
const ENTRIES: [e; 2] = [
24+
e::new("test2", 0), e::new("test1", 1)
25+
];
2626

2727
#[inline]
2828
unsafe fn get_hash(value: &str) -> u64 {

Src/FastData.Generator.CPlusPlus/CPlusPlusCodeGenerator.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ public override string Generate()
103103
ValueObjectDeclarations = GetObjectDeclarations<TValue>(),
104104
GetMethodModifier = constExpr => constExpr ? "static constexpr " : "static ",
105105
GetFieldModifier = constExpr => constExpr ? "static constexpr " : "inline static const ",
106-
GetValueTypeName = customType => customType ? ValueTypeName + "*" : ValueTypeName
106+
GetValueTypeName = () => typeof(TValue).IsPrimitive ? ValueTypeName : ValueTypeName + "*"
107107
}
108108
},
109109
{ "Context", context },
@@ -264,7 +264,7 @@ protected override string GetMethodHeader(MethodType methodType)
264264
sb.Append(base.GetMethodHeader(methodType));
265265

266266
if (TotalTrimLength != 0)
267-
sb.Append($" const auto {TrimmedKeyName} = {InputKeyName}.substr({TrimPrefix.Length.ToStringInvariant()}, {InputKeyName}.length() - {TotalTrimLength.ToStringInvariant()});");
267+
sb.Append($" const auto {TrimmedKeyName} = {InputKeyName}.substr({TrimPrefix.Length.ToStringInvariant()}, {InputKeyName}.length() - {TotalTrimLength.ToStringInvariant()});");
268268

269269
return sb.ToString();
270270
}

Src/FastData.Generator.CPlusPlus/Internal/Framework/CPlusPlusEarlyExitDef.cs

Lines changed: 57 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,12 @@ protected override string GetLengthBitmapEarlyExit(MethodType methodType, ulong[
1818
return bitSet.Length == 1
1919
? RenderWord(bitSet[0], methodType)
2020
: $$"""
21-
switch (key.length() >> 6)
22-
{
21+
switch (key.length() >> 6)
22+
{
2323
{{RenderCases()}}
24-
default:
25-
{{RenderExit(methodType)}}
26-
}
24+
default:
25+
{{RenderExit(methodType)}}
26+
}
2727
""";
2828

2929
string RenderCases()
@@ -33,9 +33,9 @@ string RenderCases()
3333
for (int i = 0; i < bitSet.Length; i++)
3434
{
3535
sb.Append($"""
36-
case {i.ToStringInvariant()}:
37-
{RenderWord(bitSet[i], methodType)}
38-
break;
36+
case {i.ToStringInvariant()}:
37+
{RenderWord(bitSet[i], methodType)}
38+
break;
3939
4040
""");
4141
}
@@ -46,8 +46,8 @@ string RenderCases()
4646

4747
protected override string GetValueEarlyExit<T>(MethodType methodType, T min, T max) =>
4848
$"""
49-
if ({(min.Equals(max) ? $"key != {map.ToValueLabel(max)}" : $"key < {map.ToValueLabel(min)} || key > {map.ToValueLabel(max)}")})
50-
{RenderExit(methodType)}
49+
if ({(min.Equals(max) ? $"key != {map.ToValueLabel(max)}" : $"key < {map.ToValueLabel(min)} || key > {map.ToValueLabel(max)}")})
50+
{RenderExit(methodType)}
5151
""";
5252

5353
protected override string GetValueBitMaskEarlyExit<T>(MethodType methodType, ulong mask)
@@ -58,8 +58,8 @@ protected override string GetValueBitMaskEarlyExit<T>(MethodType methodType, ulo
5858
string maskLiteral = map.ToValueLabel(maskValue, unsignedType);
5959

6060
return $"""
61-
if ((static_cast<{unsignedTypeName}>(key) & {maskLiteral}) != 0)
62-
{RenderExit(methodType)}
61+
if ((static_cast<{unsignedTypeName}>(key) & {maskLiteral}) != 0)
62+
{RenderExit(methodType)}
6363
""";
6464
}
6565

@@ -74,8 +74,8 @@ protected override string GetLengthEqualEarlyExit(MethodType methodType, uint le
7474
};
7575

7676
return $"""
77-
if (key.length() != {map.ToValueLabel(lengthValue)})
78-
{RenderExit(methodType)}
77+
if (key.length() != {map.ToValueLabel(lengthValue)})
78+
{RenderExit(methodType)}
7979
""";
8080
}
8181

@@ -104,9 +104,9 @@ protected override string GetLengthRangeEarlyExit(MethodType methodType, uint mi
104104
}
105105

106106
return $"""
107-
const size_t len = key.length();
108-
if (len < {map.ToValueLabel(minLen)} || len > {map.ToValueLabel(maxLen)})
109-
{RenderExit(methodType)}
107+
const size_t len = key.length();
108+
if (len < {map.ToValueLabel(minLen)} || len > {map.ToValueLabel(maxLen)})
109+
{RenderExit(methodType)}
110110
""";
111111
}
112112

@@ -115,8 +115,8 @@ protected override string GetLengthDivisorEarlyExit(MethodType methodType, uint
115115
Debug.Assert(byteDivisor > 1);
116116

117117
return $"""
118-
if (key.length() % {map.ToValueLabel(byteDivisor)} != 0)
119-
{RenderExit(methodType)}
118+
if (key.length() % {map.ToValueLabel(byteDivisor)} != 0)
119+
{RenderExit(methodType)}
120120
""";
121121
}
122122

@@ -131,69 +131,69 @@ protected override string GetStringBitMaskEarlyExit(MethodType methodType, ulong
131131
if (!ignoreCase)
132132
{
133133
return $"""
134-
uint64_t first = 0;
135-
std::memcpy(&first, key.data(), {byteCount});
134+
uint64_t first = 0;
135+
std::memcpy(&first, key.data(), {byteCount});
136136
137-
if ((first & {mask.ToStringInvariant()}ULL) != 0)
138-
{RenderExit(methodType)}
137+
if ((first & {mask.ToStringInvariant()}ULL) != 0)
138+
{RenderExit(methodType)}
139139
""";
140140
}
141141

142142
StringBuilder sb = new StringBuilder();
143-
sb.Append(" uint64_t first = 0;");
143+
sb.Append(" uint64_t first = 0;");
144144

145145
for (int i = 0; i < byteCount; i++)
146146
{
147147
sb.Append($"""
148-
uint32_t c{i} = static_cast<uint32_t>(key[{i}]);
149-
c{i} = to_lower_ascii(c{i});
150-
first |= static_cast<uint64_t>(c{i}) << {i * 8};
148+
uint32_t c{i} = static_cast<uint32_t>(key[{i}]);
149+
c{i} = to_lower_ascii(c{i});
150+
first |= static_cast<uint64_t>(c{i}) << {i * 8};
151151
""");
152152
}
153153

154154
sb.Append($"""
155155
156-
if ((first & {mask.ToStringInvariant()}ULL) != 0)
157-
{RenderExit(methodType)}
156+
if ((first & {mask.ToStringInvariant()}ULL) != 0)
157+
{RenderExit(methodType)}
158158
""");
159159
return sb.ToString();
160160
}
161161

162162
protected override string GetCharRangeEarlyExit(MethodType methodType, CharPosition position, char min, char max, bool ignoreCase, GeneratorEncoding encoding) =>
163163
$"""
164-
uint32_t valueChar = {(position == CharPosition.First ?
165-
ignoreCase ? "to_lower_ascii(static_cast<uint32_t>(key.front()))" : "static_cast<uint32_t>(key.front())" :
166-
ignoreCase ? "to_lower_ascii(static_cast<uint32_t>(key.back()))" : "static_cast<uint32_t>(key.back())")};
167-
if (valueChar < {map.ToValueLabel((uint)min)} || valueChar > {map.ToValueLabel((uint)max)})
168-
{RenderExit(methodType)}
164+
uint32_t valueChar = {(position == CharPosition.First ?
165+
ignoreCase ? "to_lower_ascii(static_cast<uint32_t>(key.front()))" : "static_cast<uint32_t>(key.front())" :
166+
ignoreCase ? "to_lower_ascii(static_cast<uint32_t>(key.back()))" : "static_cast<uint32_t>(key.back())")};
167+
if (valueChar < {map.ToValueLabel((uint)min)} || valueChar > {map.ToValueLabel((uint)max)})
168+
{RenderExit(methodType)}
169169
""";
170170

171171
protected override string GetCharEqualsEarlyExit(MethodType methodType, CharPosition position, char value, bool ignoreCase, GeneratorEncoding encoding) =>
172172
$"""
173-
uint32_t valueChar = {(position == CharPosition.First ?
174-
ignoreCase ? "to_lower_ascii(static_cast<uint32_t>(key.front()))" : "static_cast<uint32_t>(key.front())" :
175-
ignoreCase ? "to_lower_ascii(static_cast<uint32_t>(key.back()))" : "static_cast<uint32_t>(key.back())")};
176-
if (valueChar != {map.ToValueLabel((uint)value)})
177-
{RenderExit(methodType)}
173+
uint32_t valueChar = {(position == CharPosition.First ?
174+
ignoreCase ? "to_lower_ascii(static_cast<uint32_t>(key.front()))" : "static_cast<uint32_t>(key.front())" :
175+
ignoreCase ? "to_lower_ascii(static_cast<uint32_t>(key.back()))" : "static_cast<uint32_t>(key.back())")};
176+
if (valueChar != {map.ToValueLabel((uint)value)})
177+
{RenderExit(methodType)}
178178
""";
179179

180180
protected override string GetCharBitmapEarlyExit(MethodType methodType, CharPosition position, ulong low, ulong high, bool ignoreCase, GeneratorEncoding encoding) =>
181181
$$"""
182-
uint32_t valueChar = {{(position == CharPosition.First ?
183-
ignoreCase ? "to_lower_ascii(static_cast<uint32_t>(key.front()))" : "static_cast<uint32_t>(key.front())" :
184-
ignoreCase ? "to_lower_ascii(static_cast<uint32_t>(key.back()))" : "static_cast<uint32_t>(key.back())")}};
185-
if (valueChar > 0x7F)
182+
uint32_t valueChar = {{(position == CharPosition.First ?
183+
ignoreCase ? "to_lower_ascii(static_cast<uint32_t>(key.front()))" : "static_cast<uint32_t>(key.front())" :
184+
ignoreCase ? "to_lower_ascii(static_cast<uint32_t>(key.back()))" : "static_cast<uint32_t>(key.back())")}};
185+
if (valueChar > 0x7F)
186+
{{RenderExit(methodType)}}
187+
if (valueChar < 64)
188+
{
189+
if (((1ULL << valueChar) & {{low.ToStringInvariant()}}ULL) == 0)
186190
{{RenderExit(methodType)}}
187-
if (valueChar < 64)
188-
{
189-
if (((1ULL << valueChar) & {{low.ToStringInvariant()}}ULL) == 0)
190-
{{RenderExit(methodType)}}
191-
}
192-
else
193-
{
194-
if (((1ULL << (valueChar - 64)) & {{high.ToStringInvariant()}}ULL) == 0)
195-
{{RenderExit(methodType)}}
196-
}
191+
}
192+
else
193+
{
194+
if (((1ULL << (valueChar - 64)) & {{high.ToStringInvariant()}}ULL) == 0)
195+
{{RenderExit(methodType)}}
196+
}
197197
""";
198198

199199
protected override string GetStringPrefixSuffixEarlyExit(MethodType methodType, string prefix, string suffix, bool ignoreCase)
@@ -208,15 +208,15 @@ protected override string GetStringPrefixSuffixEarlyExit(MethodType methodType,
208208
condition = suffix.Length == 0 ? prefixCheck : $"{prefixCheck} && {suffixCheck}";
209209

210210
return $"""
211-
if (!({condition}))
212-
{RenderExit(methodType)}
211+
if (!({condition}))
212+
{RenderExit(methodType)}
213213
""";
214214
}
215215

216216
private static string RenderWord(ulong word, MethodType methodType) =>
217217
$"""
218-
if (({word.ToStringInvariant()}ULL & (1ULL << ((key.length() - 1) & 63))) == 0)
219-
{RenderExit(methodType)}
218+
if (({word.ToStringInvariant()}ULL & (1ULL << ((key.length() - 1) & 63))) == 0)
219+
{RenderExit(methodType)}
220220
""";
221221

222222
private static string RenderExit(MethodType methodType) => methodType == MethodType.TryLookup

0 commit comments

Comments
 (0)