From a7b31179ed1935bf527ca4b72fb54dfb044b5ae1 Mon Sep 17 00:00:00 2001 From: Simmo Saan Date: Fri, 26 Jul 2024 16:48:13 +0300 Subject: [PATCH] Fix deprecated with type operator from Scala 3.4.0 --- src/main/scala/eu/sim642/adventofcode2021/Day12.scala | 6 +++--- src/main/scala/eu/sim642/adventofcode2023/Day10.scala | 2 +- src/main/scala/eu/sim642/adventofcode2023/Day21.scala | 2 +- .../eu/sim642/adventofcodelib/cycle/BrentCycleFinder.scala | 2 +- .../eu/sim642/adventofcodelib/cycle/FloydCycleFinder.scala | 2 +- .../eu/sim642/adventofcodelib/cycle/NaiveCycleFinder.scala | 2 +- .../eu/sim642/adventofcodelib/cycle/NaiverCycleFinder.scala | 4 ++-- src/main/scala/eu/sim642/adventofcodelib/graph/AStar.scala | 2 +- src/main/scala/eu/sim642/adventofcodelib/graph/BFS.scala | 6 +++--- src/main/scala/eu/sim642/adventofcodelib/graph/DFS.scala | 2 +- .../scala/eu/sim642/adventofcodelib/graph/Dijkstra.scala | 2 +- .../eu/sim642/adventofcodelib/graph/SimultaneousBFS.scala | 6 +++--- src/test/scala/eu/sim642/adventofcode2019/Day22Test.scala | 2 +- 13 files changed, 20 insertions(+), 20 deletions(-) diff --git a/src/main/scala/eu/sim642/adventofcode2021/Day12.scala b/src/main/scala/eu/sim642/adventofcode2021/Day12.scala index cb8368b6..c6313873 100644 --- a/src/main/scala/eu/sim642/adventofcode2021/Day12.scala +++ b/src/main/scala/eu/sim642/adventofcode2021/Day12.scala @@ -15,7 +15,7 @@ object Day12 { sealed trait Part { type Node <: PathNode - def caveTraversal(caveMap: CaveMap): GraphTraversal[Node] with UnitNeighbors[Node] + def caveTraversal(caveMap: CaveMap): GraphTraversal[Node] & UnitNeighbors[Node] def countPaths(caveMap: CaveMap): Int = { val pathNodes = BFS.traverse(caveTraversal(caveMap)).nodes @@ -27,7 +27,7 @@ object Day12 { override case class Node(path: List[Cave]) extends PathNode - override def caveTraversal(caveMap: CaveMap): GraphTraversal[Node] with UnitNeighbors[Node] = new GraphTraversal[Node] with UnitNeighbors[Node] { + override def caveTraversal(caveMap: CaveMap): GraphTraversal[Node] & UnitNeighbors[Node] = new GraphTraversal[Node] with UnitNeighbors[Node] { override val startNode: Node = Node(List("start")) override def unitNeighbors(node: Node): IterableOnce[Node] = { @@ -43,7 +43,7 @@ object Day12 { override case class Node(path: List[Cave])(val canDuplicateSmall: Boolean) extends PathNode - override def caveTraversal(caveMap: CaveMap): GraphTraversal[Node] with UnitNeighbors[Node] = new GraphTraversal[Node] with UnitNeighbors[Node] { + override def caveTraversal(caveMap: CaveMap): GraphTraversal[Node] & UnitNeighbors[Node] = new GraphTraversal[Node] with UnitNeighbors[Node] { override val startNode: Node = Node(List("start"))(true) override def unitNeighbors(node: Node): IterableOnce[Node] = { diff --git a/src/main/scala/eu/sim642/adventofcode2023/Day10.scala b/src/main/scala/eu/sim642/adventofcode2023/Day10.scala index ff64b99a..4c853087 100644 --- a/src/main/scala/eu/sim642/adventofcode2023/Day10.scala +++ b/src/main/scala/eu/sim642/adventofcode2023/Day10.scala @@ -17,7 +17,7 @@ object Day10 { 'S' -> Pos.axisOffsets.toSet, ) - def loopTraversal(grid: Grid[Char]): GraphTraversal[Pos] with UnitNeighbors[Pos] = { + def loopTraversal(grid: Grid[Char]): GraphTraversal[Pos] & UnitNeighbors[Pos] = { new GraphTraversal[Pos] with UnitNeighbors[Pos] { override val startNode: Pos = grid.posOf('S') diff --git a/src/main/scala/eu/sim642/adventofcode2023/Day21.scala b/src/main/scala/eu/sim642/adventofcode2023/Day21.scala index 5772c4b3..5259ea53 100644 --- a/src/main/scala/eu/sim642/adventofcode2023/Day21.scala +++ b/src/main/scala/eu/sim642/adventofcode2023/Day21.scala @@ -10,7 +10,7 @@ import scala.math.Integral.Implicits.* object Day21 { - def gardenSearch(startPos: Pos, grid: Pos => Boolean, maxDist: Int): GraphSearch[Pos] with UnitNeighbors[Pos] = { + def gardenSearch(startPos: Pos, grid: Pos => Boolean, maxDist: Int): GraphSearch[Pos] & UnitNeighbors[Pos] = { new GraphSearch[Pos] with UnitNeighbors[Pos] { override val startNode: Pos = startPos diff --git a/src/main/scala/eu/sim642/adventofcodelib/cycle/BrentCycleFinder.scala b/src/main/scala/eu/sim642/adventofcodelib/cycle/BrentCycleFinder.scala index dedbe035..bf4aed0d 100644 --- a/src/main/scala/eu/sim642/adventofcodelib/cycle/BrentCycleFinder.scala +++ b/src/main/scala/eu/sim642/adventofcodelib/cycle/BrentCycleFinder.scala @@ -4,7 +4,7 @@ object BrentCycleFinder extends FunctionCycleFinder with FunctionCycleByFinder { - override def find[A](x0: A, f: A => A): Cycle[A] with Indexing[A] = { + override def find[A](x0: A, f: A => A): Cycle[A] & Indexing[A] = { // https://en.wikipedia.org/wiki/Cycle_detection#Brent's_algorithm var power = 1 var λ = 1 diff --git a/src/main/scala/eu/sim642/adventofcodelib/cycle/FloydCycleFinder.scala b/src/main/scala/eu/sim642/adventofcodelib/cycle/FloydCycleFinder.scala index ac3044b9..3094b765 100644 --- a/src/main/scala/eu/sim642/adventofcodelib/cycle/FloydCycleFinder.scala +++ b/src/main/scala/eu/sim642/adventofcodelib/cycle/FloydCycleFinder.scala @@ -4,7 +4,7 @@ object FloydCycleFinder extends FunctionCycleFinder with FunctionCycleByFinder { - override def find[A](x0: A, f: A => A): Cycle[A] with Indexing[A] = { + override def find[A](x0: A, f: A => A): Cycle[A] & Indexing[A] = { // https://en.wikipedia.org/wiki/Cycle_detection#Floyd's_Tortoise_and_Hare var tortoise = f(x0) var hare = f(f(x0)) diff --git a/src/main/scala/eu/sim642/adventofcodelib/cycle/NaiveCycleFinder.scala b/src/main/scala/eu/sim642/adventofcodelib/cycle/NaiveCycleFinder.scala index 1eeaf675..6431bff7 100644 --- a/src/main/scala/eu/sim642/adventofcodelib/cycle/NaiveCycleFinder.scala +++ b/src/main/scala/eu/sim642/adventofcodelib/cycle/NaiveCycleFinder.scala @@ -26,7 +26,7 @@ object NaiveCycleFinder }) } - override def find[A](x0: A, f: A => A): Cycle[A] with Indexing[A] = { + override def find[A](x0: A, f: A => A): Cycle[A] & Indexing[A] = { val cycle = find(Iterator.iterate(x0)(f)).get FunctionCycle( stemLength = cycle.stemLength, diff --git a/src/main/scala/eu/sim642/adventofcodelib/cycle/NaiverCycleFinder.scala b/src/main/scala/eu/sim642/adventofcodelib/cycle/NaiverCycleFinder.scala index de216ee0..7a9cb0b9 100644 --- a/src/main/scala/eu/sim642/adventofcodelib/cycle/NaiverCycleFinder.scala +++ b/src/main/scala/eu/sim642/adventofcodelib/cycle/NaiverCycleFinder.scala @@ -6,7 +6,7 @@ object NaiverCycleFinder extends IterableOnceCycleFinder with FunctionCycleFinder { - override def find[A](coll: IterableOnce[A]): Option[Cycle[A] with Indexing[A]] = { + override def find[A](coll: IterableOnce[A]): Option[Cycle[A] & Indexing[A]] = { val prevs = mutable.Map[A, Int]() val values = Vector.newBuilder[A] @@ -21,7 +21,7 @@ object NaiverCycleFinder }) } - override def find[A](x0: A, f: A => A): Cycle[A] with Indexing[A] = { + override def find[A](x0: A, f: A => A): Cycle[A] & Indexing[A] = { find(Iterator.iterate(x0)(f)).get } } diff --git a/src/main/scala/eu/sim642/adventofcodelib/graph/AStar.scala b/src/main/scala/eu/sim642/adventofcodelib/graph/AStar.scala index 5e23f347..fe81053a 100644 --- a/src/main/scala/eu/sim642/adventofcodelib/graph/AStar.scala +++ b/src/main/scala/eu/sim642/adventofcodelib/graph/AStar.scala @@ -4,7 +4,7 @@ import scala.collection.mutable object AStar { // moved from 2018 Day 22 - def search[A](graphSearch: GraphSearch[A] with Heuristic[A]): Distances[A] with Target[A] = { + def search[A](graphSearch: GraphSearch[A] & Heuristic[A]): Distances[A] & Target[A] = { val visitedDistance: mutable.Map[A, Int] = mutable.Map.empty val toVisit: mutable.PriorityQueue[(Int, Int, A)] = mutable.PriorityQueue.empty(Ordering.by(-_._1)) diff --git a/src/main/scala/eu/sim642/adventofcodelib/graph/BFS.scala b/src/main/scala/eu/sim642/adventofcodelib/graph/BFS.scala index b5409548..72bf61fd 100644 --- a/src/main/scala/eu/sim642/adventofcodelib/graph/BFS.scala +++ b/src/main/scala/eu/sim642/adventofcodelib/graph/BFS.scala @@ -7,7 +7,7 @@ object BFS { // TODO: reduce duplication without impacting performance // copied from Dijkstra - def traverse[A](graphTraversal: GraphTraversal[A] with UnitNeighbors[A]): Distances[A] = { + def traverse[A](graphTraversal: GraphTraversal[A] & UnitNeighbors[A]): Distances[A] = { val visitedDistance: mutable.Map[A, Int] = mutable.Map.empty val toVisit: mutable.Queue[(Int, A)] = mutable.Queue.empty @@ -39,7 +39,7 @@ object BFS { } // copied from Dijkstra - def search[A](graphSearch: GraphSearch[A] with UnitNeighbors[A]): Distances[A] with Target[A] = { + def search[A](graphSearch: GraphSearch[A] & UnitNeighbors[A]): Distances[A] & Target[A] = { val visitedDistance: mutable.Map[A, Int] = mutable.Map.empty val toVisit: mutable.Queue[(Int, A)] = mutable.Queue.empty @@ -82,7 +82,7 @@ object BFS { } // copied from search - def searchPaths[A](graphSearch: GraphSearch[A] with UnitNeighbors[A]): Distances[A] with Paths[A] with Target[A] = { + def searchPaths[A](graphSearch: GraphSearch[A] & UnitNeighbors[A]): Distances[A] & Paths[A] & Target[A] = { val visitedDistance: mutable.Map[A, Int] = mutable.Map.empty val prevNode: mutable.Map[A, A] = mutable.Map.empty val toVisit: mutable.Queue[(Int, Option[A], A)] = mutable.Queue.empty diff --git a/src/main/scala/eu/sim642/adventofcodelib/graph/DFS.scala b/src/main/scala/eu/sim642/adventofcodelib/graph/DFS.scala index f7579224..767dd38a 100644 --- a/src/main/scala/eu/sim642/adventofcodelib/graph/DFS.scala +++ b/src/main/scala/eu/sim642/adventofcodelib/graph/DFS.scala @@ -6,7 +6,7 @@ object DFS { // TODO: reduce duplication without impacting performance // copied from BFS - def traverse[A](graphTraversal: GraphTraversal[A] with UnitNeighbors[A]): Distances[A] with Order[A] = { + def traverse[A](graphTraversal: GraphTraversal[A] & UnitNeighbors[A]): Distances[A] & Order[A] = { val visitedDistance: mutable.Map[A, Int] = mutable.Map.empty val visitedOrder: mutable.Buffer[A] = mutable.Buffer.empty val toVisit: mutable.Stack[(Int, A)] = mutable.Stack.empty diff --git a/src/main/scala/eu/sim642/adventofcodelib/graph/Dijkstra.scala b/src/main/scala/eu/sim642/adventofcodelib/graph/Dijkstra.scala index b745b718..5503b2fe 100644 --- a/src/main/scala/eu/sim642/adventofcodelib/graph/Dijkstra.scala +++ b/src/main/scala/eu/sim642/adventofcodelib/graph/Dijkstra.scala @@ -38,7 +38,7 @@ object Dijkstra { } // copied from AStar - def search[A](graphSearch: GraphSearch[A]): Distances[A] with Target[A] = { + def search[A](graphSearch: GraphSearch[A]): Distances[A] & Target[A] = { val visitedDistance: mutable.Map[A, Int] = mutable.Map.empty val toVisit: mutable.PriorityQueue[(Int, A)] = mutable.PriorityQueue.empty(Ordering.by(-_._1)) diff --git a/src/main/scala/eu/sim642/adventofcodelib/graph/SimultaneousBFS.scala b/src/main/scala/eu/sim642/adventofcodelib/graph/SimultaneousBFS.scala index 75619f8b..9120cbbb 100644 --- a/src/main/scala/eu/sim642/adventofcodelib/graph/SimultaneousBFS.scala +++ b/src/main/scala/eu/sim642/adventofcodelib/graph/SimultaneousBFS.scala @@ -10,7 +10,7 @@ object SimultaneousBFS { // TODO: reduce duplication without impacting performance // moved from 2018 Day 20 - def traverse[A](graphTraversal: GraphTraversal[A] with UnitNeighbors[A]): Distances[A] = { + def traverse[A](graphTraversal: GraphTraversal[A] & UnitNeighbors[A]): Distances[A] = { @tailrec def helper(visited: Map[A, Int], toVisit: Map[A, Int]): Distances[A] = { @@ -34,10 +34,10 @@ object SimultaneousBFS { } // moved from 2018 Day 20 - def search[A](graphSearch: GraphSearch[A] with UnitNeighbors[A]): Distances[A] with Target[A] = { + def search[A](graphSearch: GraphSearch[A] & UnitNeighbors[A]): Distances[A] & Target[A] = { @tailrec - def helper(visited: Map[A, Int], toVisit: Map[A, Int]): Distances[A] with Target[A] = { + def helper(visited: Map[A, Int], toVisit: Map[A, Int]): Distances[A] & Target[A] = { // TODO: use one dist: Int argument instead of all same toVisit values val newVisited = visited ++ toVisit toVisit.find(graphSearch.isTargetNode.tupled) match { diff --git a/src/test/scala/eu/sim642/adventofcode2019/Day22Test.scala b/src/test/scala/eu/sim642/adventofcode2019/Day22Test.scala index 8ef75fb8..550e4c84 100644 --- a/src/test/scala/eu/sim642/adventofcode2019/Day22Test.scala +++ b/src/test/scala/eu/sim642/adventofcode2019/Day22Test.scala @@ -85,6 +85,6 @@ object Day22Test { } class LinearSolutionTest extends Part1SolutionTest with Part2SolutionTest { - override val solution: Part1Solution with Part2Solution = LinearSolution + override val solution: Part1Solution & Part2Solution = LinearSolution } }