/// <summary> /// Gets an enumerator for the KeyValuePairs in this dictionary. /// </summary> /// <returns>The enumerator.</returns> public IEnumerator <KeyValuePair <TKey, TValue> > GetEnumerator() { //throw new NotImplementedException(); DictionaryEnumerator temp = new DictionaryEnumerator(_table); return(temp); }
public object DictionaryEnumeratorKey <TKey, TValue>(DictionaryEnumerator <TKey, TValue> enumerator) { if (enumerator.Index == 0 || (enumerator.Index == enumerator.Dictionary.Count + 1)) { throw new System.Exception("Enumeration has either not started or has already finished."); } return(enumerator.Current.Key); }
public void Reset <TKey, TValue>(DictionaryEnumerator <TKey, TValue> enumerator) { if (enumerator.Version != enumerator.Dictionary.Version) { throw new System.Exception("Collection was modified; enumeration operation may not execute."); } enumerator.Index = 0; enumerator.Current = new KeyValuePair <TKey, TValue>(); }
public object Clone() { var e = new DictionaryEnumerator(host, mode); e.stamp = stamp; e.pos = pos; e.size = size; e.currentKey = currentKey; e.currentValue = currentValue; e.invalid = invalid; return e; }
public DictionaryEnumerator <TKey, TValue> Create <TKey, TValue>(Dictionary <TKey, TValue> dictionary, int getEnumeratorRetType) { var enumerator = new DictionaryEnumerator <TKey, TValue> { Dictionary = dictionary, Version = dictionary.Version, Index = 0, GetEnumeratorRetType = getEnumeratorRetType, Current = new KeyValuePair <TKey, TValue>() }; return(enumerator); }
public void DictionaryEnumerator_PropertyCheck() { var dic = new OrderedDictionary <string, string>(); dic.Add("a", "string1"); dic.Add("b", "string2"); var enumerator = new DictionaryEnumerator <string, string>(dic); enumerator.MoveNext(); Assert.AreEqual("a", enumerator.Key); Assert.AreEqual("string1", enumerator.Value); }
private void CopyToArray([NotNull] Array arr, int i, EnumeratorMode mode) { if (arr == null) throw new ArgumentNullException(nameof(arr)); if (i < 0 || i + this.Count > arr.Length) throw new ArgumentOutOfRangeException(nameof(i)); IEnumerator it = new DictionaryEnumerator(this, mode); while (it.MoveNext()) { arr.SetValue(it.Current, i++); } }
public object EnumeratorCurrent <TKey, TValue>(DictionaryEnumerator <TKey, TValue> enumerator) { if (enumerator.Index == 0 || (enumerator.Index == enumerator.Dictionary.Count + 1)) { throw new System.Exception("Enumeration has either not started or has already finished."); } if (enumerator.GetEnumeratorRetType == DictEntry) { return(new DictionaryEntry <TKey, TValue>(enumerator.Current.Key, enumerator.Current.Value)); } else { return(new KeyValuePair <TKey, TValue>(enumerator.Current.Key, enumerator.Current.Value)); } }
public void DictionaryEnumerator_Reset_YieldsFirstItemAgain() { var dic = new OrderedDictionary <string, string>(); dic.Add("a", "string1"); dic.Add("b", "string2"); var enumerator = new DictionaryEnumerator <string, string>(dic); enumerator.MoveNext(); var firstValue = enumerator.Value; enumerator.Reset(); enumerator.MoveNext(); var firstValueAfterReset = enumerator.Value; Assert.AreEqual(firstValue, firstValueAfterReset); }
public bool MoveNext <TKey, TValue>(DictionaryEnumerator <TKey, TValue> enumerator) { if (enumerator.Version != enumerator.Dictionary.Version) { throw new System.Exception("Collection was modified; enumeration operation may not execute."); } // Use unsigned comparison since we set index to dictionary.count+1 when the enumeration ends. // dictionary.count+1 could be negative if dictionary.count is Int32.MaxValue while ((uint)enumerator.Index < (uint)enumerator.Dictionary.Count) { if (enumerator.Dictionary.Entries[enumerator.Index].HashCode >= 0) { enumerator.Current = new KeyValuePair <TKey, TValue>(enumerator.Dictionary.Entries[enumerator.Index].Key, enumerator.Dictionary.Entries[enumerator.Index].Value); enumerator.Index++; return(true); } enumerator.Index++; } enumerator.Index = enumerator.Dictionary.Count + 1; enumerator.Current = new KeyValuePair <TKey, TValue>(); return(false); }
public DictionaryCollection(DictionaryEnumerator e) { enumerator = e; }
internal static ZipkinSpan ToZipkinSpan(this SpanData otelSpan, ZipkinEndpoint defaultLocalEndpoint, bool useShortTraceIds = false) { var context = otelSpan.Context; var startTimestamp = ToEpochMicroseconds(otelSpan.StartTimestamp); var endTimestamp = ToEpochMicroseconds(otelSpan.EndTimestamp); string parentId = null; if (otelSpan.ParentSpanId != default) { parentId = EncodeSpanId(otelSpan.ParentSpanId); } var attributeEnumerationState = new AttributeEnumerationState { Tags = PooledList <KeyValuePair <string, string> > .Create(), }; DictionaryEnumerator <string, object, AttributeEnumerationState> .AllocationFreeForEach(otelSpan.Attributes, ref attributeEnumerationState, ProcessAttributesRef); DictionaryEnumerator <string, object, AttributeEnumerationState> .AllocationFreeForEach(otelSpan.LibraryResource.Attributes, ref attributeEnumerationState, ProcessLibraryResourcesRef); var localEndpoint = defaultLocalEndpoint; var serviceName = attributeEnumerationState.ServiceName; // override default service name if (!string.IsNullOrWhiteSpace(serviceName)) { if (!string.IsNullOrWhiteSpace(attributeEnumerationState.ServiceNamespace)) { serviceName = attributeEnumerationState.ServiceNamespace + "." + serviceName; } if (!LocalEndpointCache.TryGetValue(serviceName, out localEndpoint)) { localEndpoint = defaultLocalEndpoint.Clone(serviceName); LocalEndpointCache.TryAdd(serviceName, localEndpoint); } } ZipkinEndpoint remoteEndpoint = null; if ((otelSpan.Kind == SpanKind.Client || otelSpan.Kind == SpanKind.Producer) && attributeEnumerationState.RemoteEndpointServiceName != null) { remoteEndpoint = RemoteEndpointCache.GetOrAdd(attributeEnumerationState.RemoteEndpointServiceName, ZipkinEndpoint.Create); } var status = otelSpan.Status; if (status.IsValid) { if (!CanonicalCodeCache.TryGetValue(status.CanonicalCode, out string canonicalCode)) { canonicalCode = status.CanonicalCode.ToString(); CanonicalCodeCache.TryAdd(status.CanonicalCode, canonicalCode); } PooledList <KeyValuePair <string, string> > .Add(ref attributeEnumerationState.Tags, new KeyValuePair <string, string>(StatusCode, canonicalCode)); if (status.Description != null) { PooledList <KeyValuePair <string, string> > .Add(ref attributeEnumerationState.Tags, new KeyValuePair <string, string>(StatusDescription, status.Description)); } } var annotations = PooledList <ZipkinAnnotation> .Create(); ListEnumerator <Event, PooledList <ZipkinAnnotation> > .AllocationFreeForEach(otelSpan.Events, ref annotations, ProcessEventsRef); return(new ZipkinSpan( EncodeTraceId(context.TraceId, useShortTraceIds), parentId, EncodeSpanId(context.SpanId), ToSpanKind(otelSpan), otelSpan.Name, ToEpochMicroseconds(otelSpan.StartTimestamp), duration: endTimestamp - startTimestamp, localEndpoint, remoteEndpoint, annotations, attributeEnumerationState.Tags, null, null)); }
internal static ZipkinSpan ToZipkinSpan(this Activity activity, ZipkinEndpoint defaultLocalEndpoint, bool useShortTraceIds = false) { var context = activity.Context; var startTimestamp = activity.StartTimeUtc.ToEpochMicroseconds(); string parentId = EncodeSpanId(activity.ParentSpanId); if (string.Equals(parentId, InvalidSpanId, StringComparison.Ordinal)) { parentId = null; } var attributeEnumerationState = new AttributeEnumerationState { Tags = PooledList <KeyValuePair <string, string> > .Create(), }; DictionaryEnumerator <string, string, AttributeEnumerationState> .AllocationFreeForEach(activity.Tags, ref attributeEnumerationState, ProcessTagsRef); var activitySource = activity.Source; if (!string.IsNullOrEmpty(activitySource.Name)) { PooledList <KeyValuePair <string, string> > .Add(ref attributeEnumerationState.Tags, new KeyValuePair <string, string>("library.name", activitySource.Name)); if (!string.IsNullOrEmpty(activitySource.Version)) { PooledList <KeyValuePair <string, string> > .Add(ref attributeEnumerationState.Tags, new KeyValuePair <string, string>("library.version", activitySource.Version)); } } var localEndpoint = defaultLocalEndpoint; var serviceName = attributeEnumerationState.ServiceName; // override default service name if (!string.IsNullOrWhiteSpace(serviceName)) { if (!string.IsNullOrWhiteSpace(attributeEnumerationState.ServiceNamespace)) { serviceName = attributeEnumerationState.ServiceNamespace + "." + serviceName; } if (!LocalEndpointCache.TryGetValue(serviceName, out localEndpoint)) { localEndpoint = defaultLocalEndpoint.Clone(serviceName); LocalEndpointCache.TryAdd(serviceName, localEndpoint); } } ZipkinEndpoint remoteEndpoint = null; if ((activity.Kind == ActivityKind.Client || activity.Kind == ActivityKind.Producer) && attributeEnumerationState.RemoteEndpointServiceName != null) { remoteEndpoint = RemoteEndpointCache.GetOrAdd(attributeEnumerationState.RemoteEndpointServiceName, ZipkinEndpoint.Create); } var annotations = PooledList <ZipkinAnnotation> .Create(); ListEnumerator <ActivityEvent, PooledList <ZipkinAnnotation> > .AllocationFreeForEach(activity.Events, ref annotations, ProcessActivityEventsRef); return(new ZipkinSpan( EncodeTraceId(context.TraceId, useShortTraceIds), parentId, EncodeSpanId(context.SpanId), ToActivityKind(activity), activity.OperationName, activity.StartTimeUtc.ToEpochMicroseconds(), duration: (long)activity.Duration.ToEpochMicroseconds(), localEndpoint, remoteEndpoint, annotations, attributeEnumerationState.Tags, null, null)); }
public void Dispose <TKey, TValue>(DictionaryEnumerator <TKey, TValue> enumerator) { }
/// <inheritdoc/> public IDictionaryEnumerator GetEnumerator() { return(DictionaryEnumerator <TKey, TValue> .GetDictionaryEnumerator(this)); }