Skip to content

Commit

Permalink
Fix deprecated with type operator from Scala 3.4.0
Browse files Browse the repository at this point in the history
  • Loading branch information
sim642 committed Jul 26, 2024
1 parent 718222c commit a7b3117
Show file tree
Hide file tree
Showing 13 changed files with 20 additions and 20 deletions.
6 changes: 3 additions & 3 deletions src/main/scala/eu/sim642/adventofcode2021/Day12.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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] = {
Expand All @@ -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] = {
Expand Down
2 changes: 1 addition & 1 deletion src/main/scala/eu/sim642/adventofcode2023/Day10.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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')

Expand Down
2 changes: 1 addition & 1 deletion src/main/scala/eu/sim642/adventofcode2023/Day21.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Expand All @@ -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
}
}
2 changes: 1 addition & 1 deletion src/main/scala/eu/sim642/adventofcodelib/graph/AStar.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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))

Expand Down
6 changes: 3 additions & 3 deletions src/main/scala/eu/sim642/adventofcodelib/graph/BFS.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/main/scala/eu/sim642/adventofcodelib/graph/DFS.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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] = {
Expand All @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion src/test/scala/eu/sim642/adventofcode2019/Day22Test.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

0 comments on commit a7b3117

Please sign in to comment.