public void DeserializeSortedSet() { string json = @"[ ""One"", ""II"", ""3"" ]"; ImmutableSortedSet <string> data = JsonSerializer.Parse <ImmutableSortedSet <string> >(json); Assert.Equal(3, data.Count); Assert.True(data.Contains("3")); Assert.True(data.Contains("II")); Assert.True(data.Contains("One")); }
public void DeserializeSortedSet() { string json = @"[ ""One"", ""II"", ""3"" ]"; ImmutableSortedSet <string> l = JsonConvert.DeserializeObject <ImmutableSortedSet <string> >(json); Assert.AreEqual(3, l.Count()); Assert.IsTrue(l.Contains("3")); Assert.IsTrue(l.Contains("II")); Assert.IsTrue(l.Contains("One")); }
/// <summary> /// Implements the common camera lookup logic. /// </summary> /// <param name="cameraNameQuery">The text to search for. Ideally it is a camera name.</param> /// <returns></returns> public ICameraLookupData Lookup(string cameraNameQuery) { string cameraName = null; if (cameraNames.Contains(cameraNameQuery)) { // We got an exact camera name. cameraName = cameraNameQuery; } else { // Try the searcher. var results = searcher.Search(cameraNameQuery); if (results.Count == 1) { cameraName = results.First(); } else if (results.Count > 1) { return(HandleChoiceResult(results)); } } if (cameraName == null) { return(new CameraLookupError("Not found")); } return(GetImageUrlForCamera(cameraName)); }
public GapAwareTrackingToken AdvanceTo(long index, int maxGapOffset) { long newIndex; ImmutableSortedSet <long> gaps = ImmutableSortedSet.Create(_gaps.ToArray()); if (_gaps.Contains(index)) { gaps = gaps.Remove(index); newIndex = _index; } else if (index > _index) { newIndex = index; var immutableBuilder = gaps.ToBuilder(); foreach (var i in Enumerable.Range((int)(_index + 1L), (int)index)) { immutableBuilder.Add(i); } gaps = immutableBuilder.ToImmutable(); } else { throw new ArgumentException( $"The given index {index} should be larger than the token index {_index} or " + $"be one of the token's gaps {gaps}"); } long smalledAllowedGap = Math.Max(_gapTruncationIndex, newIndex - maxGapOffset); gaps = gaps.Where(x => x >= smalledAllowedGap).ToImmutableSortedSet(); return(new GapAwareTrackingToken(newIndex, gaps, smalledAllowedGap)); }
/// <summary> /// Adds a member to the member node ring. /// </summary> /// <param name="member">TBD</param> /// <returns>TBD</returns> public Gossip AddMember(Member member) { if (_members.Contains(member)) { return(this); } return(Copy(members: _members.Add(member))); }
public void AddSuccessor(BlockId id) { if (_predecessors.Contains(id)) { throw new ArgumentException($"Can't add block as both successor and predecessor"); } _successors.Add(id); }
public bool SysColImmutableSortedSet() { var result = true; foreach (var value in values) { result &= immutableSortedSet.Contains(value); } return(result); }
public bool ImmutableSortedSet() { bool result = default; ImmutableSortedSet <T> collection = _immutableSortedSet; T[] notFound = _notFound; for (int i = 0; i < notFound.Length; i++) { result ^= collection.Contains(notFound[i]); } return(result); }
public override bool IsInScope(string fieldName) { int index; if (GeneratedNames.TryParseSlotIndex(fieldName, out index)) { return(_indices.Contains(index)); } else { Debug.Assert(false, $"Expected hoisted local field name, found '{fieldName}'"); return(true); } }
private static void Main(string[] args) { SeatFactory factory = new SeatFactory(); ImmutableSortedSet <int> seatIds = File.ReadAllLines("./input.txt") .Select(factory.From) .Select(seat => seat.Id) .ToImmutableSortedSet(); int maxId = seatIds.Max(); Console.WriteLine($"The highest seat id is {maxId}."); int searchedId = Enumerable .Range(seatIds.Min(), seatIds.Count + 1) .SingleOrDefault(id => !seatIds.Contains(id)); Console.WriteLine($"My seat id is {searchedId}."); }
private static void OnCompilation(CompilationAnalysisContext context) { if (!TryLoadNUnitTypes(context.Compilation, out NUnitTypes types)) { return; } VisitCategories(types, context.Compilation.Assembly, (category, attribute) => { if (!ProhibitedAssemblyCategories.Contains(category)) { return; } context.ReportDiagnostic(Diagnostic.Create( Diagnostics.NUnitCategory, attribute.ApplicationSyntaxReference.GetSyntax(context.CancellationToken).GetLocation(), $"Assemblies cannot be categorized as any of [{string.Join( ", ", ProhibitedAssemblyCategories )}], but saw '{category}'." )); }); }
public void ToImmutableSortedSet() { ImmutableSortedSet <int> .Builder builder = ImmutableSortedSet.CreateBuilder <int>(); builder.Add(1); builder.Add(5); builder.Add(10); var set = builder.ToImmutableSortedSet(); Assert.Equal(1, builder[0]); Assert.Equal(5, builder[1]); Assert.Equal(10, builder[2]); builder.Remove(10); Assert.False(builder.Contains(10)); Assert.True(set.Contains(10)); builder.Clear(); Assert.True(builder.ToImmutableSortedSet().IsEmpty); Assert.False(set.IsEmpty); ImmutableSortedSet <int> .Builder nullBuilder = null; AssertExtensions.Throws <ArgumentNullException>("builder", () => nullBuilder.ToImmutableSortedSet()); }
public static ImmutableSortedSet <long> Simulate(ImmutableSortedSet <long> currentState, ImmutableHashSet <long> notes) { var min = currentState.Min(); var max = currentState.Max() + 4; var value = 0L; var result = currentState.ToBuilder(); for (var i = min; i <= max; ++i) { value = ((value << 1) & 0b11111) | (currentState.Contains(i) ? 1L : 0L); if (notes.Contains(value)) { result.Add(i - 2L); } else { result.Remove(i - 2L); } } return(result.ToImmutable()); }
public bool hasAppInstalled(string bundleIdentifier) => packageNames.Contains(bundleIdentifier);
private static void GetDisplayClassVariables( ArrayBuilder<string> displayClassVariableNamesInOrderBuilder, Dictionary<string, DisplayClassVariable> displayClassVariablesBuilder, HashSet<string> parameterNames, ImmutableSortedSet<int> inScopeHoistedLocalIndices, DisplayClassInstanceAndFields instance, HashSet<string> hoistedParameterNames) { // Display class instance. The display class fields are variables. foreach (var member in instance.Type.GetMembers()) { if (member.Kind != SymbolKind.Field) { continue; } var field = (FieldSymbol)member; var fieldName = field.Name; DisplayClassVariableKind variableKind; string variableName; GeneratedNameKind fieldKind; int openBracketOffset; int closeBracketOffset; GeneratedNames.TryParseGeneratedName(fieldName, out fieldKind, out openBracketOffset, out closeBracketOffset); switch (fieldKind) { case GeneratedNameKind.DisplayClassLocalOrField: // A local that is itself a display class instance. Debug.Assert(!field.IsStatic); continue; case GeneratedNameKind.HoistedLocalField: // Filter out hoisted locals that are known to be out-of-scope at the current IL offset. // Hoisted locals with invalid indices will be included since more information is better // than less in error scenarios. int slotIndex; if (GeneratedNames.TryParseSlotIndex(fieldName, out slotIndex) && !inScopeHoistedLocalIndices.Contains(slotIndex)) { continue; } variableName = fieldName.Substring(openBracketOffset + 1, closeBracketOffset - openBracketOffset - 1); variableKind = DisplayClassVariableKind.Local; Debug.Assert(!field.IsStatic); break; case GeneratedNameKind.ThisProxyField: // A reference to "this". variableName = fieldName; variableKind = DisplayClassVariableKind.This; Debug.Assert(!field.IsStatic); break; case GeneratedNameKind.None: // A reference to a parameter or local. variableName = fieldName; if (parameterNames.Contains(variableName)) { variableKind = DisplayClassVariableKind.Parameter; hoistedParameterNames.Add(variableName); } else { variableKind = DisplayClassVariableKind.Local; } Debug.Assert(!field.IsStatic); break; default: continue; } if (displayClassVariablesBuilder.ContainsKey(variableName)) { // Only expecting duplicates for async state machine // fields (that should be at the top-level). Debug.Assert(displayClassVariablesBuilder[variableName].DisplayClassFields.Count() == 1); Debug.Assert(instance.Fields.Count() >= 1); // greater depth Debug.Assert(variableKind == DisplayClassVariableKind.Parameter); } else if (variableKind != DisplayClassVariableKind.This || GeneratedNames.GetKind(instance.Type.ContainingType.Name) != GeneratedNameKind.LambdaDisplayClass) { // In async lambdas, the hoisted "this" field in the state machine type will point to the display class instance, if there is one. // In such cases, we want to add the display class "this" to the map instead (or nothing, if it lacks one). displayClassVariableNamesInOrderBuilder.Add(variableName); displayClassVariablesBuilder.Add(variableName, instance.ToVariable(variableName, variableKind, field)); } } }
public bool Contains(Datum value) => set.Contains(value);