public void LinearAddressTest() { var par1 = new Parameter("par1", 0, 4, 1); var par2 = new Parameter("par2", 0, 4, 1); var pars = new RefList <Parameter>(); pars.Add(par1); pars.Add(par2); //var pars = new Parameters(); pars.Ref(0).CurrentPosition = 1; pars.Ref(1).CurrentPosition = 0; Assert.AreEqual(5, pars.LinearAddress()); pars.Ref(1).CurrentPosition = 1; Assert.AreEqual(6, pars.LinearAddress()); pars.Ref(0).CurrentPosition = 4; pars.Ref(1).CurrentPosition = 3; Assert.AreEqual(23, pars.LinearAddress()); var pars2 = pars.SetPositionsFromLinearAddress(23); Assert.AreEqual(4, pars2[0].CurrentPosition); Assert.AreEqual(3, pars2[1].CurrentPosition); }
public double this[string code] { [MethodImpl(MethodImplOptions.AggressiveInlining)] get { // NB simple (almost silly) optimization for linear search: // if we lookup the same code or sequentially lookup codes // in the same order they were added then we will hit the right parameter // instantly or in two comparisons var idx = _lastLookupIndex; var total = _parameters.Count; do // round trip { ref var par = ref _parameters.Ref(idx); if (par.Code.Equals(code, StringComparison.OrdinalIgnoreCase)) { _lastLookupIndex = idx; return(par.Current); } idx = (idx + 1) % total; } while (idx != _lastLookupIndex);