internal Caches() { var units = GetUnits(); foreach (var unit in units) { this.symbolUnitMap.Add(unit.Symbol, unit); var pos = 0; if (SymbolAndPowerReader.TryRead(unit.Symbol, ref pos, out IReadOnlyList <SymbolAndPower> result)) { if (!WhiteSpaceReader.IsRestWhiteSpace(unit.Symbol, pos)) { throw new InvalidOperationException($"Failed splitting {((IUnit)unit).Symbol} into {nameof(SymbolAndPower)}"); } if (result.Count == 0) { throw new InvalidOperationException($"Did not find any parts in {unit.Symbol}"); } this.symbolPartsMap.Add(unit.Symbol, result); var sapSet = new ReadonlySet <SymbolAndPower>(result); this.unitPartsMap.TryAdd(sapSet, unit); } } }
public bool Equals(ReadonlySet <T> other) { if (ReferenceEquals(null, other)) { return(false); } if (ReferenceEquals(this, other)) { return(true); } return(this.source.SetEquals(other.source)); }
internal bool Equals(ReadonlySet <T> other) { if (other is null) { return(false); } if (ReferenceEquals(this, other)) { return(true); } return(this.source.SetEquals(other.source)); }
internal bool TryGetUnitForParts(IReadOnlyList <SymbolAndPower> symbolsAndPowers, out TUnit unit) { var set = new ReadonlySet <SymbolAndPower>(symbolsAndPowers); return(this.unitPartsMap.TryGet(set, out unit)); }