Skip to content

Commit 77cf110

Browse files
committed
Add key/value and complex object support to Rust
1 parent 717eed2 commit 77cf110

File tree

85 files changed

+1280
-308
lines changed

Some content is hidden

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

85 files changed

+1280
-308
lines changed

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using Genbox.FastData.Generator.CPlusPlus.Enums;
2+
using Genbox.FastData.Generator.Enums;
23
using Genbox.FastData.Generator.Extensions;
34
using Genbox.FastData.Generator.Framework;
45
using Genbox.FastData.Generator.Framework.Definitions;
@@ -9,19 +10,19 @@ internal class CPlusPlusEarlyExitDef(TypeMap map, CPlusPlusOptions options) : Ea
910
{
1011
protected override bool IsEnabled => !options.HasFlag(CPlusPlusOptions.DisableEarlyExits);
1112

12-
protected override string GetMaskEarlyExit(ulong bitSet) =>
13+
protected override string GetMaskEarlyExit(MethodType methodType, ulong bitSet) =>
1314
$"""
1415
if (({bitSet}ULL & (1ULL << (key.length() - 1))) == 0)
1516
return false;
1617
""";
1718

18-
protected override string GetValueEarlyExits<T>(T min, T max) =>
19+
protected override string GetValueEarlyExits<T>(MethodType methodType, T min, T max) =>
1920
$"""
2021
if ({(min.Equals(max) ? $"key != {map.ToValueLabel(max)}" : $"key < {map.ToValueLabel(min)} || key > {map.ToValueLabel(max)}")})
2122
return false;
2223
""";
2324

24-
protected override string GetLengthEarlyExits(uint min, uint max, uint minByte, uint maxByte) =>
25+
protected override string GetLengthEarlyExits(MethodType methodType, uint min, uint max, uint minByte, uint maxByte) =>
2526
$"""
2627
if ({(min.Equals(max) ? $"key.length() != {map.ToValueLabel(max)}" : $"const size_t len = key.length(); len < {map.ToValueLabel(min)} || len > {map.ToValueLabel(max)}")})
2728
return false;

Src/FastData.Generator.CPlusPlus/Internal/Generators/ArrayCode.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public override string Generate()
2121
{{MethodAttribute}}
2222
{{MethodModifier}}bool contains(const {{KeyTypeName}} key){{PostMethodModifier}}
2323
{
24-
{{EarlyExits}}
24+
{{GetEarlyExits(MethodType.Contains)}}
2525
2626
for ({{ArraySizeType}} i = 0; i < {{ctx.Keys.Length.ToStringInvariant()}}; i++)
2727
{
@@ -34,7 +34,7 @@ public override string Generate()
3434

3535
if (ctx.Values != null)
3636
{
37-
shared.Add("classes", CodePlacement.Before, GetObjectDeclarations<TValue>());
37+
shared.Add(CodePlacement.Before, GetObjectDeclarations<TValue>());
3838

3939
sb.Append($$"""
4040
@@ -45,7 +45,7 @@ public override string Generate()
4545
{{MethodAttribute}}
4646
{{MethodModifier}}bool try_lookup(const {{KeyTypeName}} key, const {{ValueTypeName}}*& value){{PostMethodModifier}}
4747
{
48-
{{EarlyExits}}
48+
{{GetEarlyExits(MethodType.TryLookup)}}
4949
5050
for ({{ArraySizeType}} i = 0; i < {{ctx.Keys.Length.ToStringInvariant()}}; i++)
5151
{

Src/FastData.Generator.CPlusPlus/Internal/Generators/BinarySearchCode.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public override string Generate()
2121
{{MethodAttribute}}
2222
{{MethodModifier}}bool contains(const {{KeyTypeName}} key){{PostMethodModifier}}
2323
{
24-
{{EarlyExits}}
24+
{{GetEarlyExits(MethodType.Contains)}}
2525
2626
{{ArraySizeType}} lo = 0;
2727
{{ArraySizeType}} hi = {{(ctx.Keys.Length - 1).ToStringInvariant()}};
@@ -44,7 +44,7 @@ public override string Generate()
4444

4545
if (ctx.Values != null)
4646
{
47-
shared.Add("classes", CodePlacement.Before, GetObjectDeclarations<TValue>());
47+
shared.Add(CodePlacement.Before, GetObjectDeclarations<TValue>());
4848

4949
sb.Append($$"""
5050
@@ -55,7 +55,7 @@ public override string Generate()
5555
{{MethodAttribute}}
5656
{{MethodModifier}}bool try_lookup(const {{KeyTypeName}} key, const {{ValueTypeName}}*& value){{PostMethodModifier}}
5757
{
58-
{{EarlyExits}}
58+
{{GetEarlyExits(MethodType.TryLookup)}}
5959
6060
{{ArraySizeType}} lo = 0;
6161
{{ArraySizeType}} hi = {{(ctx.Keys.Length - 1).ToStringInvariant()}};

Src/FastData.Generator.CPlusPlus/Internal/Generators/ConditionalCode.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public override string Generate()
1717
{{MethodAttribute}}
1818
{{MethodModifier}}bool contains(const {{KeyTypeName}} key){{PostMethodModifier}}
1919
{
20-
{{EarlyExits}}
20+
{{GetEarlyExits(MethodType.Contains)}}
2121
2222
if ({{FormatList(ctx.Keys, x => GetEqualFunction("key", ToValueLabel(x)), " || ")}})
2323
return true;
@@ -28,7 +28,7 @@ public override string Generate()
2828

2929
if (ctx.Values != null)
3030
{
31-
shared.Add("classes", CodePlacement.Before, GetObjectDeclarations<TValue>());
31+
shared.Add(CodePlacement.Before, GetObjectDeclarations<TValue>());
3232

3333
sb.Append($$"""
3434
@@ -39,7 +39,7 @@ public override string Generate()
3939
{{MethodAttribute}}
4040
{{MethodModifier}}bool try_lookup(const {{KeyTypeName}} key, const {{ValueTypeName}}*& value){{PostMethodModifier}}
4141
{
42-
{{EarlyExits}}
42+
{{GetEarlyExits(MethodType.TryLookup)}}
4343
{{GenerateBranches()}}
4444
value = nullptr;
4545
return false;

Src/FastData.Generator.CPlusPlus/Internal/Generators/HashTableCode.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ struct e
3636
{{MethodAttribute}}
3737
{{MethodModifier}}bool contains(const {{KeyTypeName}} key){{PostMethodModifier}}
3838
{
39-
{{EarlyExits}}
39+
{{GetEarlyExits(MethodType.Contains)}}
4040
4141
const {{HashSizeType}} hash = get_hash(key);
4242
const {{ArraySizeType}} index = {{GetModFunction("hash", (ulong)ctx.Buckets.Length)}};
@@ -58,14 +58,14 @@ struct e
5858

5959
if (ctx.Values != null)
6060
{
61-
shared.Add("classes", CodePlacement.Before, GetObjectDeclarations<TValue>());
61+
shared.Add(CodePlacement.Before, GetObjectDeclarations<TValue>());
6262

6363
sb.Append($$"""
6464
6565
{{MethodAttribute}}
6666
{{MethodModifier}}bool try_lookup(const {{KeyTypeName}} key, const {{ValueTypeName}}*& value){{PostMethodModifier}}
6767
{
68-
{{EarlyExits}}
68+
{{GetEarlyExits(MethodType.TryLookup)}}
6969
7070
const {{HashSizeType}} hash = get_hash(key);
7171
const {{ArraySizeType}} index = {{GetModFunction("hash", (ulong)ctx.Buckets.Length)}};

Src/FastData.Generator.CPlusPlus/Internal/Generators/HashTablePerfectCode.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ constexpr e(const {{KeyTypeName}} key{{(ctx.StoreHashCode ? $", const {HashSizeT
5151
{{MethodAttribute}}
5252
{{MethodModifier}}bool contains(const {{KeyTypeName}} key){{PostMethodModifier}}
5353
{
54-
{{EarlyExits}}
54+
{{GetEarlyExits(MethodType.Contains)}}
5555
5656
const {{HashSizeType}} hash = get_hash(key);
5757
const {{ArraySizeType}} index = {{GetModFunction("hash", (ulong)ctx.Data.Length)}};
@@ -63,14 +63,14 @@ constexpr e(const {{KeyTypeName}} key{{(ctx.StoreHashCode ? $", const {HashSizeT
6363

6464
if (ctx.Values != null)
6565
{
66-
shared.Add("classes", CodePlacement.Before, GetObjectDeclarations<TValue>());
66+
shared.Add(CodePlacement.Before, GetObjectDeclarations<TValue>());
6767

6868
sb.Append($$"""
6969
7070
{{MethodAttribute}}
7171
{{MethodModifier}}bool try_lookup(const {{KeyTypeName}} key, const {{ValueTypeName}}*& value){{PostMethodModifier}}
7272
{
73-
{{EarlyExits}}
73+
{{GetEarlyExits(MethodType.TryLookup)}}
7474
7575
const {{HashSizeType}} hash = get_hash(key);
7676
const {{ArraySizeType}} index = {{GetModFunction("hash", (ulong)ctx.Data.Length)}};

Src/FastData.Generator.CPlusPlus/Internal/Generators/KeyLengthCode.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public override string Generate()
1313

1414
if (ctx.Values != null)
1515
{
16-
shared.Add("classes", CodePlacement.Before, GetObjectDeclarations<TValue>());
16+
shared.Add(CodePlacement.Before, GetObjectDeclarations<TValue>());
1717

1818
sb.Append($$"""
1919
{{FieldModifier}}std::array<int32_t, {{ctx.ValueOffsets.Length}}> offsets = {
@@ -39,7 +39,7 @@ public override string Generate()
3939
{{MethodAttribute}}
4040
{{MethodModifier}}bool contains(const {{KeyTypeName}} key){{PostMethodModifier}}
4141
{
42-
{{EarlyExits}}
42+
{{GetEarlyExits(MethodType.Contains)}}
4343
4444
return {{GetEqualFunction("key", $"keys[key.length() - {ctx.MinLength.ToStringInvariant()}]")}};
4545
}
@@ -52,7 +52,7 @@ public override string Generate()
5252
{{MethodAttribute}}
5353
{{MethodModifier}}bool try_lookup(const {{KeyTypeName}} key, const {{ValueTypeName}}*& value){{PostMethodModifier}}
5454
{
55-
{{EarlyExits}}
55+
{{GetEarlyExits(MethodType.TryLookup)}}
5656
5757
size_t idx = key.length() - {{ctx.MinLength.ToStringInvariant()}};
5858
if ({{GetEqualFunction("key", "keys[idx]")}})

Src/FastData.Generator.CPlusPlus/Internal/Generators/SingleValueCode.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public override string Generate()
2121

2222
if (ctx.Values != null)
2323
{
24-
shared.Add("classes", CodePlacement.Before, GetObjectDeclarations<TValue>());
24+
shared.Add(CodePlacement.Before, GetObjectDeclarations<TValue>());
2525

2626
sb.Append($$"""
2727

Src/FastData.Generator.CSharp/Internal/Framework/CSharpEarlyExitDef.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using Genbox.FastData.Generator.CSharp.Enums;
2+
using Genbox.FastData.Generator.Enums;
23
using Genbox.FastData.Generator.Extensions;
34
using Genbox.FastData.Generator.Framework;
45
using Genbox.FastData.Generator.Framework.Definitions;
@@ -9,19 +10,19 @@ internal class CSharpEarlyExitDef(TypeMap map, CSharpOptions options) : EarlyExi
910
{
1011
protected override bool IsEnabled => !options.HasFlag(CSharpOptions.DisableEarlyExits);
1112

12-
protected override string GetMaskEarlyExit(ulong bitSet) =>
13+
protected override string GetMaskEarlyExit(MethodType methodType, ulong bitSet) =>
1314
$"""
1415
if (({bitSet}UL & (1UL << (key.Length - 1))) == 0)
1516
return false;
1617
""";
1718

18-
protected override string GetValueEarlyExits<T>(T min, T max) =>
19+
protected override string GetValueEarlyExits<T>(MethodType methodType, T min, T max) =>
1920
$"""
2021
if ({(min.Equals(max) ? $"key != {map.ToValueLabel(max)}" : $"key < {map.ToValueLabel(min)} || key > {map.ToValueLabel(max)}")})
2122
return false;
2223
""";
2324

24-
protected override string GetLengthEarlyExits(uint min, uint max, uint minByte, uint maxByte) =>
25+
protected override string GetLengthEarlyExits(MethodType methodType, uint min, uint max, uint minByte, uint maxByte) =>
2526
$"""
2627
if ({(min.Equals(max) ? $"key.Length != {map.ToValueLabel(max)}" : $"key.Length < {map.ToValueLabel(min)} || key.Length > {map.ToValueLabel(max)}")})
2728
return false;

Src/FastData.Generator.CSharp/Internal/Generators/ArrayCode.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public override string Generate()
1919
{{MethodAttribute}}
2020
{{MethodModifier}}bool Contains({{KeyTypeName}} key)
2121
{
22-
{{EarlyExits}}
22+
{{GetEarlyExits(MethodType.Contains)}}
2323
2424
for (int i = 0; i < {{ctx.Keys.Length.ToStringInvariant()}}; i++)
2525
{
@@ -32,7 +32,7 @@ public override string Generate()
3232

3333
if (ctx.Values != null)
3434
{
35-
shared.Add("classes", CodePlacement.Before, GetObjectDeclarations<TValue>());
35+
shared.Add(CodePlacement.Before, GetObjectDeclarations<TValue>());
3636

3737
sb.Append($$"""
3838
@@ -45,7 +45,7 @@ public override string Generate()
4545
{
4646
value = default;
4747
48-
{{EarlyExits}}
48+
{{GetEarlyExits(MethodType.TryLookup)}}
4949
5050
for ({{ArraySizeType}} i = 0; i < {{ctx.Keys.Length.ToStringInvariant()}}; i++)
5151
{

0 commit comments

Comments
 (0)