From 86a0eeee2d173f8354e7f938be7f993e1c8ba2b4 Mon Sep 17 00:00:00 2001 From: Alexander Pacha Date: Fri, 2 Oct 2020 00:42:12 +0200 Subject: [PATCH 1/2] Removing obsolete RangeTree code for release of 3.0.0 --- IntervalTree/IntervalTree.csproj | 8 +- IntervalTree/Obsolete/IRangeTree.cs | 18 --- IntervalTree/Obsolete/RangeTree.cs | 18 --- IntervalTree/Obsolete/RangeTreeNode.cs | 18 --- IntervalTreeExamples/Obsolete/Program.cs | 82 ---------- IntervalTreeTests/Obsolete/ComparerTests.cs | 30 ---- .../Obsolete/MultipleComparerTests.cs | 34 ----- IntervalTreeTests/Obsolete/RangeTreeTests.cs | 71 --------- .../Obsolete/ReadmeExampleTests.cs | 40 ----- .../Obsolete/TreeOfDateTimeTests.cs | 90 ----------- IntervalTreeTests/Obsolete/TreeOfIntTests.cs | 64 -------- IntervalTreeTests/Obsolete/TreeSpecs.cs | 141 ------------------ 12 files changed, 4 insertions(+), 610 deletions(-) delete mode 100644 IntervalTree/Obsolete/IRangeTree.cs delete mode 100644 IntervalTree/Obsolete/RangeTree.cs delete mode 100644 IntervalTree/Obsolete/RangeTreeNode.cs delete mode 100644 IntervalTreeExamples/Obsolete/Program.cs delete mode 100644 IntervalTreeTests/Obsolete/ComparerTests.cs delete mode 100644 IntervalTreeTests/Obsolete/MultipleComparerTests.cs delete mode 100644 IntervalTreeTests/Obsolete/RangeTreeTests.cs delete mode 100644 IntervalTreeTests/Obsolete/ReadmeExampleTests.cs delete mode 100644 IntervalTreeTests/Obsolete/TreeOfDateTimeTests.cs delete mode 100644 IntervalTreeTests/Obsolete/TreeOfIntTests.cs delete mode 100644 IntervalTreeTests/Obsolete/TreeSpecs.cs diff --git a/IntervalTree/IntervalTree.csproj b/IntervalTree/IntervalTree.csproj index 47d7885..1c53dfa 100644 --- a/IntervalTree/IntervalTree.csproj +++ b/IntervalTree/IntervalTree.csproj @@ -5,7 +5,7 @@ - RangeTree + IntervalTree A generic implementation of a centered interval tree in C#. In computer science, an interval tree is an ordered tree data structure to hold intervals. Specifically, it allows one to efficiently find all intervals that overlap with any given interval or point. It is often used for windowing queries, for instance, to find all roads on a computerized map inside a rectangular viewport, or to find all visible elements inside a three-dimensional scene. True @@ -16,14 +16,14 @@ In computer science, an interval tree is an ordered tree data structure to hold https://github.com/mbuchetics/RangeTree.git git range, tree, interval - 2.1.0 + 3.0.0 RangeTree Matthias Buchetics, Alexander Pacha and others, see CONTRIBUTORS.md IntervalTree - A generic interval tree implementation in C# Renamed from RangeTree to IntervalTree, because this is what it actually is. For a full list changes at https://github.com/mbuchetics/RangeTree/releases - 2.1.0 - 2.1.0 + 3.0.0 + 3.0.0 Matthias Buchetics, Alexander Pacha diff --git a/IntervalTree/Obsolete/IRangeTree.cs b/IntervalTree/Obsolete/IRangeTree.cs deleted file mode 100644 index c647de7..0000000 --- a/IntervalTree/Obsolete/IRangeTree.cs +++ /dev/null @@ -1,18 +0,0 @@ -using System; -using IntervalTree; - -namespace RangeTree -{ - /// - /// The standard interval tree implementation. Keeps a root node and forwards all queries to it. - /// Whenever new items are added or items are removed, the tree goes temporarily "out of sync", which means that the - /// internal index is not updated immediately, but upon the next query operation. - /// - /// The type of the range. - /// The type of the data items. - [Obsolete("This interface has been renamed to IIntervalTree. Please switch to that interface. Starting with version 3.0.0, this interface will be removed.")] - public interface IRangeTree : IIntervalTree - { - - } -} diff --git a/IntervalTree/Obsolete/RangeTree.cs b/IntervalTree/Obsolete/RangeTree.cs deleted file mode 100644 index 49e6d62..0000000 --- a/IntervalTree/Obsolete/RangeTree.cs +++ /dev/null @@ -1,18 +0,0 @@ -using System; -using System.Collections.Generic; -using IntervalTree; - -namespace RangeTree -{ - [Obsolete("This class has been renamed to IntervalTree. Please switch to that class. Starting with version 3.0.0, this class will be removed.")] - public class RangeTree : IntervalTree, IRangeTree - { - public RangeTree() - { - } - - public RangeTree(IComparer comparer) : base(comparer) - { - } - } -} diff --git a/IntervalTree/Obsolete/RangeTreeNode.cs b/IntervalTree/Obsolete/RangeTreeNode.cs deleted file mode 100644 index e812a7a..0000000 --- a/IntervalTree/Obsolete/RangeTreeNode.cs +++ /dev/null @@ -1,18 +0,0 @@ -using System; -using System.Collections.Generic; -using IntervalTree; - -namespace RangeTree -{ - [Obsolete("This class has been renamed to IntervalTreeNode. Please switch to that class. Starting with version 3.0.0, this class will be removed.")] - internal class RangeTreeNode : IntervalTreeNode - { - public RangeTreeNode(IComparer comparer) : base(comparer) - { - } - - public RangeTreeNode(IList> items, IComparer comparer) : base(items, comparer) - { - } - } -} \ No newline at end of file diff --git a/IntervalTreeExamples/Obsolete/Program.cs b/IntervalTreeExamples/Obsolete/Program.cs deleted file mode 100644 index e1cf2e6..0000000 --- a/IntervalTreeExamples/Obsolete/Program.cs +++ /dev/null @@ -1,82 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Diagnostics; -using RangeTree; - -namespace RangeTreeExamples -{ - class Program - { - static void Main_Obsolete(string[] args) - { - TreeExample1(); - TreeExample2(); - Console.WriteLine("Press any key to continue..."); - Console.ReadKey(); - } - - static void TreeExample1() - { - Console.WriteLine("Example 1"); - - var tree = new RangeTree() - { - { 0, 10, "1" }, - { 20, 30, "2" }, - { 15, 17, "3" }, - { 25, 35, "4" }, - }; - - PrintQueryResult("query 1", tree.Query(5)); - PrintQueryResult("query 2", tree.Query(10)); - PrintQueryResult("query 3", tree.Query(29)); - PrintQueryResult("query 4", tree.Query(5, 15)); - PrintQueryResult("query 5", tree.Query(0, Int32.MaxValue)); - - Console.WriteLine(); - } - - static void TreeExample2() - { - Console.WriteLine("Example 2"); - - var tree = new RangeTree(); - var stopwatch = new Stopwatch(); - stopwatch.Start(); - - for (int i = 0; i < 100; i++) - { - for (int j = 0; j < 100; j++) - { - RandomTreeInsert(tree, 1000); - } - - var resultCount = tree.Query(50, 60).Count(); - Console.WriteLine("query: {0} results (tree count: {1})", resultCount, tree.Count); - } - - stopwatch.Stop(); - Console.WriteLine("elapsed time: {0}", stopwatch.Elapsed); - } - - static Random s_rnd = new Random(); - - static void RandomTreeInsert(IRangeTree tree, int limit) - { - var a = s_rnd.Next(limit); - var b = s_rnd.Next(limit); - - tree.Add(Math.Min(a, b), Math.Max(a, b), "value"); - } - - static void PrintQueryResult(string queryTitle, IEnumerable result) - { - Console.WriteLine(queryTitle); - foreach (var item in result) - { - Console.WriteLine(item); - } - } - } -} diff --git a/IntervalTreeTests/Obsolete/ComparerTests.cs b/IntervalTreeTests/Obsolete/ComparerTests.cs deleted file mode 100644 index 856b9e1..0000000 --- a/IntervalTreeTests/Obsolete/ComparerTests.cs +++ /dev/null @@ -1,30 +0,0 @@ -using NUnit.Framework; -using RangeTree; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; - -namespace RangeTreeTests -{ - [TestFixture] - public class ComparerTests - { - [Test] - public void AddingAnItem_FromIsLargerThanTo_ShouldThrowException() - { - var comparer = Comparer.Create((x, y) => x - y); - var tree = new RangeTree(comparer); - - Assert.That(() => tree.Add(2, 0, "FOO"), Throws.InstanceOf()); - } - - [Test] - public void CreatingTreeWithNullComparer_AddingAnItem_ShouldNotThrowException() - { - var tree = new RangeTree(null); - - Assert.That(() => tree.Add(0, 1, "FOO"), Throws.Nothing); - } - } -} diff --git a/IntervalTreeTests/Obsolete/MultipleComparerTests.cs b/IntervalTreeTests/Obsolete/MultipleComparerTests.cs deleted file mode 100644 index 7d06c98..0000000 --- a/IntervalTreeTests/Obsolete/MultipleComparerTests.cs +++ /dev/null @@ -1,34 +0,0 @@ -using NUnit.Framework; -using System; -using System.Linq; -using RangeTree; - -namespace RangeTreeTests -{ - [TestFixture] - public class MultipleComparerTests - { - [Test] - public void CreateTwoTrees_ProvideDifferentComparers_ExpectBothToHaveTheComparersFromConstruction() - { - var tree = new RangeTree(StringComparer.Ordinal) - { - { "a", "e", "value1" }, - { "B", "D", "value2" }, - }; - var results = tree.Query("c").ToArray(); - Assert.That(results.Length, Is.EqualTo(1)); - Assert.That(results[0], Is.EqualTo("value1")); - - tree = new RangeTree(StringComparer.OrdinalIgnoreCase) - { - { "a", "e", "value1" }, - { "B", "D", "value2" }, - }; - results = tree.Query("c").ToArray(); - Assert.That(results.Length, Is.EqualTo(2)); - Assert.That(results[0], Is.EqualTo("value1")); - Assert.That(results[1], Is.EqualTo("value2")); - } - } -} diff --git a/IntervalTreeTests/Obsolete/RangeTreeTests.cs b/IntervalTreeTests/Obsolete/RangeTreeTests.cs deleted file mode 100644 index 488da9a..0000000 --- a/IntervalTreeTests/Obsolete/RangeTreeTests.cs +++ /dev/null @@ -1,71 +0,0 @@ -using NUnit.Framework; -using RangeTree; -using System; -using System.Collections.Generic; -using System.Text; - -namespace RangeTreeTests -{ - [TestFixture] - public class RangeTreeTests - { - [Test] - public void GettingMin_InnerItems() - { - var tree = new RangeTree - { - { 1, 5, -1 }, - { 2, 5, -1 }, - { 3, 5, -1 }, - }; - - var min = tree.Min; - - Assert.That(min, Is.EqualTo(1)); - } - - [Test] - public void GettingMin_LeftRecurse() - { - var tree = new RangeTree - { - { 1, 2, -1 }, - { 3, 4, -1 } - }; - - var min = tree.Min; - - Assert.That(min, Is.EqualTo(1)); - } - - [Test] - public void GettingMax_InnerItems() - { - var tree = new RangeTree - { - { 1, 2, -1 }, - { 1, 3, -1 }, - { 1, 4, -1 }, - }; - - var max = tree.Max; - - Assert.That(max, Is.EqualTo(4)); - } - - [Test] - public void GettingMax_RightRecurse() - { - var tree = new RangeTree - { - { 1, 2, -1 }, - { 3, 4, -1 }, - { 5, 6, -1 } - }; - - var max = tree.Max; - - Assert.That(max, Is.EqualTo(6)); - } - } -} diff --git a/IntervalTreeTests/Obsolete/ReadmeExampleTests.cs b/IntervalTreeTests/Obsolete/ReadmeExampleTests.cs deleted file mode 100644 index cc0b2d9..0000000 --- a/IntervalTreeTests/Obsolete/ReadmeExampleTests.cs +++ /dev/null @@ -1,40 +0,0 @@ -using System.Linq; -using NUnit.Framework; -using RangeTree; - -namespace RangeTreeTests -{ - [TestFixture] - public class ReadmeExampleTests - { - [Test] - public void Query_CreateTreeAndExecuteQuery_ExpectCorrectElementsToBeReturned() - { - var tree = new RangeTree() - { - { 0, 10, "1" }, - { 20, 30, "2" }, - { 15, 17, "3" }, - { 25, 35, "4" }, - }; - - var results1 = tree.Query(5).ToArray(); - Assert.That(results1.Count, Is.EqualTo(1)); - Assert.That(results1[0], Is.EqualTo("1")); - - var results2 = tree.Query(10).ToArray(); - Assert.That(results2.Count, Is.EqualTo(1)); - Assert.That(results2[0], Is.EqualTo("1")); - - var results3 = tree.Query(29).ToArray(); - Assert.That(results3.Count, Is.EqualTo(2)); - Assert.That(results3[0], Is.EqualTo("2")); - Assert.That(results3[1], Is.EqualTo("4")); - - var results4 = tree.Query(5, 15).ToArray(); - Assert.That(results4.Count, Is.EqualTo(2)); - Assert.That(results4[0], Is.EqualTo("3")); - Assert.That(results4[1], Is.EqualTo("1")); - } - } -} diff --git a/IntervalTreeTests/Obsolete/TreeOfDateTimeTests.cs b/IntervalTreeTests/Obsolete/TreeOfDateTimeTests.cs deleted file mode 100644 index c81697a..0000000 --- a/IntervalTreeTests/Obsolete/TreeOfDateTimeTests.cs +++ /dev/null @@ -1,90 +0,0 @@ -using System; -using System.Linq; -using NUnit.Framework; -using RangeTree; - -namespace RangeTreeTests -{ - [TestFixture] - internal class TreeOfDateTimeTests - { - private static readonly DateTime ZERO = new DateTime(2001, 01, 01, 10, 00, 00); - - [Test] - public void BuildEmptyIntervalTree() - { - var emptyTree = new RangeTree(); - Assert.Pass(); - } - - [Test] - public void CreateEmptyIntervalTree() - { - var emptyTree = new RangeTree(); - Assert.That(emptyTree, Is.Not.Null); - } - - [Test] - public void GetIntervalByExactEndTime() - { - var tree = new RangeTree(); - tree.Add(ZERO, ZERO.AddHours(1), 100); - - var result = tree.Query(ZERO.AddHours(1)).ToList(); - Assert.That(result.Count, Is.EqualTo(1)); - } - - [Test] - public void GetIntervalByExactStartTime() - { - var tree = new RangeTree(); - tree.Add(ZERO, ZERO.AddHours(1), 100); - - var result = tree.Query(ZERO).ToList(); - Assert.That(result.Count, Is.EqualTo(1)); - } - - /// - /// 0-----5-----10------15--------20 - /// |=====100====| - /// |==200=| - /// |====300==========| - /// - [Test] - public void OverlapOnExactEndAndStart_AssertCount() - { - var tree = new RangeTree(); - tree.Add(ZERO, ZERO.AddHours(10), 100); - tree.Add(ZERO.AddHours(10), ZERO.AddHours(15), 200); - tree.Add(ZERO.AddHours(10), ZERO.AddHours(20), 200); - - var result = tree.Query(ZERO.AddHours(10)).ToList(); - Assert.That(result.Count, Is.EqualTo(3)); - } - - [Test] - public void TestSeparateIntervals() - { - var tree = new RangeTree(); - tree.Add(ZERO, ZERO.AddHours(10), 100); - tree.Add(ZERO.AddHours(20), ZERO.AddHours(30), 200); - - var result = tree.Query(ZERO.AddHours(5)).ToList(); - Assert.That(result.Count, Is.EqualTo(1)); - Assert.That(result[0], Is.EqualTo(100)); - } - - [Test] - public void TwoIntersectingIntervals() - { - var tree = new RangeTree(); - tree.Add(ZERO, ZERO.AddHours(10), 100); - tree.Add(ZERO.AddHours(3), ZERO.AddHours(30), 200); - - var result = tree.Query(ZERO.AddHours(5)).ToList(); - Assert.That(result.Count, Is.EqualTo(2)); - Assert.That(result[0], Is.EqualTo(100)); - Assert.That(result[1], Is.EqualTo(200)); - } - } -} \ No newline at end of file diff --git a/IntervalTreeTests/Obsolete/TreeOfIntTests.cs b/IntervalTreeTests/Obsolete/TreeOfIntTests.cs deleted file mode 100644 index e9eb5cf..0000000 --- a/IntervalTreeTests/Obsolete/TreeOfIntTests.cs +++ /dev/null @@ -1,64 +0,0 @@ -using System.Linq; -using NUnit.Framework; -using RangeTree; - -namespace RangeTreeTests -{ - [TestFixture] - internal class TreeOfIntTests - { - [Test] - public void BuildEmptyIntervalTree() - { - var emptyTree = new RangeTree(); - Assert.Pass(); - } - - [Test] - public void CreateEmptyIntervalTree() - { - var emptyTree = new RangeTree(); - Assert.That(emptyTree, Is.Not.Null); - } - - [Test] - public void TestSeparateIntervals() - { - var tree = new RangeTree(); - tree.Add(0, 10, 100); - tree.Add(20, 30, 200); - - var result = tree.Query(5).ToList(); - Assert.That(result.Count, Is.EqualTo(1)); - Assert.That(result[0], Is.EqualTo(100)); - } - - [Test] - public void TwoIntersectingIntervals() - { - var tree = new RangeTree(); - tree.Add(0, 10, 100); - tree.Add(3, 30, 200); - - var result = tree.Query(5).ToList(); - Assert.That(result.Count, Is.EqualTo(2)); - Assert.That(result[0], Is.EqualTo(100)); - Assert.That(result[1], Is.EqualTo(200)); - } - - [Test] - public void QueryOutOfSyncTree_ExpectObsoleteResults() - { - var tree = new RangeTree(); - tree.Add(0, 10, 100); - - var result = tree.Query(5).ToList(); - Assert.That(result.Count, Is.EqualTo(1)); - - tree.Add(3, 30, 200); - - result = tree.Query(5).ToList(); - Assert.That(result.Count, Is.EqualTo(2)); - } - } -} \ No newline at end of file diff --git a/IntervalTreeTests/Obsolete/TreeSpecs.cs b/IntervalTreeTests/Obsolete/TreeSpecs.cs deleted file mode 100644 index 66d76ea..0000000 --- a/IntervalTreeTests/Obsolete/TreeSpecs.cs +++ /dev/null @@ -1,141 +0,0 @@ -using NUnit.Framework; -using System; -using System.Collections; -using System.Collections.Generic; -using System.Diagnostics; -using System.Linq; -using RangeTree; - -namespace RangeTreeTests -{ - [TestFixture] - public class If_the_user_searches_for_overlapping_entries_in_an_interval_tree : Spec - { - private static IEnumerable> TestEntries() - { - yield return Tuple.Create(1400, 1500); - yield return Tuple.Create(0100, 0130); - yield return Tuple.Create(1700, 1800); - yield return Tuple.Create(0230, 0240); - yield return Tuple.Create(0530, 0540); - yield return Tuple.Create(2330, 2400); - yield return Tuple.Create(0700, 0800); - yield return Tuple.Create(0900, 1000); - yield return Tuple.Create(0000, 0100); - yield return Tuple.Create(0540, 0700); - yield return Tuple.Create(1800, 2130); - yield return Tuple.Create(2130, 2131); - yield return Tuple.Create(0200, 0230); - } - - private static IEnumerable TestCases - { - get - { - yield return new TestCaseData(Tuple.Create(2000, 2300)).Returns(2); - yield return new TestCaseData(Tuple.Create(0000, 0100)).Returns(2); - yield return new TestCaseData(Tuple.Create(0000, 0000)).Returns(1); - yield return new TestCaseData(Tuple.Create(0100, 0100)).Returns(2); - yield return new TestCaseData(Tuple.Create(1000, 1100)).Returns(1); - yield return new TestCaseData(Tuple.Create(1030, 1400)).Returns(1); - yield return new TestCaseData(Tuple.Create(0150, 0155)).Returns(0); - yield return new TestCaseData(Tuple.Create(2132, 2133)).Returns(0); - yield return new TestCaseData(Tuple.Create(1030, 1350)).Returns(0); - yield return new TestCaseData(Tuple.Create(0000, 2359)).Returns(13); - } - } - - [Test] - [TestCaseSource("TestCases")] - public int CorrectQuery_BuiltInOrder(Tuple value) - { - var tree = CreateTree(TestEntries().OrderBy(interval => interval.Item1)); - return tree - .Query(value.Item1, value.Item2) - .Count(); - } - - [Test] - [TestCaseSource("TestCases")] - public int CorrectQuery_BuiltInReverseOrder(Tuple value) - { - var tree = CreateTree(TestEntries().OrderBy(interval => interval.Item1).Reverse()); - return tree - .Query(value.Item1, value.Item2) - .Count(); - } - - [Test] - [TestCaseSource("TestCases")] - public int CorrectQuery_BuiltRandomly(Tuple value) - { - var tree = CreateTree(TestEntries()); - return tree - .Query(value.Item1, value.Item2) - .Count(); - } - - private static IRangeTree CreateTree(IEnumerable> entries) - { - var tree = new RangeTree(); - - foreach (var interval in entries) - { - tree.Add(interval.Item1, interval.Item2, "value"); - } - - return tree; - } - } - - /// - /// Abstract helper class to make nunit tests more readable. - /// - [DebuggerStepThrough] - [DebuggerNonUserCode] - public class Spec - { - [DebuggerStepThrough] - [OneTimeSetUp] - public void SetUp() - { - EstablishContext(); - BecauseOf(); - } - - [DebuggerStepThrough] - [OneTimeTearDown] - public void TearDown() - { - Cleanup(); - } - - /// - /// Test setup. Place your initialization code here. - /// - [DebuggerStepThrough] - protected virtual void EstablishContext() { } - - /// - /// Test run. Place the tested method / action here. - /// - [DebuggerStepThrough] - protected virtual void BecauseOf() { } - - /// - /// Test clean. Close/delete files, close database connections .. - /// - [DebuggerStepThrough] - protected virtual void Cleanup() { } - - /// - /// Creates an Action delegate. - /// - /// Method the shall be created as delegate. - /// A delegate of type - protected Action Invoking(Action func) - { - return func; - } - } -} From da6ab63f87f962c0d0c2eaf96c4ba0476a38fd84 Mon Sep 17 00:00:00 2001 From: Alexander Pacha Date: Mon, 5 Oct 2020 12:26:52 +0200 Subject: [PATCH 2/2] Updating release notes for version 3.0.0 --- IntervalTree/IntervalTree.csproj | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/IntervalTree/IntervalTree.csproj b/IntervalTree/IntervalTree.csproj index 1c53dfa..20b8eb2 100644 --- a/IntervalTree/IntervalTree.csproj +++ b/IntervalTree/IntervalTree.csproj @@ -20,7 +20,8 @@ In computer science, an interval tree is an ordered tree data structure to hold RangeTree Matthias Buchetics, Alexander Pacha and others, see CONTRIBUTORS.md IntervalTree - A generic interval tree implementation in C# - Renamed from RangeTree to IntervalTree, because this is what it actually is. + BREAKING CHANGES: Removing RangeTree code after is has been renamed to IntervalTree in version 2.1.0. +Make sure that you upgrade to version 2.1.0 first and that you have no more errors before upgrading to this version. This version contains no new features, but fixes the misleading name "RangeTree" when in fact it is an Interval tree. For a full list changes at https://github.com/mbuchetics/RangeTree/releases 3.0.0 3.0.0