public static ISorterStage ToReducedSorterStage <T>(this IReadOnlyList <IKeyPair> keyPairs, ISwitchableGroup <T> switchableGroup) { var switchSet = KeyPairSwitchSet.Make <T>(switchableGroup.KeyCount); var dependentKeyPairs = keyPairs.ToDependentKeyPairs().ToList(); foreach (var switchable in switchableGroup.Switchables) { var currentItem = switchable.Item; for (var i = 0; i < dependentKeyPairs.Count; i++) { var currentDp = dependentKeyPairs[i]; if (currentDp.IsDisabled) { continue; } if (switchSet.IsSorted(currentItem)) { break; } var res = switchSet.SwitchFunction(currentDp)(currentItem); currentItem = res.Item1; if (res.Item2) { if (!currentDp.IsUsed) { currentDp.IsUsed = true; currentDp.DisableDependentKeyPairs(); } if (switchSet.IsSorted(currentItem)) { break; } } } } IReadOnlyList <IKeyPair> reducedKeyPairs = dependentKeyPairs.Reduce().ToList(); return(SorterStage.Make(switchableGroup.KeyCount, reducedKeyPairs)); }
public SorterStageVm ( ISorterStage <ISwitchEval> sorterStage, List <Brush> lineBrushes, List <Brush> switchBrushes, int width, bool showUnusedSwitches, int switchableGroupCount ) { _sorterStage = sorterStage; _lineBrushes = lineBrushes; _switchBrushes = switchBrushes; _showUnusedSwitches = showUnusedSwitches; _width = width; _switchableGroupCount = switchableGroupCount; for (var i = 0; i < SorterStage.KeyPairCount; i++) { var keyPair = SorterStage.KeyPair(i); if ((keyPair.UseCount < 1) && !ShowUnusedSwitches) { continue; } var switchBrushIndex = Math.Ceiling( (keyPair.UseCount * (SwitchBrushes.Count - 1)) / SwitchableGroupCount ); SwitchVms.Add(new SwitchGraphicVm(keyPair, SorterStage.KeyCount, LineBrushes, Width) { SwitchBrush = SwitchBrushes[(int)switchBrushIndex] }); } }