public CountCirc(int el) { quantity = 2; primes = new SortedSet<int>(Sift(el)); primes.Remove(2); primes.Remove(5); }
public void Remove () { var set = new SortedSet<int> (); Assert.IsTrue (set.Add (2)); Assert.IsTrue (set.Add (4)); Assert.AreEqual (2, set.Count); Assert.IsTrue (set.Remove (4)); Assert.IsTrue (set.Remove (2)); Assert.AreEqual (0, set.Count); Assert.IsFalse (set.Remove (4)); Assert.IsFalse (set.Remove (2)); }
public void Remove(byte[] key) { AssertValidKey(key); //find the element while adding to moveCandidates SortedSet<HashTableElement> moveCandidates = new SortedSet<HashTableElement>(); HashTableElement removingElement = null; foreach (var hashTableElement in GetElementWithKeyEnumerable(key)) { Debug.Assert(moveCandidates.Add(hashTableElement)); removingElement = hashTableElement; } Debug.Assert(removingElement != null, "GetElementWithKeyEnumberable() should have returned at least one element or thrown an exception"); moveCandidates.Remove(removingElement); //null out the element WipeArrayAt(removingElement.Index); //rehash the elements between the hash and the removed element foreach (var moveCandidate in moveCandidates) { Debug.Assert(!moveCandidate.Key.EqualsBytes(NullKey), "GetElementWithKeyEnumerable() should not return any null elements"); WipeArrayAt(moveCandidate.Index); Put(moveCandidate.Key, moveCandidate.Value); } }
/// <summary> /// Provides all the function calls related to this namespace /// </summary> /// <param name="system">The system in which the calls should be gathered</param> /// <param name="container">If provided, indicates that the calls should be limited to a given container</param> /// <returns></returns> public static List<AccessMode> getAccesses(EFSSystem system, IEnclosesNameSpaces container = null) { SortedSet<ProcedureOrFunctionCall> procedureCalls = new SortedSet<ProcedureOrFunctionCall>(); SortedSet<AccessToVariable> accessesToVariables = new SortedSet<AccessToVariable>(); foreach (Usage usage in system.FindReferences(IsCallableOrIsVariable.INSTANCE)) { ModelElement target = (ModelElement) usage.Referenced; ModelElement source = usage.User; NameSpace sourceNameSpace = getCorrespondingNameSpace(source, container, true); NameSpace targetNameSpace = getCorrespondingNameSpace(target, container, false); if (IsCallable.Predicate(usage.Referenced)) { if (considerCall(usage, container, sourceNameSpace, targetNameSpace)) { procedureCalls.Add(new ProcedureOrFunctionCall(sourceNameSpace, targetNameSpace, (ICallable) target)); } } else { // IsVariable(usage.Referenced) if (considerVariableReference(usage, container, sourceNameSpace, targetNameSpace)) { Usage.ModeEnum mode = (Usage.ModeEnum) usage.Mode; // Find a corresponding access to variable (same source and target namespaces, and same variable AccessToVariable otherAccess = null; foreach (AccessToVariable access in accessesToVariables) { if (access.Target == usage.Referenced && access.Source == sourceNameSpace && access.Target == targetNameSpace) { otherAccess = access; break; } } if (otherAccess != null) { if (otherAccess.AccessMode != mode) { // Since the access mode is different, one of them is either Read or ReadWrite and the other is ReadWrite or Write. // So, in any case, the resulting access mode is ReadWrite accessesToVariables.Remove(otherAccess); accessesToVariables.Add(new AccessToVariable(sourceNameSpace, targetNameSpace, (IVariable) target, Usage.ModeEnum.ReadAndWrite)); } else { // Already exists, do nothing } } else { // Does not already exists, insert it in the list accessesToVariables.Add(new AccessToVariable(sourceNameSpace, targetNameSpace, (IVariable) target, mode)); } } } } // Build the results based on the intermediate results List<AccessMode> retVal = new List<AccessMode>(); retVal.AddRange(procedureCalls); retVal.AddRange(accessesToVariables); return retVal; }
public void ViewCount () { var set = new SortedSet<int> { 1, 3, 4, 5, 6, 7, 8, 9 }; var view = set.GetViewBetween (4, 8); Assert.AreEqual (5, view.Count); set.Remove (5); Assert.AreEqual (4, view.Count); set.Add (10); Assert.AreEqual (4, view.Count); set.Add (6); Assert.AreEqual (4, view.Count); set.Add (5); Assert.AreEqual (5, view.Count); }
private List<PathCoordinate> GeneratePath(PathCoordinate start, PathCoordinate end, Size size, double maxDistance) { SortedSet<PathCoordinate> sortedPath = new SortedSet<PathCoordinate>(new PathCoordinateDistanceToTargetComparer()); List<PathCoordinate> path = new List<PathCoordinate>(); _firstCoordinate = start; _firstCoordinate.DistanceToTarget = _firstCoordinate.DistanceTo(end); PathCoordinate currentCoordinate = start; int loopsLeft = 1000; while (currentCoordinate != null && currentCoordinate != end && loopsLeft > 0) { currentCoordinate.Checked = true; loopsLeft--; PathCoordinate[] pathOptions = GetPathOptions(currentCoordinate, end, size, maxDistance); foreach (var option in pathOptions) { double distance = currentCoordinate.DistanceFromStart + currentCoordinate.DistanceTo(option); bool existsInPath = sortedPath.Contains(option); if (!existsInPath || distance < option.DistanceFromStart) { option.PreviousCoordinate = currentCoordinate; if (existsInPath) { sortedPath.Remove(option); option.SetDistanceFromStartAndTarget(distance, option.DistanceTo(end)); sortedPath.Add(option); } else { option.SetDistanceFromStartAndTarget(distance, option.DistanceTo(end)); sortedPath.Add(option); } } } sortedPath.Remove(currentCoordinate); if (sortedPath.Count > 0) currentCoordinate = sortedPath.Min; else break; } if (currentCoordinate == null || currentCoordinate == _firstCoordinate) return null; // currentCoordinate is destination so walk up previous coordinates and add to list, then reverse List<PathCoordinate> result = new List<PathCoordinate> {currentCoordinate}; while (currentCoordinate.PreviousCoordinate != null) { result.Add(currentCoordinate.PreviousCoordinate); currentCoordinate = currentCoordinate.PreviousCoordinate; } result.Reverse(); return result; }