Skip to content

Commit 2d713e4

Browse files
committed
Исправлено квадратичное замедление во вставке срок в индексированную таблицу
1 parent 35e6213 commit 2d713e4

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

src/OneScript.StandardLibrary/Collections/Indexes/CollectionIndex.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ public class CollectionIndex : AutoCollectionContext<CollectionIndex, IValue>
2121
private readonly List<IValue> _fields = new List<IValue>();
2222
private readonly IIndexCollectionSource _source;
2323

24-
private readonly IDictionary<CollectionIndexKey, IList<IValue>> _data =
25-
new Dictionary<CollectionIndexKey, IList<IValue>>();
24+
private readonly IDictionary<CollectionIndexKey, HashSet<IValue>> _data =
25+
new Dictionary<CollectionIndexKey, HashSet<IValue>>();
2626

2727
public CollectionIndex(IIndexCollectionSource source, IEnumerable<IValue> fields)
2828
{
@@ -48,7 +48,7 @@ public override string ToString()
4848
public IEnumerable<IValue> GetData(PropertyNameIndexAccessor searchCriteria)
4949
{
5050
var key = IndexKey(searchCriteria);
51-
return _data.TryGetValue(key, out var filteredData) ? filteredData : new List<IValue>();
51+
return _data.TryGetValue(key, out var filteredData) ? filteredData : Enumerable.Empty<IValue>();
5252
}
5353

5454
internal void FieldRemoved(IValue field)
@@ -63,22 +63,22 @@ internal void FieldRemoved(IValue field)
6363
internal void ElementAdded(PropertyNameIndexAccessor element)
6464
{
6565
var key = CollectionIndexKey.Extract(element, _fields);
66-
if (_data.TryGetValue(key, out var list))
66+
if (_data.TryGetValue(key, out var set))
6767
{
68-
list.Add(element);
68+
set.Add(element);
6969
}
7070
else
7171
{
72-
_data.Add(key, new List<IValue> { element});
72+
_data.Add(key, new HashSet<IValue> { element });
7373
}
7474
}
7575

7676
internal void ElementRemoved(PropertyNameIndexAccessor element)
7777
{
7878
var key = CollectionIndexKey.Extract(element, _fields);
79-
if (_data.TryGetValue(key, out var value))
79+
if (_data.TryGetValue(key, out var set))
8080
{
81-
value.Remove(element);
81+
set.Remove(element);
8282
}
8383
}
8484

0 commit comments

Comments
 (0)