-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
19 changed files
with
148 additions
and
100 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
EmmyLua/CodeAnalysis/Compilation/Index/UniqueIndexStorage.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
using EmmyLua.CodeAnalysis.Document; | ||
|
||
namespace EmmyLua.CodeAnalysis.Compilation.Index; | ||
|
||
public class UniqueIndexStorage<TKey, TStubElement> where TKey : notnull | ||
{ | ||
record struct ElementIndex(LuaDocumentId DocumentId, TStubElement Element); | ||
|
||
private readonly Dictionary<TKey, ElementIndex> _indexMap = new(); | ||
|
||
public void Update(LuaDocumentId documentId, TKey key, TStubElement element) | ||
{ | ||
_indexMap[key] = new ElementIndex(documentId, element); | ||
} | ||
|
||
public void Remove(LuaDocumentId documentId) | ||
{ | ||
var waitRemove = new List<TKey>(); | ||
foreach (var (key, element) in _indexMap) | ||
{ | ||
if (element.DocumentId == documentId) | ||
{ | ||
waitRemove.Add(key); | ||
} | ||
} | ||
|
||
foreach (var key in waitRemove) | ||
{ | ||
_indexMap.Remove(key); | ||
} | ||
} | ||
|
||
public TStubElement? Query(TKey key) | ||
{ | ||
if (_indexMap.TryGetValue(key, out var element)) | ||
{ | ||
return element.Element; | ||
} | ||
|
||
return default; | ||
} | ||
|
||
public IEnumerable<TStubElement> QueryAll() => | ||
_indexMap.Values.Select(it => it.Element); | ||
|
||
public bool ContainsKey(TKey key) => _indexMap.ContainsKey(key); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.