public void TestRemoveValue() { var set = new TreeSet <int>(4, Enumerable.Range(0, 10), comparer: null); Assert.False(set.Remove(-1)); Assert.Equal(10, set.Count); Assert.True(set.Remove(3)); Assert.Equal(9, set.Count); }
public void TestRemoveEdgeCase() { var equalityComparer = EqualityComparer <int> .Default; Func <int, int> getHashCode = value => Math.Abs(value) < 5 ? 0 : 1; var set = new TreeSet <int>(branchingFactor: 4, comparer: new SubsetHashCodeEqualityComparer <int>(equalityComparer, getHashCode)); set.UnionWith(Enumerable.Range(0, 10)); Assert.True(set.Remove(4)); Assert.False(set.Remove(4)); }
private static void Main() { var nameColl = new HashSet <PersonLockstepCollections>(new PersonLockstepCollections.NameEqualityComparer()); var dateColl = new TreeSet <PersonLockstepCollections>(new PersonLockstepCollections.DateComparer()); MakeLockstep(nameColl, dateColl); var p1 = new PersonLockstepCollections("Peter", 19620625); var p2 = new PersonLockstepCollections("Carsten", 19640627); var p3 = new PersonLockstepCollections("Carsten", 19640628); nameColl.Add(p1); nameColl.Add(p2); dateColl.Add(p3); Console.WriteLine($"dateColl = {dateColl}"); Console.WriteLine($"nameColl = {nameColl}"); dateColl.Remove(p1); Console.WriteLine($"dateColl = {dateColl}"); Console.WriteLine($"nameColl = {nameColl}"); dateColl.Clear(); Console.WriteLine($"dateColl = {dateColl}"); Console.WriteLine($"nameColl = {nameColl}"); }
/// <summary>Removes a sequence and its associated value.</summary> /// <remarks>Removes a sequence and its associated value.</remarks> public void RemoveSequence(long sequence) { lock (locker) { sequences.Remove(sequence); } }
public virtual void RemoveSequence(long sequence) { lock (this) { sequences.Remove(sequence); } }
public bool HasIntersections() { while (!events.IsEmpty) { var currentEvent = events.DeleteMin(); switch (currentEvent.Type) { case EventType.SegmentStart: sweepline.Add(currentEvent.Segment); int i = sweepline.IndexOf(currentEvent.Segment); if (i > 0 && currentEvent.Segment.IntersectsWith(sweepline[0])) { return(true); } if (i < sweepline.Count - 1 && currentEvent.Segment.IntersectsWith(sweepline[i + 1])) { return(true); } break; case EventType.SegmentEnd: int j = sweepline.IndexOf(currentEvent.Segment); if (j > 0 && j < sweepline.Count - 1 && sweepline[j - 1].IntersectsWith(sweepline[j + 1])) { return(true); } sweepline.Remove(currentEvent.Segment); break; } } return(false); }
public void TriggeredJobComplete(Trigger trigger, IScheduledJob job, SchedulerInstruction triggerInstCode) { lock (_triggerLock) { JobWrapper jw = _jobsDictionary[job.Name] as JobWrapper; TriggerWrapper tw = _triggersDictionary[trigger.Name] as TriggerWrapper; // even if it was deleted, there may be cleanup to do _blockedJobs.Remove(job.Name); // check for trigger deleted during execution... if (tw != null) { if (triggerInstCode == SchedulerInstruction.DeleteTrigger) { //log.Debug("Deleting trigger"); NullableDateTime d = trigger.GetNextFireTimeUtc(); if (!d.HasValue) { // double check for possible reschedule within job // execution, which would cancel the need to delete... d = tw.Trigger.GetNextFireTimeUtc(); if (!d.HasValue) { RemoveTrigger(trigger.Name); } else { log.Debug("Deleting cancelled - trigger still active"); } } else { RemoveTrigger(trigger.Name); } } else if (triggerInstCode == SchedulerInstruction.SetTriggerComplete) { tw.State = InternalTriggerState.Complete; _timeTriggers.Remove(tw); } else if (triggerInstCode == SchedulerInstruction.SetTriggerError) { log.Info(string.Format(CultureInfo.InvariantCulture, "Trigger {0} set to ERROR state.", trigger.Name)); tw.State = InternalTriggerState.Error; } else if (triggerInstCode == SchedulerInstruction.SetAllJobTriggersError) { log.Info(string.Format(CultureInfo.InvariantCulture, "All triggers of Job {0} set to ERROR state.", trigger.Name)); SetAllTriggersOfJobToState(trigger.Name, InternalTriggerState.Error); } else if (triggerInstCode == SchedulerInstruction.SetAllJobTriggersComplete) { SetAllTriggersOfJobToState(trigger.Name, InternalTriggerState.Complete); } } } }
public bool RemoveTrigger(string triggerName, bool deleteOrphanedJob) { bool found; lock (_triggerLock) { // remove from triggers object tempObject; tempObject = _triggersDictionary[triggerName]; _triggersDictionary.Remove(triggerName); found = (tempObject == null) ? false : true; if (found) { TriggerWrapper tw = null; // remove from triggers array for (int i = 0; i < _triggers.Count; ++i) { tw = _triggers[i] as TriggerWrapper; if (triggerName.Equals(tw.Name)) { _triggers.RemoveAt(i); break; } } _timeTriggers.Remove(tw); JobWrapper jw = _jobsDictionary[tw.Trigger.JobName] as JobWrapper; Trigger[] triggers = GetTriggersForJob(tw.Trigger.JobName); if ((triggers == null || triggers.Length == 0) && deleteOrphanedJob) { RemoveJob(tw.Trigger.JobName); } } } return(found); }
public void TestTreeSetSimpleOperations() { ISortedSet <int> set = new TreeSet <int>(); var count = 0; foreach (var item in set) { count++; } Assert.True(count == 0); Assert.True(set.Count == 0); set.Add(10); set.Add(20); set.Add(30); set.Add(5); set.Add(1); Assert.True(set.Contains(20)); Assert.False(set.Contains(100)); Assert.Equal(5, set.Count); Assert.Equal(30, set.Max); Assert.Equal(1, set.Min); var list = new List <int>(); foreach (var item in set) { list.Add(item); } Assert.True(list.Count == set.Count); foreach (var item in list) { Assert.True(set.Contains(item)); } var array = new int[5]; set.CopyTo(array, 0); foreach (var item in array) { Assert.True(set.Contains(item)); } Assert.True(set.Remove(5)); Assert.Equal(4, set.Count); Assert.False(set.Contains(5)); set.RemoveMin(); Assert.Equal(3, set.Count); Assert.False(set.Contains(1)); set.Clear(); Assert.Equal(0, set.Count); }
internal void ProcessLeavePvs(LeavePvs u) { if (u.Delete) { Entities[u.Index] = null; _nonNullEnts.Remove(u.Index); } else { Entities[u.Index].InPvs = false; } }
/// <summary> /// Adds an /// <see cref="Org.Apache.Http.Cookie.Cookie">HTTP cookie</see> /// , replacing any existing equivalent cookies. /// If the given cookie has already expired it will not be added, but existing /// values will still be removed. /// </summary> /// <param name="cookie"> /// the /// <see cref="Org.Apache.Http.Cookie.Cookie">cookie</see> /// to be added /// </param> /// <seealso cref="AddCookies(Org.Apache.Http.Cookie.Cookie[])">AddCookies(Org.Apache.Http.Cookie.Cookie[]) /// </seealso> public virtual void AddCookie(Org.Apache.Http.Cookie.Cookie cookie) { lock (this) { if (cookie != null) { // first remove any old cookie that is equivalent cookies.Remove(cookie); if (!cookie.IsExpired(new DateTime())) { cookies.AddItem(cookie); } } } }
private PlotLane NextFreeLane() { PlotLane p = CreateLane(); if (freePositions.IsEmpty()) { p.position = positionsAllocated++; } else { int min = freePositions.First(); p.position = min; freePositions.Remove(min); } return(p); }
public void Build() { //htree.Clear(); htree = new TreeDictionary <double, ISorted <Edge <T> > >(dc); TreeSet <Edge <T> > vtree = new TreeSet <Edge <T> >(lc); double lastx = Double.NegativeInfinity; foreach (KeyValuePair <EndPoint, Edge <T> > p in endpoints) { if (dc.Compare(p.Key.x, lastx) > 0) { //Put an empty snapshot at -infinity! htree[lastx] = (ISorted <Edge <T> >)(vtree.Snapshot()); lc.X = lastx = p.Key.x; lc.compareToRight = false; } if (p.Key.start) { if (!lc.compareToRight) { lc.compareToRight = true; } Debug.Assert(vtree.Check()); bool chk = vtree.Add(p.Value); Debug.Assert(vtree.Check()); Debug.Assert(chk, "edge was not added!", "" + p.Value); } else { Debug.Assert(!lc.compareToRight); Debug.Assert(vtree.Check("C")); bool chk = vtree.Remove(p.Value); Debug.Assert(vtree.Check("D")); Debug.Assert(chk, "edge was not removed!", "" + p.Value); } } lc.compareToRight = true; htree[lastx] = (TreeSet <Edge <T> >)(vtree.Snapshot()); built = true; }
private static void TestBinaryTree() { structures.common.ISet <int> tree = new TreeSet <int>(); tree.Add(5); tree.Add(6); tree.Add(9); tree.Add(1); tree.Add(4); tree.Add(8); tree.Add(-15); tree.Remove(1); Console.Out.WriteLine(tree.Contains(1)); Console.Out.WriteLine(tree.Contains(9)); foreach (var elem in tree) { Console.Out.WriteLine(elem); } }
static void Main(String[] args) { ICollection <Person> nameColl = new HashSet <Person>(new Person.NameEqualityComparer()); ICollection <Person> dateColl = new TreeSet <Person>(new Person.DateComparer()); MakeLockstep(nameColl, dateColl); Person p1 = new Person("Peter", 19620625), p2 = new Person("Carsten", 19640627), p3 = new Person("Carsten", 19640628); nameColl.Add(p1); nameColl.Add(p2); dateColl.Add(p3); Console.WriteLine("dateColl = {0}", dateColl); Console.WriteLine("nameColl = {0}", nameColl); dateColl.Remove(p1); Console.WriteLine("dateColl = {0}", dateColl); Console.WriteLine("nameColl = {0}", nameColl); dateColl.Clear(); Console.WriteLine("dateColl = {0}", dateColl); Console.WriteLine("nameColl = {0}", nameColl); }
/// <summary> /// Removes the excluded date. /// </summary> /// <param name="dateToRemoveUtc">The date to remove.</param> public virtual void RemoveExcludedDate(DateTime dateToRemoveUtc) { DateTime date = dateToRemoveUtc.Date; dates.Remove(date); }
/// <summary>Removes a sequence and its associated value.</summary> /// <remarks>Removes a sequence and its associated value.</remarks> public void RemoveSequence(long sequence) { _lock.EnterWriteLock(); sequences.Remove(sequence); _lock.ExitWriteLock(); }
private void UpdateNextGroup(int topN, ShardIter <T> shard) { while (shard.Iter.MoveNext()) { ISearchGroup <T> group = shard.Next(); MergedGroup <T> mergedGroup = groupsSeen.ContainsKey(group.GroupValue) ? groupsSeen[group.GroupValue] : null; bool isNew = mergedGroup == null; //System.out.println(" next group=" + (group.groupValue == null ? "null" : ((BytesRef) group.groupValue).utf8ToString()) + " sort=" + Arrays.toString(group.sortValues)); if (isNew) { // Start a new group: //System.out.println(" new"); mergedGroup = new MergedGroup <T>(group.GroupValue); mergedGroup.MinShardIndex = shard.ShardIndex; Debug.Assert(group.SortValues != null); mergedGroup.TopValues = group.SortValues; groupsSeen[group.GroupValue] = mergedGroup; mergedGroup.IsInQueue = true; queue.Add(mergedGroup); } else if (mergedGroup.IsProcessed) { // This shard produced a group that we already // processed; move on to next group... continue; } else { //System.out.println(" old"); bool competes = false; for (int compIDX = 0; compIDX < groupComp.Comparers.Length; compIDX++) { int cmp = groupComp.Reversed[compIDX] * groupComp.Comparers[compIDX].CompareValues(group.SortValues[compIDX], mergedGroup.TopValues[compIDX]); if (cmp < 0) { // Definitely competes competes = true; break; } else if (cmp > 0) { // Definitely does not compete break; } else if (compIDX == groupComp.Comparers.Length - 1) { if (shard.ShardIndex < mergedGroup.MinShardIndex) { competes = true; } } } //System.out.println(" competes=" + competes); if (competes) { // Group's sort changed -- remove & re-insert if (mergedGroup.IsInQueue) { queue.Remove(mergedGroup); } mergedGroup.TopValues = group.SortValues; mergedGroup.MinShardIndex = shard.ShardIndex; queue.Add(mergedGroup); mergedGroup.IsInQueue = true; } } mergedGroup.Shards.Add(shard); break; } // Prune un-competitive groups: while (queue.Count > topN) { MergedGroup <T> group = queue.Last(); queue.Remove(group); //System.out.println("PRUNE: " + group); group.IsInQueue = false; } }
/** * @see <a href="http://en.wikipedia.org/wiki/Sweep_line_algorithm">Sweep line algorithm</a> */ private void SweepCleanColumns(CT_Cols cols, CT_Col[] flattenedColsArray, CT_Col overrideColumn) { List <CT_Col> flattenedCols = new List <CT_Col>(flattenedColsArray); TreeSet <CT_Col> currentElements = new TreeSet <CT_Col>(CTColComparator.BY_MAX); IEnumerator <CT_Col> flIter = flattenedCols.GetEnumerator(); CT_Col haveOverrideColumn = null; long lastMaxIndex = 0; long currentMax = 0; IList <CT_Col> toRemove = new List <CT_Col>(); int pos = -1; //while (flIter.hasNext()) while ((pos + 1) < flattenedCols.Count) { //CTCol col = flIter.next(); pos++; CT_Col col = flattenedCols[pos]; long currentIndex = col.min; long colMax = col.max; long nextIndex = (colMax > currentMax) ? colMax : currentMax; //if (flIter.hasNext()) { if ((pos + 1) < flattenedCols.Count) { //nextIndex = flIter.next().getMin(); nextIndex = flattenedCols[pos + 1].min; //flIter.previous(); } IEnumerator <CT_Col> iter = currentElements.GetEnumerator(); toRemove.Clear(); while (iter.MoveNext()) { CT_Col elem = iter.Current; if (currentIndex <= elem.max) { break; // all passed elements have been purged } toRemove.Add(elem); } foreach (CT_Col rc in toRemove) { currentElements.Remove(rc); } if (!(currentElements.Count == 0) && lastMaxIndex < currentIndex) { // we need to process previous elements first CT_Col[] copyCols = new CT_Col[currentElements.Count]; currentElements.CopyTo(copyCols); insertCol(cols, lastMaxIndex, currentIndex - 1, copyCols, true, haveOverrideColumn); } currentElements.Add(col); if (colMax > currentMax) { currentMax = colMax; } if (col.Equals(overrideColumn)) { haveOverrideColumn = overrideColumn; } while (currentIndex <= nextIndex && !(currentElements.Count == 0)) { NPOI.Util.Collections.HashSet <CT_Col> currentIndexElements = new NPOI.Util.Collections.HashSet <CT_Col>(); long currentElemIndex; { // narrow scope of currentElem CT_Col currentElem = currentElements.First(); currentElemIndex = currentElem.max; currentIndexElements.Add(currentElem); while (true) { CT_Col higherElem = currentElements.Higher(currentElem); if (higherElem == null || higherElem.max != currentElemIndex) { break; } currentElem = higherElem; currentIndexElements.Add(currentElem); if (colMax > currentMax) { currentMax = colMax; } if (col.Equals(overrideColumn)) { haveOverrideColumn = overrideColumn; } } } //if (currentElemIndex < nextIndex || !flIter.hasNext()) { if (currentElemIndex < nextIndex || !((pos + 1) < flattenedCols.Count)) { CT_Col[] copyCols = new CT_Col[currentElements.Count]; currentElements.CopyTo(copyCols); insertCol(cols, currentIndex, currentElemIndex, copyCols, true, haveOverrideColumn); //if (flIter.hasNext()) { if ((pos + 1) < flattenedCols.Count) { if (nextIndex > currentElemIndex) { //currentElements.removeAll(currentIndexElements); foreach (CT_Col rc in currentIndexElements) { currentElements.Remove(rc); } if (currentIndexElements.Contains(overrideColumn)) { haveOverrideColumn = null; } } } else { //currentElements.removeAll(currentIndexElements); foreach (CT_Col rc in currentIndexElements) { currentElements.Remove(rc); } if (currentIndexElements.Contains(overrideColumn)) { haveOverrideColumn = null; } } lastMaxIndex = currentIndex = currentElemIndex + 1; } else { lastMaxIndex = currentIndex; currentIndex = nextIndex + 1; } } } SortColumns(cols); }
/// <summary> /// adapted from /// http://www.baptiste-wicht.com/2010/04/closest-pair-of-point-plane-sweep-algorithm/ /// </summary> /// <param name="points"></param> /// <returns></returns> static P[] ClosestPair(IEnumerable <P> points) { var closestPair = new P[2]; // When we start the min distance is the infinity var crtMinDist = MaxDistance; // Get the points and sort them var sorted = new List <P>(); sorted.AddRange(points); sorted.Sort(XComparer.XCompare); // When we start the left most candidate is the first one var leftMostCandidateIndex = 0; // Vertically sorted set of candidates var candidates = new TreeSet <P>(new YComparer()); // C5 data structure // For each point from left to right foreach (var current in sorted) { // Shrink the candidates while (current.X - sorted[leftMostCandidateIndex].X > crtMinDist) { candidates.Remove(sorted[leftMostCandidateIndex]); leftMostCandidateIndex++; } // Compute the y head and the y tail of the candidates set var head = new P { X = current.X, Y = checked (current.Y - crtMinDist) }; var tail = new P { X = current.X, Y = checked (current.Y + crtMinDist) }; // We take only the interesting candidates in the y axis var subset = candidates.RangeFromTo(head, tail); foreach (var point in subset) { var distance = current.Distance(point); if (distance < 0) { throw new ApplicationException("number overflow"); } // Simple min computation if (distance < crtMinDist) { crtMinDist = distance; closestPair[0] = current; closestPair[1] = point; } } // The current point is now a candidate candidates.Add(current); } return(closestPair); }
public void Remove(Segment s) { PositionOrdered.Remove(s); WidthOrdered.Remove(s); }
public void TestTreeSetRandomOperations() { for (int j = 0; j < 10; j++) { ISortedSet <int> set = new TreeSet <int>(); Random randomValue = new Random((int)(DateTime.Now.Ticks & 0x0000FFFF)); List <int> list = new List <int>(); int testNumber = 1000; while (set.Count < testNumber) { int v = randomValue.Next(); if (!set.Contains(v)) { set.Add(v); list.Add(v); } } int count = 0; foreach (var item in set) { Assert.True(list.Contains(item)); count++; } Assert.True(count == set.Count); Assert.Equal(testNumber, set.Count); Random randomIndex = new Random((int)(DateTime.Now.Ticks & 0x0000FFFF)); for (int i = 0; i < 100; i++) { int index = randomIndex.Next(); index = index < 0 ? (-index) : index; index %= testNumber; int testValue = list[index]; Assert.True(set.Contains(testValue)); } for (int i = 0; i < 100; i++) { int min = list.Min(); Assert.Equal(min, set.Min); set.RemoveMin(); Assert.Equal(testNumber - i - 1, set.Count); Assert.False(set.Contains(min)); list.Remove(min); } testNumber -= 100; for (int i = 0; i < 100; i++) { int max = list.Max(); Assert.Equal(max, set.Max); set.RemoveMax(); Assert.Equal(testNumber - i - 1, set.Count); Assert.False(set.Contains(max)); list.Remove(max); } testNumber -= 100; for (int i = 0; i < 100; i++) { int index = randomIndex.Next(); index = index < 0 ? (-index) : index; index %= testNumber - i; int toRemove = list[index]; Assert.True(set.Contains(toRemove)); Assert.True(set.Remove(toRemove)); Assert.False(set.Contains(toRemove)); Assert.Equal(testNumber - i - 1, set.Count); list.Remove(toRemove); } } }
public void Remove(T result) { _results.Remove(result); }