protected static PooledList <int> CreatePooled(int size) { var rand = new Random(RAND_SEED); var list = new PooledList <int>(size); for (int i = 0; i < size; i++) { list.Add(rand.Next()); } return(list); }
public void Sort_IComparer_WithDuplicates(int count) { PooledList <T> list = GenericListFactory(count); list.Add(list[0]); IComparer <T> comparer = GetIComparer(); list.Sort(comparer); Assert.All(Enumerable.Range(0, count - 2), i => { Assert.True(comparer.Compare(list[i], list[i + 1]) <= 0); }); }
public bool ForEach(ActivityEvent activityEvent) { if (!this.Created) { this.Logs = PooledList <JaegerLog> .Create(); this.Created = true; } PooledList <JaegerLog> .Add(ref this.Logs, activityEvent.ToJaegerLog()); return(true); }
private static void Test1() { var List = new PooledList <int>(1); for (int I = 1; I <= 16; I++) { List.Add(I); } List.Remove(1); List.Add(2); List.Remove(9); List.Add(69); foreach (var x in List) { Console.WriteLine(x); } }
public bool ForEach(ActivityLink activityLink) { if (!this.Created) { this.SpanRefs = PooledList <JaegerSpanRef> .Create(); this.Created = true; } PooledList <JaegerSpanRef> .Add(ref this.SpanRefs, activityLink.ToJaegerSpanRef()); return(true); }
public bool ForEach(KeyValuePair <string, object> tag) { if (tag.Value is Array) { ProcessJaegerTagArray(ref this.Tags, tag); } else if (tag.Value != null) { PooledList <JaegerTag> .Add(ref this.Tags, tag.ToJaegerTag()); } return(true); }
public void Exists_VerifyExceptions(T[] items) { using (var list = new PooledList <T>()) { for (int i = 0; i < items.Length; ++i) { list.Add(items[i]); } //[] Verify Null match Assert.Throws <ArgumentNullException>(() => list.Exists(null)); //"Err_858ahia Expected null match to throw ArgumentNullException" } }
public bool ForEach(ActivityEvent activityEvent) { if (!this.Created) { this.Annotations = PooledList <ZipkinAnnotation> .Create(); this.Created = true; } PooledList <ZipkinAnnotation> .Add(ref this.Annotations, new ZipkinAnnotation(activityEvent.Timestamp.ToEpochMicroseconds(), activityEvent.Name)); return(true); }
public bool ForEach(ActivityEvent activityEvent) { if (!this.Created) { this.Events = PooledList <OtlpTrace.Span.Types.Event> .Create(); this.Created = true; } PooledList <OtlpTrace.Span.Types.Event> .Add(ref this.Events, ToOtlpEvent(activityEvent)); return(true); }
public bool ForEach(ActivityLink activityLink) { if (!this.Created) { this.Links = PooledList <OtlpTrace.Span.Types.Link> .Create(); this.Created = true; } PooledList <OtlpTrace.Span.Types.Link> .Add(ref this.Links, ToOtlpLink(activityLink)); return(true); }
public bool ForEach(KeyValuePair <string, object> activityTag) { if (activityTag.Value == null) { return(true); } if (activityTag.Value is string strVal) { string key = activityTag.Key; if (RemoteEndpointServiceNameKeyResolutionDictionary.TryGetValue(key, out int priority) && (this.RemoteEndpointServiceName == null || priority < this.RemoteEndpointServiceNamePriority)) { this.RemoteEndpointServiceName = strVal; this.RemoteEndpointServiceNamePriority = priority; } else if (key == SemanticConventions.AttributeNetPeerName) { this.HostName = strVal; } else if (key == SemanticConventions.AttributeNetPeerIp) { this.IpAddress = strVal; } else if (key == SemanticConventions.AttributeNetPeerPort && int.TryParse(strVal, out var port)) { this.Port = port; } else if (key == Resource.ServiceNameKey) { this.ServiceName = strVal; } else if (key == Resource.ServiceNamespaceKey) { this.ServiceNamespace = strVal; } PooledList <KeyValuePair <string, object> > .Add(ref this.Tags, new KeyValuePair <string, object>(key, strVal)); } else { if (activityTag.Value is int intVal && activityTag.Key == SemanticConventions.AttributeNetPeerPort) { this.Port = intVal; } PooledList <KeyValuePair <string, object> > .Add(ref this.Tags, activityTag); } return(true); }
private static void Test2() { var List = new PooledList <int>(20); for (int I = 1; I <= 10; I++) { List.Add(I); } foreach (var x in List) { Console.WriteLine(x); } }
static public string[] EvaluateConcepts(Level inLevel) { using (PooledList <Code> codes = PooledList <Code> .Create()) { codes.Capacity = 4; if (inLevel.isSingleDigitProblem && inLevel.isTargetNumber) { codes.Add(Code.M52); codes.Add(Code.M53); } if (inLevel.isDoubleDigitProblem && inLevel.isTargetNumber && !inLevel.requiresRegrouping) { codes.Add(Code.M64); } if (inLevel.isSingleDigitProblem && !inLevel.isTargetNumber) { codes.Add(Code.M80); codes.Add(Code.M85); } if (inLevel.isDoubleDigitProblem) { codes.Add(Code.M86); } if (inLevel.isDoubleDigitProblem && inLevel.isTargetNumber && inLevel.requiresRegrouping) { codes.Add(Code.M87); } if (!inLevel.requiresRegrouping && !inLevel.isTargetNumber) { codes.Add(Code.M88); } if (inLevel.requiresRegrouping) { codes.Add(Code.M92); } return(BuildCodeStrings(codes)); } }
public void IndexOf_DefaultValue(IndexOfMethod indexOfMethod, int count, bool frontToBackOrder) { T defaultValue = default; PooledList <T> list = GenericListFactory(count); IndexOfDelegate IndexOf = IndexOfDelegateFromType(indexOfMethod); while (list.Remove(defaultValue)) { count--; } list.Add(defaultValue); Assert.Equal(count, IndexOf(list, defaultValue)); list.Dispose(); }
public bool ForEach(KeyValuePair <string, object> activityTag) { if (activityTag.Value == null) { return(true); } string key = activityTag.Key; if (activityTag.Value is string strVal) { PeerServiceResolver.InspectTag(ref this, key, strVal); if (key == SpanAttributeConstants.StatusCodeKey) { this.StatusCode = StatusHelper.GetStatusCodeForTagValue(strVal); if (!this.StatusCode.HasValue || this.StatusCode == Trace.StatusCode.Unset) { // Unset Status is not sent: https://github.com/open-telemetry/opentelemetry-specification/blob/master/specification/trace/sdk_exporters/zipkin.md#status return(true); } // Normalize status since it is user-driven. activityTag = new KeyValuePair <string, object>(key, StatusHelper.GetTagValueForStatusCode(this.StatusCode.Value)); } else if (key == SpanAttributeConstants.StatusDescriptionKey) { // Description is sent as `error` but only if StatusCode is Error. See: https://github.com/open-telemetry/opentelemetry-specification/blob/master/specification/trace/sdk_exporters/zipkin.md#status this.StatusDescription = strVal; return(true); } else if (key == ZipkinErrorFlagTagName) { // Ignore `error` tag if it exists, it will be added based on StatusCode + StatusDescription. return(true); } } else if (activityTag.Value is int intVal && activityTag.Key == SemanticConventions.AttributeNetPeerPort) { PeerServiceResolver.InspectTag(ref this, key, intVal); } PooledList <KeyValuePair <string, object> > .Add(ref this.Tags, activityTag); return(true); }
private void SpawnChickens() { using (PooledList <DragHolder> chickenNests = PooledList <DragHolder> .Create()) { int maxChickens = Level.Chickens.Length; if (!Level.FixedOperator) { maxChickens += 2; } for (int i = 0; i < maxChickens; ++i) { float offset = i - ((maxChickens - 1) / 2.0f); // Spawn the nest DragHolder chickenNest = ((GameObject)Instantiate(ChickenNestPrefab, new Vector3(offset * ChickenSpacing, 0, 0), Quaternion.identity)).GetComponent <DragHolder>(); chickenNest.transform.SetParent(ChickenRoot, false); chickenNests.Add(chickenNest); SlotFinder.AddSlot(chickenNest); if (i < Level.Chickens.Length) { // Spawn the chicken ExpressionChicken chicken = ((GameObject)Instantiate(ValueChickenPrefab, new Vector3(offset * ChickenSpacing, 0, 0), Quaternion.identity)).GetComponent <ExpressionChicken>(); chicken.transform.SetParent(ChickenRoot, false); chicken.GetComponent <StartingSeat>().SetHolder(chickenNest); chicken.SetValue(Level.Chickens[i]); chicken.SlotFinder = SlotFinder; } else { OperatorType operatorType = i == Level.Chickens.Length ? OperatorType.Add : OperatorType.Subtract; // Spawn the operator chicken ExpressionChicken chicken = ((GameObject)Instantiate(OperatorChickenPrefab, new Vector3(offset * ChickenSpacing, 0, 0), Quaternion.identity)).GetComponent <ExpressionChicken>(); chicken.transform.SetParent(ChickenRoot, false); chicken.GetComponent <StartingSeat>().SetHolder(chickenNest); chicken.SetOperator(operatorType); chicken.SlotFinder = SlotFinder; } } foreach (var nest in chickenNests) { nest.transform.SetAsFirstSibling(); } } }
static public string[] EvaluateConcepts(Minigames.ExpressionMinigame inMinigame) { using (PooledList <Code> codes = PooledList <Code> .Create()) { ExpressionMinigameCategories category = inMinigame.Level.Categories; codes.Capacity = 4; bool bIsDouble = HasCategories(category, ExpressionMinigameCategories.Double) || HasCategories(category, ExpressionMinigameCategories.DoubleLow); if (HasCategories(category, ExpressionMinigameCategories.Single)) { codes.Add(Code.M52); codes.Add(Code.M53); codes.Add(Code.M80); codes.Add(Code.M85); } if (bIsDouble && !HasCategories(category, ExpressionMinigameCategories.Regroup)) { codes.Add(Code.M64); } if (bIsDouble) { codes.Add(Code.M86); } if (HasCategories(category, ExpressionMinigameCategories.Double | ExpressionMinigameCategories.Regroup) || HasCategories(category, ExpressionMinigameCategories.DoubleLow | ExpressionMinigameCategories.Regroup)) { codes.Add(Code.M87); } if (HasCategories(category, ExpressionMinigameCategories.Regroup)) { codes.Add(Code.M92); } return(BuildCodeStrings(codes)); } }
public void GlobalSetup() { int N = 8192; list = new List <int>(N); pooled = new PooledList <int>(N); for (int i = 0; i < N; i++) { list.Add(i); pooled.Add(i); } nonexistentItem = -1; firstItem = 0; middleItem = pooled.Count / 2; lastItem = pooled.Count - 1; }
public void Sort_Comparison_WithDuplicates(int count) { PooledList <T> list = GenericListFactory(count); list.Add(list[0]); IComparer <T> iComparer = GetIComparer(); int comparer(T first, T second) { return(iComparer.Compare(first, second)); } list.Sort(comparer); Assert.All(Enumerable.Range(0, count - 2), i => { Assert.True(iComparer.Compare(list[i], list[i + 1]) <= 0); }); }
public void ForEach_Verify(int count) { PooledList <T> list = GenericListFactory(count); PooledList <T> visitedItems = new PooledList <T>(); void action(T item) { visitedItems.Add(item); } //[] Verify ForEach looks at every item visitedItems.Clear(); list.ForEach(action); VerifyList(list, visitedItems); list.Dispose(); visitedItems.Dispose(); }
public void GlobalSetup() { int N = 8192; list = new List <string>(N); pooled = new PooledList <string>(N); for (int i = 0; i < N; i++) { list.Add(i.ToString()); pooled.Add(i.ToString()); } nonexistentItem = "foo"; firstItem = 0.ToString(); middleItem = (list.Count / 2).ToString(); lastItem = (list.Count - 1).ToString(); }
public void BinarySearch_ForEveryItemWithDuplicates(int count) { if (count > 0) { PooledList <T> list = GenericListFactory(count); list.Add(list[0]); list.Sort(); PooledList <T> beforeList = list.ToPooledList(); Assert.All(Enumerable.Range(0, list.Count), index => { Assert.True(list.BinarySearch(beforeList[index]) >= 0); Assert.True(list.BinarySearch(beforeList[index], GetIComparer()) >= 0); Assert.Equal(beforeList[index], list[index]); }); list.Dispose(); } }
/// <summary> /// /// </summary> /// <param name="blockGraph"></param> /// <returns></returns> public Task <VerifyResult> TryAddBlockGraph(BlockGraph blockGraph) { Guard.Argument(blockGraph, nameof(blockGraph)).NotNull(); try { if (_pooledBlockGraphs.Contains(blockGraph)) { return(Task.FromResult(VerifyResult.AlreadyExists)); } _pooledBlockGraphs.Add(blockGraph); OnBlockGraphAdd(new BlockGraphEventArgs(blockGraph)); } catch (Exception ex) { _logger.Here().Error(ex, ex.Message); return(Task.FromResult(VerifyResult.Invalid)); } return(Task.FromResult(VerifyResult.Succeed)); }
private static bool ProcessAttributes(ref AttributeEnumerationState state, KeyValuePair <string, object> attribute) { string key = attribute.Key; if (!(attribute.Value is string strVal)) { strVal = attribute.Value?.ToString(); } if (strVal != null && RemoteEndpointServiceNameKeyResolutionDictionary.TryGetValue(key, out int priority) && (state.RemoteEndpointServiceName == null || priority < state.RemoteEndpointServiceNamePriority)) { state.RemoteEndpointServiceName = strVal; state.RemoteEndpointServiceNamePriority = priority; } PooledList <KeyValuePair <string, string> > .Add(ref state.Tags, new KeyValuePair <string, string>(key, strVal)); return(true); }
public bool ForEach(KeyValuePair <string, object> activityTag) { if (activityTag.Value == null) { return(true); } string key = activityTag.Key; if (activityTag.Value is string strVal) { PeerServiceResolver.InspectTag(ref this, key, strVal); if (key == SpanAttributeConstants.StatusCodeKey) { StatusCode?statusCode = StatusHelper.GetStatusCodeForTagValue(strVal); if (statusCode == StatusCode.Error) { // Error flag: https://github.com/open-telemetry/opentelemetry-specification/blob/master/specification/trace/sdk_exporters/zipkin.md#error-flag PooledList <KeyValuePair <string, object> > .Add(ref this.Tags, new KeyValuePair <string, object>("error", string.Empty)); } else if (!statusCode.HasValue || statusCode == StatusCode.Unset) { // Unset Status is not sent: https://github.com/open-telemetry/opentelemetry-specification/blob/master/specification/trace/sdk_exporters/zipkin.md#status return(true); } // Normalize status since it is user-driven. activityTag = new KeyValuePair <string, object>(key, StatusHelper.GetTagValueForStatusCode(statusCode.Value)); } } else if (activityTag.Value is int intVal && activityTag.Key == SemanticConventions.AttributeNetPeerPort) { PeerServiceResolver.InspectTag(ref this, key, intVal); } PooledList <KeyValuePair <string, object> > .Add(ref this.Tags, activityTag); return(true); }
void HitTestCore(CompositionVisual visual, Point globalPoint, PooledList <CompositionVisual> result, Func <IVisual, bool>?filter) { if (visual.Visible == false) { return; } if (!TryTransformTo(visual, globalPoint, out var point)) { return; } if (visual.ClipToBounds && (point.X < 0 || point.Y < 0 || point.X > visual.Size.X || point.Y > visual.Size.Y)) { return; } if (visual.Clip?.FillContains(point) == false) { return; } // Inspect children if (visual is CompositionContainerVisual cv) { for (var c = cv.Children.Count - 1; c >= 0; c--) { var ch = cv.Children[c]; HitTestCore(ch, globalPoint, result, filter); } } // Hit-test the current node if (visual.HitTest(point, filter)) { result.Add(visual); } }
public bool ForEach(KeyValuePair <string, object> activityTag) { if (activityTag.Value == null) { return(true); } string key = activityTag.Key; if (activityTag.Value is string strVal) { PeerServiceResolver.InspectTag(ref this, key, strVal); } else if (activityTag.Value is int intVal && activityTag.Key == SemanticConventions.AttributeNetPeerPort) { PeerServiceResolver.InspectTag(ref this, key, intVal); } PooledList <KeyValuePair <string, object> > .Add(ref this.Tags, activityTag); return(true); }
private static bool ProcessLibraryResources(ref AttributeEnumerationState state, KeyValuePair <string, object> label) { // See https://github.com/open-telemetry/opentelemetry-specification/blob/master/specification/data-resource-semantic-conventions.md string key = label.Key; object val = label.Value; string strVal = val as string; if (key == Resource.ServiceNameKey && strVal != null) { state.ServiceName = strVal; } else if (key == Resource.ServiceNamespaceKey && strVal != null) { state.ServiceNamespace = strVal; } else { PooledList <KeyValuePair <string, string> > .Add(ref state.Tags, new KeyValuePair <string, string>(key, strVal ?? val?.ToString())); } return(true); }
public void Sort_intintIComparer_WithDuplicates(int count) { PooledList <T> unsortedList = GenericListFactory(count); IComparer <T> comparer = GetIComparer(); unsortedList.Add(unsortedList[0]); for (int startIndex = 0; startIndex < count - 2; startIndex++) { for (int sortCount = 2; sortCount < count - startIndex; sortCount++) { using (var list = new PooledList <T>(unsortedList)) { list.Sort(startIndex, sortCount + 1, comparer); for (int i = startIndex; i < sortCount; i++) { Assert.InRange(comparer.Compare(list[i], list[i + 1]), int.MinValue, 1); } } } } unsortedList.Dispose(); }
private void Exists_VerifyVanilla(T[] items) { T expectedItem = default; using (var list = new PooledList <T>()) { bool expectedItemDelegate(T item) { return(expectedItem == null ? item == null : expectedItem.Equals(item)); } bool typeNullable = default(T) == null; for (int i = 0; i < items.Length; ++i) { list.Add(items[i]); } //[] Verify Exists returns the correct index for (int i = 0; i < items.Length; ++i) { expectedItem = items[i]; Assert.True(list.Exists(expectedItemDelegate), "Err_282308ahid Verifying Nullable returned FAILED\n"); } //[] Verify Exists returns true if the match returns true on every item Assert.True((0 < items.Length) == list.Exists((T item) => { return(true); }), "Err_548ahid Verify Exists returns 0 if the match returns true on every item FAILED\n"); //[] Verify Exists returns false if the match returns false on every item Assert.True(!list.Exists((T item) => { return(false); }), "Err_30848ahidi Verify Exists returns -1 if the match returns false on every item FAILED\n"); //[] Verify with default(T) list.Add(default);