Skip to content

Commit

Permalink
Merge pull request #25 from mbuchetics/rename-intervaltree
Browse files Browse the repository at this point in the history
Renamed project from RangeTree to IntervalTree
  • Loading branch information
apacha authored Sep 20, 2020
2 parents 8375f2e + fee2118 commit d13e0d7
Show file tree
Hide file tree
Showing 28 changed files with 737 additions and 126 deletions.
13 changes: 8 additions & 5 deletions RangeTree.sln → IntervalTree.sln
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.26430.14
# Visual Studio Version 16
VisualStudioVersion = 16.0.30011.22
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RangeTree", "RangeTree\RangeTree.csproj", "{A12CFD40-6EA9-459A-84AD-2DF944E332CE}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "IntervalTree", "IntervalTree\IntervalTree.csproj", "{A12CFD40-6EA9-459A-84AD-2DF944E332CE}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RangeTreeExamples", "RangeTreeExamples\RangeTreeExamples.csproj", "{A2ECC374-8BB1-4B8C-AF67-062595E6FBDB}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "IntervalTreeExamples", "IntervalTreeExamples\IntervalTreeExamples.csproj", "{A2ECC374-8BB1-4B8C-AF67-062595E6FBDB}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RangeTreeTests", "RangeTreeTests\RangeTreeTests.csproj", "{087BD1DE-623A-4C8B-A41B-E99938EC9296}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "IntervalTreeTests", "IntervalTreeTests\IntervalTreeTests.csproj", "{087BD1DE-623A-4C8B-A41B-E99938EC9296}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand All @@ -31,4 +31,7 @@ Global
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {ECFD1131-4EBD-489E-81BE-550DBF8805EF}
EndGlobalSection
EndGlobal
12 changes: 6 additions & 6 deletions RangeTree/IRangeTree.cs → IntervalTree/IIntervalTree.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
using System.Collections.Generic;

namespace RangeTree
namespace IntervalTree
{
/// <summary>
/// The standard range tree implementation. Keeps a root node and forwards all queries to it.
/// 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.
/// </summary>
/// <typeparam name="TKey">The type of the range.</typeparam>
/// <typeparam name="TValue">The type of the data items.</typeparam>
public interface IRangeTree<TKey, TValue> : IEnumerable<RangeValuePair<TKey, TValue>>
public interface IIntervalTree<TKey, TValue> : IEnumerable<RangeValuePair<TKey, TValue>>
{
/// <summary>
/// Returns all items contained in the tree.
Expand All @@ -30,12 +30,12 @@ public interface IRangeTree<TKey, TValue> : IEnumerable<RangeValuePair<TKey, TVa
/// Performs a range query. All items with overlapping ranges are returned.
/// </summary>
IEnumerable<TValue> Query(TKey from, TKey to);

/// <summary>
/// Adds the specified item.
/// </summary>
void Add(TKey from, TKey to, TValue value);

/// <summary>
/// Removes the specified item.
/// </summary>
Expand All @@ -51,4 +51,4 @@ public interface IRangeTree<TKey, TValue> : IEnumerable<RangeValuePair<TKey, TVa
/// </summary>
void Clear();
}
}
}
20 changes: 10 additions & 10 deletions RangeTree/RangeTree.cs → IntervalTree/IntervalTree.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
using System.Collections.Generic;
using System.Linq;

namespace RangeTree
namespace IntervalTree
{
public class RangeTree<TKey, TValue> : IRangeTree<TKey, TValue>
public class IntervalTree<TKey, TValue> : IIntervalTree<TKey, TValue>
{
private RangeTreeNode<TKey, TValue> root;
private IntervalTreeNode<TKey, TValue> root;
private List<RangeValuePair<TKey, TValue>> items;
private readonly IComparer<TKey> comparer;
private bool isInSync;
Expand Down Expand Up @@ -43,16 +43,16 @@ public TKey Min
/// <summary>
/// Initializes an empty tree.
/// </summary>
public RangeTree() : this(Comparer<TKey>.Default) { }
public IntervalTree() : this(Comparer<TKey>.Default) { }

/// <summary>
/// Initializes an empty tree.
/// </summary>
public RangeTree(IComparer<TKey> comparer)
public IntervalTree(IComparer<TKey> comparer)
{
this.comparer = comparer ?? Comparer<TKey>.Default;
isInSync = true;
root = new RangeTreeNode<TKey, TValue>(this.comparer);
root = new IntervalTreeNode<TKey, TValue>(this.comparer);
items = new List<RangeValuePair<TKey, TValue>>();
}

Expand Down Expand Up @@ -95,7 +95,7 @@ public void Remove(IEnumerable<TValue> items)

public void Clear()
{
root = new RangeTreeNode<TKey, TValue>(comparer);
root = new IntervalTreeNode<TKey, TValue>(comparer);
items = new List<RangeValuePair<TKey, TValue>>();
isInSync = true;
}
Expand All @@ -114,10 +114,10 @@ private void Rebuild()
return;

if (items.Count > 0)
root = new RangeTreeNode<TKey, TValue>(items, comparer);
root = new IntervalTreeNode<TKey, TValue>(items, comparer);
else
root = new RangeTreeNode<TKey, TValue>(comparer);
root = new IntervalTreeNode<TKey, TValue>(comparer);
isInSync = true;
}
}
}
}
15 changes: 7 additions & 8 deletions RangeTree/RangeTree.csproj → IntervalTree/IntervalTree.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>netstandard1.2;netstandard2.0;net45</TargetFrameworks>
<TargetFrameworks>netstandard1.2;netstandard2.0;netstandard2.1;net45</TargetFrameworks>
</PropertyGroup>

<PropertyGroup>
Expand All @@ -10,21 +10,20 @@
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.</Description>
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
<PackageRequireLicenseAcceptance>False</PackageRequireLicenseAcceptance>
<Copyright>Copyright (c) 2019, Matthias Buchetics and Alexander Pacha</Copyright>
<Copyright>Copyright (c) 2020, Matthias Buchetics and Alexander Pacha</Copyright>
<PackageLicenseUrl>https://github.com/mbuchetics/RangeTree/blob/master/LICENSE</PackageLicenseUrl>
<PackageProjectUrl>https://github.com/mbuchetics/RangeTree</PackageProjectUrl>
<RepositoryUrl>https://github.com/mbuchetics/RangeTree.git</RepositoryUrl>
<RepositoryType>git</RepositoryType>
<PackageTags>range, tree, interval</PackageTags>
<Version>2.0.1</Version>
<Version>2.1.0</Version>
<PackageId>RangeTree</PackageId>
<Authors>Matthias Buchetics, Alexander Pacha and others, see CONTRIBUTORS.md</Authors>
<Product>RangeTree - A generic interval tree implementation in C#</Product>
<PackageReleaseNotes>Major overhaul by Erik Domke to a nice and cleaner interface.
Support for async version has been dropped and Rebuild / AutoRebuild functionality is now only internal (there was no reason for making it accessible from the outside anyway).
<Product>IntervalTree - A generic interval tree implementation in C#</Product>
<PackageReleaseNotes>Renamed from RangeTree to IntervalTree, because this is what it actually is.
For a full list changes at https://github.com/mbuchetics/RangeTree/releases</PackageReleaseNotes>
<AssemblyVersion>2.0.1</AssemblyVersion>
<FileVersion>2.0.1</FileVersion>
<AssemblyVersion>2.1.0</AssemblyVersion>
<FileVersion>2.1.0</FileVersion>
<Company>Matthias Buchetics, Alexander Pacha</Company>
</PropertyGroup>

Expand Down
21 changes: 10 additions & 11 deletions RangeTree/RangeTreeNode.cs → IntervalTree/IntervalTreeNode.cs
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
using System;
using System.Collections.Generic;
using System.Collections.Generic;
using System.Linq;

namespace RangeTree
namespace IntervalTree
{
/// <summary>
/// A node of the range tree. Given a list of items, it builds
/// its subtree. Also contains methods to query the subtree.
/// Basically, all interval tree logic is here.
/// </summary>
internal class RangeTreeNode<TKey, TValue> : IComparer<RangeValuePair<TKey, TValue>>
internal class IntervalTreeNode<TKey, TValue> : IComparer<RangeValuePair<TKey, TValue>>
{
private readonly TKey center;
private readonly RangeTreeNode<TKey, TValue> leftNode;
private readonly RangeTreeNode<TKey, TValue> rightNode;
private readonly IntervalTreeNode<TKey, TValue> leftNode;
private readonly IntervalTreeNode<TKey, TValue> rightNode;
private readonly RangeValuePair<TKey, TValue>[] items;

private readonly IComparer<TKey> comparer;
Expand All @@ -22,7 +21,7 @@ internal class RangeTreeNode<TKey, TValue> : IComparer<RangeValuePair<TKey, TVal
/// Initializes an empty node.
/// </summary>
/// <param name="comparer">The comparer used to compare two items.</param>
public RangeTreeNode(IComparer<TKey> comparer)
public IntervalTreeNode(IComparer<TKey> comparer)
{
this.comparer = comparer ?? Comparer<TKey>.Default;

Expand All @@ -37,7 +36,7 @@ public RangeTreeNode(IComparer<TKey> comparer)
/// </summary>
/// <param name="items">The items that should be added to this node</param>
/// <param name="comparer">The comparer used to compare two items.</param>
public RangeTreeNode(IList<RangeValuePair<TKey, TValue>> items, IComparer<TKey> comparer)
public IntervalTreeNode(IList<RangeValuePair<TKey, TValue>> items, IComparer<TKey> comparer)
{
this.comparer = comparer ?? Comparer<TKey>.Default;

Expand Down Expand Up @@ -88,9 +87,9 @@ public RangeTreeNode(IList<RangeValuePair<TKey, TValue>> items, IComparer<TKey>

// create left and right nodes, if there are any items
if (left.Count > 0)
leftNode = new RangeTreeNode<TKey, TValue>(left, this.comparer);
leftNode = new IntervalTreeNode<TKey, TValue>(left, this.comparer);
if (right.Count > 0)
rightNode = new RangeTreeNode<TKey, TValue>(right, this.comparer);
rightNode = new IntervalTreeNode<TKey, TValue>(right, this.comparer);
}

/// <summary>
Expand Down Expand Up @@ -198,4 +197,4 @@ public TKey Min
}
}
}
}
}
18 changes: 18 additions & 0 deletions IntervalTree/Obsolete/IRangeTree.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using System;
using IntervalTree;

namespace RangeTree
{
/// <summary>
/// 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.
/// </summary>
/// <typeparam name="TKey">The type of the range.</typeparam>
/// <typeparam name="TValue">The type of the data items.</typeparam>
[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<TKey, TValue> : IIntervalTree<TKey, TValue>
{

}
}
18 changes: 18 additions & 0 deletions IntervalTree/Obsolete/RangeTree.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
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<TKey, TValue> : IntervalTree<TKey, TValue>, IRangeTree<TKey, TValue>
{
public RangeTree()
{
}

public RangeTree(IComparer<TKey> comparer) : base(comparer)
{
}
}
}
18 changes: 18 additions & 0 deletions IntervalTree/Obsolete/RangeTreeNode.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
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<TKey, TValue> : IntervalTreeNode<TKey, TValue>
{
public RangeTreeNode(IComparer<TKey> comparer) : base(comparer)
{
}

public RangeTreeNode(IList<IntervalTree.RangeValuePair<TKey, TValue>> items, IComparer<TKey> comparer) : base(items, comparer)
{
}
}
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
using System;
using System.Collections.Generic;

namespace RangeTree
namespace IntervalTree
{
/// <summary>
/// Represents a range of values.
/// Both values must be of the same type and comparable.
/// </summary>
/// <typeparam name="TKey">Type of the values.</typeparam>
public struct RangeValuePair<TKey, TValue> : IEquatable<RangeValuePair<TKey, TValue>>
public readonly struct RangeValuePair<TKey, TValue> : IEquatable<RangeValuePair<TKey, TValue>>
{
public TKey From { get; }
public TKey To { get; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,14 @@
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\RangeTree\RangeTree.csproj" />
<PackageReference Include="StyleCop.Analyzers" Version="1.1.118">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>

<ItemGroup>
<PackageReference Include="StyleCop.Analyzers" Version="1.0.2" />
<ProjectReference Include="..\IntervalTree\IntervalTree.csproj" />
</ItemGroup>

<PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace RangeTreeExamples
{
class Program
{
static void Main(string[] args)
static void Main_Obsolete(string[] args)
{
TreeExample1();
TreeExample2();
Expand All @@ -32,6 +32,7 @@ static void TreeExample1()
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();
}
Expand Down
Loading

0 comments on commit d13e0d7

Please sign in to comment.