mirror of
https://github.com/Flow-Launcher/Flow.Launcher.git
synced 2026-03-11 08:54:32 +00:00
34 lines
1.1 KiB
C#
34 lines
1.1 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
|
|
namespace Flow.Launcher.Infrastructure
|
|
{
|
|
public class TranslationMapping
|
|
{
|
|
private bool _isConstructed;
|
|
|
|
// Assuming one original item maps to multi translated items
|
|
// list[i] is the last translated index + 1 of original index i
|
|
private readonly List<int> _originalToTranslated = new();
|
|
|
|
public void AddNewIndex(int translatedIndex, int length)
|
|
{
|
|
if (_isConstructed)
|
|
throw new InvalidOperationException("Mapping shouldn't be changed after construction");
|
|
_originalToTranslated.Add(translatedIndex + length);
|
|
}
|
|
|
|
public int MapToOriginalIndex(int translatedIndex)
|
|
{
|
|
var searchResult = _originalToTranslated.BinarySearch(translatedIndex);
|
|
return searchResult >= 0 ? searchResult + 1 : ~searchResult;
|
|
}
|
|
|
|
public void EndConstruct()
|
|
{
|
|
if (_isConstructed)
|
|
throw new InvalidOperationException("Mapping has already been constructed");
|
|
_isConstructed = true;
|
|
}
|
|
}
|
|
}
|