From 311da1357415b87fca3f36bce770b4d3546fd17a Mon Sep 17 00:00:00 2001 From: Arthur Bols Date: Wed, 15 May 2019 16:58:33 +0200 Subject: [PATCH] perf fixes --- TMI-practicum/Circle.cs | 3 ++- TMI-practicum/SimpleAlgorithm.cs | 4 ++-- TMI-practicum/SweepLineAlgorithm.cs | 8 ++++---- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/TMI-practicum/Circle.cs b/TMI-practicum/Circle.cs index 73f3808..46ba3a8 100644 --- a/TMI-practicum/Circle.cs +++ b/TMI-practicum/Circle.cs @@ -21,7 +21,8 @@ namespace TMI_practicum return Math.Round(Math.Sqrt(Math.Pow(X - otherCircle.X, 2) + Math.Pow(Y - otherCircle.Y, 2)), 15); } - public IList FindIntersections(Circle c1) + public + IEnumerable FindIntersections(Circle c1) { IList intersections; double d = Distance(c1); diff --git a/TMI-practicum/SimpleAlgorithm.cs b/TMI-practicum/SimpleAlgorithm.cs index afebc16..c5e41db 100644 --- a/TMI-practicum/SimpleAlgorithm.cs +++ b/TMI-practicum/SimpleAlgorithm.cs @@ -6,7 +6,7 @@ namespace TMI_practicum { public static IEnumerable Solve(IList circles) { - var intersections = new HashSet(); + var intersections = new Stack(); for (int i = 0; i < circles.Count - 1; i++) { @@ -18,7 +18,7 @@ namespace TMI_practicum if (intersects == null) continue; foreach (var intersect in intersects) { - intersections.Add(intersect); + intersections.Push(intersect); } } } diff --git a/TMI-practicum/SweepLineAlgorithm.cs b/TMI-practicum/SweepLineAlgorithm.cs index 13061ef..2fcedea 100644 --- a/TMI-practicum/SweepLineAlgorithm.cs +++ b/TMI-practicum/SweepLineAlgorithm.cs @@ -6,10 +6,10 @@ namespace TMI_practicum { public static class SweepLineAlgorithm { - public static IEnumerable Solve(IList circles) + public static IEnumerable Solve(IEnumerable circles) { var events = new PriorityQueue(); - var intersections = new HashSet(); + var intersections = new Stack(); var active = new List(); foreach (var circle in circles) @@ -38,7 +38,7 @@ namespace TMI_practicum return intersections; } - private static void CheckIntersections(IEnumerable active, Circle circle, HashSet intersections) + private static void CheckIntersections(IEnumerable active, Circle circle, Stack intersections) { foreach (var otherCircle in active) { @@ -49,7 +49,7 @@ namespace TMI_practicum foreach (var intersection in intersects) { - intersections.Add(intersection); + intersections.Push(intersection); } } }