private StateVM[] CreateStates() { try { if (_showAll) { int width = _outputModel.Width; int statesCount = (int)Math.Pow(2, width); StateVM[] states = new StateVM[statesCount]; foreach (OutputState state in _outputModel.States) { states[state.Value] = new StateVM(state); } bool amplitudeHasValue = _outputModel.States.First().Amplitude.HasValue; for (int i = 0; i < statesCount; i++) { if (states[i] == null) { if (amplitudeHasValue) { states[i] = new StateVM(new OutputState((ulong)i, Complex.Zero, width)); } else { states[i] = new StateVM(new OutputState((ulong)i, 0.0, width)); } } } switch (_sortBy) { case SortField.Probability: if (_sortDesc) { return(states.OrderByDescending(x => x.Probability).ToArray()); } return(states.OrderBy(x => x.Probability).ToArray()); case SortField.Value: default: if (_sortDesc) { return(states.Reverse().ToArray()); } return(states); } } else { int statesCount = _outputModel.States.Count; StateVM[] states = new StateVM[statesCount]; int i = 0; IEnumerable <OutputState> sorted = _outputModel.States; switch (_sortBy) { case SortField.Probability: if (_sortDesc) { sorted = _outputModel.States.OrderByDescending(x => x.Probability); } else { sorted = _outputModel.States.OrderBy(x => x.Probability); } break; case SortField.Value: default: if (_sortDesc) { sorted = _outputModel.States.OrderByDescending(x => x.Value); } else { sorted = _outputModel.States.OrderBy(x => x.Value); } break; } foreach (OutputState state in sorted) { states[i] = new StateVM(state); i++; } return(states); } } catch (Exception e) { PrintException(e); } return(new StateVM[] { new StateVM(new OutputState(0, Complex.Zero, _outputModel.Width)) }); }
private StateVM[] CreateStates() { try { if (_showAll) { int width = _outputModel.Width; int statesCount = (int)Math.Pow(2, width); StateVM[] states = new StateVM[statesCount]; foreach (OutputState state in _outputModel.States) { states[state.Value] = new StateVM(state); } bool amplitudeHasValue = _outputModel.States.First().Amplitude.HasValue; for (int i = 0; i < statesCount; i++) { if (states[i] == null) { if (amplitudeHasValue) { states[i] = new StateVM(new OutputState((ulong)i, Complex.Zero, width)); } else { states[i] = new StateVM(new OutputState((ulong)i, 0.0, width)); } } } switch (_sortBy) { case SortField.Probability: if (_sortDesc) { return states.OrderByDescending(x => x.Probability).ToArray(); } return states.OrderBy(x => x.Probability).ToArray(); case SortField.Value: default: if (_sortDesc) { return states.Reverse().ToArray(); } return states; } } else { int statesCount = _outputModel.States.Count; StateVM[] states = new StateVM[statesCount]; int i = 0; IEnumerable<OutputState> sorted = _outputModel.States; switch (_sortBy) { case SortField.Probability: if (_sortDesc) { sorted = _outputModel.States.OrderByDescending(x => x.Probability); } else { sorted = _outputModel.States.OrderBy(x => x.Probability); } break; case SortField.Value: default: if (_sortDesc) { sorted = _outputModel.States.OrderByDescending(x => x.Value); } else { sorted = _outputModel.States.OrderBy(x => x.Value); } break; } foreach (OutputState state in sorted) { states[i] = new StateVM(state); i++; } return states; } } catch (Exception e) { PrintException(e); } return new StateVM[] { new StateVM(new OutputState(0, Complex.Zero, _outputModel.Width)) }; }