17 using System.Collections;
18 using System.Collections.Generic;
30 public static PositionGroupCollection Empty =>
new(
new Dictionary<PositionGroupKey, IPositionGroup>(),
new Dictionary<Symbol, HashSet<IPositionGroup>>());
35 public int Count => _groups.Count;
44 if (_hasNonDefaultGroups ==
null)
46 _hasNonDefaultGroups = _groups.Count == 0 || _groups.All(grp => grp.Key.IsDefaultGroup);
49 return _hasNonDefaultGroups.Value;
53 private bool? _hasNonDefaultGroups;
54 private readonly Dictionary<PositionGroupKey, IPositionGroup> _groups;
55 private readonly Dictionary<Symbol, HashSet<IPositionGroup>> _groupsBySymbol;
63 Dictionary<PositionGroupKey, IPositionGroup> groups,
64 Dictionary<
Symbol, HashSet<IPositionGroup>> groupsBySymbol
68 _groupsBySymbol = groupsBySymbol;
78 _groupsBySymbol =
new();
79 foreach (var group
in groups)
92 foreach (var position
in group)
94 if (!_groupsBySymbol.TryGetValue(position.Symbol, out var groups))
96 _groupsBySymbol[position.Symbol] = groups =
new();
100 _groups[group.Key] = group;
112 return _groups.ContainsKey(key);
128 return new PositionGroup(key, 0m, key.CreateEmptyPositions());
143 return _groups.TryGetValue(key, out group);
154 HashSet<IPositionGroup> list;
155 if (_groupsBySymbol.TryGetValue(symbol, out list) && list?.Count > 0)
180 foreach (var positionGroup
in other)
182 result = result.
Add(positionGroup);
192 return _groups.Values.GetEnumerator();
197 IEnumerator IEnumerable.GetEnumerator()