Skip to content

Commit 75cfca9

Browse files
committed
Use (string Command, TValue Value)
1 parent 0dcd30c commit 75cfca9

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

CSharpMath/Structures/Dictionary.cs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,11 @@ public void Add<TCollection>(TCollection keys, Func<TKey, TValue> valueFunc) whe
4040
foreach (var key in keys) Add(key, valueFunc(key));
4141
}
4242
}
43-
class DescendingStringLengthIComparer<TValue> : IComparer<Tuple<string, TValue>> {
44-
int IComparer<Tuple<string, TValue>>.Compare(Tuple<string, TValue> x, Tuple<string, TValue> y) {
45-
if (x.Item1.Length > y.Item1.Length) { return -1; }
46-
else if (x.Item1.Length < y.Item1.Length) { return 1; }
47-
else { return string.CompareOrdinal(x.Item1, y.Item1); }
43+
class DescendingStringLengthIComparer<TValue> : IComparer<(string NonCommand, TValue Value)> {
44+
public int Compare((string NonCommand, TValue Value) x, (string NonCommand, TValue Value) y) {
45+
if (x.NonCommand.Length > y.NonCommand.Length) { return -1; }
46+
else if (x.NonCommand.Length < y.NonCommand.Length) { return 1; }
47+
else { return string.CompareOrdinal(x.NonCommand, y.NonCommand); }
4848
}
4949
}
5050

@@ -69,18 +69,18 @@ public LaTeXCommandDictionary(DefaultDelegate defaultParser,
6969
if (SplitCommand(key.AsSpan()) != key.Length - 1)
7070
commands.Add(key, value);
7171
else throw new ArgumentException("Key is unreachable: " + key, nameof(key));
72-
else nonCommands.Add(new Tuple<string, TValue>(key, value));
72+
else nonCommands.Add((key, value));
7373
};
7474
}
7575
readonly DefaultDelegate defaultParser;
7676
readonly DefaultDelegate defaultParserForCommands;
7777

78-
readonly SortedSet<Tuple<string, TValue>> nonCommands =
79-
new SortedSet<Tuple<string, TValue>>(new DescendingStringLengthIComparer<TValue>());
78+
readonly SortedSet<(string NonCommand, TValue Value)> nonCommands =
79+
new SortedSet<(string NonCommand, TValue Value)>(new DescendingStringLengthIComparer<TValue>());
8080
readonly Dictionary<string, TValue> commands = new Dictionary<string, TValue>();
8181

8282
public IEnumerator<KeyValuePair<string, TValue>> GetEnumerator() =>
83-
nonCommands.Select(t => new KeyValuePair<string, TValue>(t.Item1, t.Item2))
83+
nonCommands.Select(t => new KeyValuePair<string, TValue>(t.NonCommand, t.Value))
8484
.Concat(commands).GetEnumerator();
8585
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
8686

@@ -120,9 +120,9 @@ static int SplitCommand(ReadOnlySpan<char> chars) {
120120
return TryLookupNonCommand(chars);
121121
}
122122
Result<(TValue Result, int SplitIndex)> TryLookupNonCommand(ReadOnlySpan<char> chars) {
123-
foreach (Tuple<string,TValue> t in nonCommands) {
124-
if (chars.StartsWith(t.Item1.AsSpan(), StringComparison.Ordinal)) {
125-
return Result.Ok((t.Item2, t.Item1.Length)); }
123+
foreach ((string NonCommand, TValue Value) t in nonCommands) {
124+
if (chars.StartsWith(t.NonCommand.AsSpan(), StringComparison.Ordinal)) {
125+
return Result.Ok((t.Value, t.NonCommand.Length)); }
126126
}
127127
return defaultParser(chars);
128128
}

0 commit comments

Comments
 (0)