Skip to content

Commit 2082922

Browse files
committed
добавлено свойство Колонки о принадлежности к индексу
1 parent c3d8fe2 commit 2082922

File tree

4 files changed

+28
-17
lines changed

4 files changed

+28
-17
lines changed

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

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,21 +18,31 @@ namespace OneScript.StandardLibrary.Collections.Indexes
1818
[ContextClass("ИндексКоллекции", "CollectionIndex")]
1919
public class CollectionIndex : AutoCollectionContext<CollectionIndex, IValue>
2020
{
21-
private readonly List<IValue> _fields = new List<IValue>();
21+
readonly List<IValue> _fields = new List<IValue>();
2222
private readonly IIndexCollectionSource _source;
2323

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

2727
public CollectionIndex(IIndexCollectionSource source, IEnumerable<IValue> fields)
2828
{
2929
_source = source;
30-
_fields.AddRange(fields);
30+
foreach (var value in _source)
31+
{
32+
ElementAdded(value);
33+
}
34+
35+
foreach (var field in fields)
36+
{
37+
if (field is ValueTable.ValueTableColumn column)
38+
column.IsIndexable = true;
39+
_fields.Add(field);
40+
}
3141
}
3242

3343
internal bool CanBeUsedFor(IEnumerable<IValue> searchFields)
3444
{
35-
return _fields.Any() && _fields.ToHashSet().IsSubsetOf(searchFields.ToHashSet());
45+
return _fields.Count>0 && _fields.ToHashSet().IsSubsetOf(searchFields);
3646
}
3747

3848
private CollectionIndexKey IndexKey(PropertyNameIndexAccessor source)
@@ -82,10 +92,7 @@ internal void ElementRemoved(PropertyNameIndexAccessor element)
8292
}
8393
}
8494

85-
internal void Clear()
86-
{
87-
_data.Clear();
88-
}
95+
internal void Clear() => _data.Clear();
8996

9097
internal void Rebuild()
9198
{

src/OneScript.StandardLibrary/Collections/ValueTable/CollectionIndexes.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ public CollectionIndexes(IIndexCollectionSource owner)
3232
public CollectionIndex Add(string columns)
3333
{
3434
var newIndex = new CollectionIndex(_owner, BuildFieldList(_owner, columns));
35-
newIndex.Rebuild();
3635
_indexes.Add(newIndex);
3736
return newIndex;
3837
}

src/OneScript.StandardLibrary/Collections/ValueTable/ValueTableColumn.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,18 @@ public class ValueTableColumn : AutoContext<ValueTableColumn>
2121
{
2222
private string _title;
2323
private string _name;
24-
private TypeDescription _valueType;
24+
private readonly TypeDescription _valueType;
2525
private readonly WeakReference _owner;
26-
private readonly int _id;
26+
27+
public bool IsIndexable { get; set; }
2728

28-
public ValueTableColumn(ValueTableColumnCollection owner, int id, string name, string title, TypeDescription type, int width)
29+
public ValueTableColumn(ValueTableColumnCollection owner, string name, string title, TypeDescription type, int width)
2930
{
3031
_name = name;
3132
_title = title;
3233
_valueType = type ?? new TypeDescription();
3334
Width = width;
34-
_id = id;
35+
IsIndexable = false;
3536

3637
_owner = new WeakReference(owner);
3738
}
@@ -65,7 +66,6 @@ public string Name
6566
_title = value;
6667

6768
_name = value;
68-
6969
}
7070
}
7171
/// <summary>

src/OneScript.StandardLibrary/Collections/ValueTable/ValueTableRow.cs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,14 @@ public void Set(IValue index, IValue value)
8989

9090
public void Set(ValueTableColumn column, IValue value)
9191
{
92-
_owner.Indexes.ElementRemoved(this);
93-
_data[column] = column.ValueType.AdjustValue(value);
94-
_owner.Indexes.ElementAdded(this);
92+
if (column.IsIndexable)
93+
{
94+
_owner.Indexes.ElementRemoved(this);
95+
_data[column] = column.ValueType.AdjustValue(value);
96+
_owner.Indexes.ElementAdded(this);
97+
}
98+
else
99+
_data[column] = column.ValueType.AdjustValue(value);
95100
}
96101

97102
public void OnOwnerColumnRemoval(ValueTableColumn column)

0 commit comments

Comments
 (0)