Skip to content

Commit 1f458d3

Browse files
committed
Fix typos & Code quality
1 parent 5be732d commit 1f458d3

File tree

1 file changed

+22
-18
lines changed

1 file changed

+22
-18
lines changed

Flow.Launcher.Infrastructure/TranslationMapping.cs

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,73 +8,77 @@ public class TranslationMapping
88
{
99
private bool constructed;
1010

11-
private List<int> originalIndexs = new List<int>();
12-
private List<int> translatedIndexs = new List<int>();
11+
private readonly List<int> originalIndexes = new();
12+
private readonly List<int> translatedIndexes = new();
13+
1314
private int translatedLength = 0;
1415

1516
public void AddNewIndex(int originalIndex, int translatedIndex, int length)
1617
{
1718
if (constructed)
1819
throw new InvalidOperationException("Mapping shouldn't be changed after constructed");
1920

20-
originalIndexs.Add(originalIndex);
21-
translatedIndexs.Add(translatedIndex);
22-
translatedIndexs.Add(translatedIndex + length);
21+
originalIndexes.Add(originalIndex);
22+
translatedIndexes.Add(translatedIndex);
23+
translatedIndexes.Add(translatedIndex + length);
2324
translatedLength += length - 1;
2425
}
2526

2627
public int MapToOriginalIndex(int translatedIndex)
2728
{
28-
if (translatedIndex > translatedIndexs.Last())
29+
if (translatedIndex > translatedIndexes.Last())
2930
return translatedIndex - translatedLength - 1;
3031

3132
int lowerBound = 0;
32-
int upperBound = originalIndexs.Count - 1;
33+
int upperBound = originalIndexes.Count - 1;
3334

3435
int count = 0;
3536

3637
// Corner case handle
37-
if (translatedIndex < translatedIndexs[0])
38+
if (translatedIndex < translatedIndexes[0])
3839
return translatedIndex;
39-
if (translatedIndex > translatedIndexs.Last())
40+
41+
if (translatedIndex > translatedIndexes.Last())
4042
{
4143
int indexDef = 0;
42-
for (int k = 0; k < originalIndexs.Count; k++)
44+
for (int k = 0; k < originalIndexes.Count; k++)
4345
{
44-
indexDef += translatedIndexs[k * 2 + 1] - translatedIndexs[k * 2];
46+
indexDef += translatedIndexes[k * 2 + 1] - translatedIndexes[k * 2];
4547
}
4648

4749
return translatedIndex - indexDef - 1;
4850
}
4951

5052
// Binary Search with Range
51-
for (int i = originalIndexs.Count / 2;; count++)
53+
for (int i = originalIndexes.Count / 2;; count++)
5254
{
53-
if (translatedIndex < translatedIndexs[i * 2])
55+
if (translatedIndex < translatedIndexes[i * 2])
5456
{
5557
// move to lower middle
5658
upperBound = i;
5759
i = (i + lowerBound) / 2;
5860
}
59-
else if (translatedIndex > translatedIndexs[i * 2 + 1] - 1)
61+
else if (translatedIndex > translatedIndexes[i * 2 + 1] - 1)
6062
{
6163
lowerBound = i;
6264
// move to upper middle
6365
// due to floor of integer division, move one up on corner case
6466
i = (i + upperBound + 1) / 2;
6567
}
6668
else
67-
return originalIndexs[i];
69+
{
70+
return originalIndexes[i];
71+
}
6872

6973
if (upperBound - lowerBound <= 1 &&
70-
translatedIndex > translatedIndexs[lowerBound * 2 + 1] &&
71-
translatedIndex < translatedIndexs[upperBound * 2])
74+
translatedIndex > translatedIndexes[lowerBound * 2 + 1] &&
75+
translatedIndex < translatedIndexes[upperBound * 2])
7276
{
7377
int indexDef = 0;
7478

7579
for (int j = 0; j < upperBound; j++)
7680
{
77-
indexDef += translatedIndexs[j * 2 + 1] - translatedIndexs[j * 2];
81+
indexDef += translatedIndexes[j * 2 + 1] - translatedIndexes[j * 2];
7882
}
7983

8084
return translatedIndex - indexDef - 1;

0 commit comments

Comments
 (0)