public MapPair FindNear(double x, double tolerance) { Enumerator cur, min, max; min = LowerBound(x - tolerance); max = LowerBound(x + tolerance); if (!min.IsValid || (max.IsValid && min.Current == max.Current)) { return(null); // no peaks } MutableKeyValuePair <double, T> best = min.Current; // find the peak closest to the desired mz double minDiff = Math.Abs(x - best.Key); cur = min; while (true) { double curDiff = Math.Abs(x - cur.Current.Key); if (curDiff < minDiff) { minDiff = curDiff; best = cur.Current; } cur.MoveNext(); if ((!max.IsValid && !cur.IsValid) || cur.Current == max.Current) { break; } } return(new MapPair(best.Key, best.Value)); }
public void Store() { lock (this) { XmlSerializer xml = MutableKVPairListSerializer; List <MutableKeyValuePair <string, string> > list = new List <MutableKeyValuePair <string, string> >(); foreach (string k in mDictionary.Keys) { MutableKeyValuePair <string, string> kv = new MutableKeyValuePair <string, string>(); kv.Key = k; kv.Value = mDictionary[k]; list.Add(kv); } try { StreamWriter sw = new StreamWriter(mFilePath); xml.Serialize(sw, list); sw.Close(); } catch { } } }
public CommandExecutionException(string message, MutableKeyValuePair <string, object> pair, Stack <MutableKeyValuePair <string, object> > stack) : base(message) { ExceptionPair = pair; ExceptionStack = stack; }
/// <summary> /// Runs command execution /// </summary> public void Run() { MutableKeyValuePair <string, object>[] procNumbers; switch (MathOperation) { case "*": try { procNumbers = Context.PeekLastTwoStackElement(); } catch (CommandExecutionException ex) { throw ex; } try { Context.PushStackWithDel(new MutableKeyValuePair <string, object>("ans", (Convert.ToDouble(procNumbers[0].Value) * Convert.ToDouble(procNumbers[1].Value)))); } catch (ArithmeticException ex) { throw new CommandExecutionException(ex.Message); } break; case "/": try { procNumbers = Context.PeekLastTwoStackElement(); } catch (CommandExecutionException ex) { throw ex; } if (Convert.ToDouble(procNumbers[1].Value) == 0) { throw new CommandExecutionException("Divide by zero is not allowed"); } try { Context.PushStackWithDel(new MutableKeyValuePair <string, object>("ans", Convert.ToDouble(procNumbers[0].Value) / Convert.ToDouble(procNumbers[1].Value))); } catch (ArithmeticException ex) { throw new CommandExecutionException(ex.Message); } break; case "+": try { procNumbers = Context.PeekLastTwoStackElement(); } catch (CommandExecutionException ex) { throw ex; } try { Context.PushStackWithDel(new MutableKeyValuePair <string, object>("ans", (Convert.ToDouble(procNumbers[0].Value) + Convert.ToDouble(procNumbers[1].Value)))); } catch (ArithmeticException ex) { throw new CommandExecutionException(ex.Message); } break; case "-": try { procNumbers = Context.PeekLastTwoStackElement(); } catch (CommandExecutionException ex) { throw ex; } try { Context.PushStackWithDel(new MutableKeyValuePair <string, object>("ans", (Convert.ToDouble(procNumbers[0].Value) - Convert.ToDouble(procNumbers[1].Value)))); } catch (ArithmeticException ex) { throw new CommandExecutionException(ex.Message); } break; case "SQRT": MutableKeyValuePair <string, object> number = Context.PeekLastStackElement(); try { if (Convert.ToDouble(number.Value) <= 0) { throw new CommandExecutionException($"Can't find square root from {number.Value}", Context.Stack); } Context.PopLastStackElement(); Context.PushStack(new MutableKeyValuePair <string, object>("ans", Math.Sqrt(Convert.ToDouble(number.Value)))); } catch { throw new CommandExecutionException("Not enough items in stack to do this", Context.Stack); } break; default: throw new CommandExecutionException($"There no such operation: {MathOperation}", Context.Stack); } }
private void WriteSummaryEvent(EventSummary summary) { _jsonWriter.WriteStartObject(); _jsonWriter.WritePropertyName("kind"); _jsonWriter.WriteValue("summary"); _jsonWriter.WritePropertyName("startDate"); _jsonWriter.WriteValue(summary.StartDate); _jsonWriter.WritePropertyName("endDate"); _jsonWriter.WriteValue(summary.EndDate); _jsonWriter.WritePropertyName("features"); _jsonWriter.WriteStartObject(); var unprocessedCounters = summary.Counters.Select(kv => MutableKeyValuePair <EventsCounterKey, EventsCounterValue> .FromKeyValue(kv)).ToArray(); for (var i = 0; i < unprocessedCounters.Length; i++) { var firstEntry = unprocessedCounters[i]; if (firstEntry.Value is null) { // already processed continue; } var flagKey = firstEntry.Key.Key; var flagDefault = firstEntry.Value.Default; _jsonWriter.WritePropertyName(flagKey); _jsonWriter.WriteStartObject(); _jsonWriter.WritePropertyName("default"); LdValueSerializer.Instance.WriteJson(_jsonWriter, flagDefault, _jsonSerializer); _jsonWriter.WritePropertyName("counters"); _jsonWriter.WriteStartArray(); for (var j = i; j < unprocessedCounters.Length; j++) { var entry = unprocessedCounters[j]; var key = entry.Key; if (key.Key == flagKey && entry.Value != null) { var counter = entry.Value; unprocessedCounters[j].Value = null; // mark as already processed _jsonWriter.WriteStartObject(); if (key.Variation.HasValue) { _jsonWriter.WritePropertyName("variation"); _jsonWriter.WriteValue(key.Variation.Value); } _jsonWriter.WritePropertyName("value"); LdValueSerializer.Instance.WriteJson(_jsonWriter, counter.FlagValue, _jsonSerializer); if (key.Version.HasValue) { _jsonWriter.WritePropertyName("version"); _jsonWriter.WriteValue(key.Version.Value); } else { _jsonWriter.WritePropertyName("unknown"); _jsonWriter.WriteValue(true); } _jsonWriter.WritePropertyName("count"); _jsonWriter.WriteValue(counter.Count); _jsonWriter.WriteEndObject(); } } _jsonWriter.WriteEndArray(); _jsonWriter.WriteEndObject(); } _jsonWriter.WriteEndObject(); _jsonWriter.WriteEndObject(); }
/// <summary> /// Compares two elements of the map. /// </summary> public int Compare(MutableKeyValuePair <TKey, TValue> x, MutableKeyValuePair <TKey, TValue> y) { return(_comparer.Compare(x.Key, y.Key)); }
public void WriteSummaryEvent(EventSummary summary) { var obj = _jsonWriter.Object(); obj.Name("kind").String("summary"); obj.Name("startDate").Long(summary.StartDate.Value); obj.Name("endDate").Long(summary.EndDate.Value); var flagsObj = obj.Name("features").Object(); var unprocessedCounters = summary.Counters.Select(kv => MutableKeyValuePair <EventsCounterKey, EventsCounterValue> .FromKeyValue(kv)).ToArray(); for (var i = 0; i < unprocessedCounters.Length; i++) { var firstEntry = unprocessedCounters[i]; if (firstEntry.Value is null) { // already processed continue; } var flagKey = firstEntry.Key.Key; var flagDefault = firstEntry.Value.Default; var flagObj = flagsObj.Name(flagKey).Object(); LdValueConverter.WriteJsonValue(flagDefault, flagObj.Name("default")); var countersArr = flagObj.Name("counters").Array(); for (var j = i; j < unprocessedCounters.Length; j++) { var entry = unprocessedCounters[j]; var key = entry.Key; if (key.Key == flagKey && entry.Value != null) { var counter = entry.Value; unprocessedCounters[j].Value = null; // mark as already processed var counterObj = countersArr.Object(); if (key.Variation.HasValue) { counterObj.Name("variation").Int(key.Variation.Value); } LdValueConverter.WriteJsonValue(counter.FlagValue, counterObj.Name("value")); if (key.Version.HasValue) { counterObj.Name("version").Int(key.Version.Value); } else { counterObj.Name("unknown").Bool(true); } counterObj.Name("count").Int(counter.Count); counterObj.End(); } } countersArr.End(); flagObj.End(); } flagsObj.End(); obj.End(); }
public CommandExecutionException(string message, MutableKeyValuePair <string, object> pair) : this(message, pair, null) { }