-
Notifications
You must be signed in to change notification settings - Fork 5k
Auronas: remove force casts on dequeuing #969
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -54,10 +54,7 @@ public final class AStar<G: Graph> { | |
/// - Precondition: both `source` and `target` belong to `graph`. | ||
public func path(start: G.Vertex, target: G.Vertex) -> [G.Vertex] { | ||
open.insert(Node<G.Vertex>(vertex: start, cost: 0, estimate: heuristic(start, target))) | ||
while !open.isEmpty { | ||
guard let node = open.remove() else { | ||
break | ||
} | ||
while !open.isEmpty, let node = open.remove() { | ||
|
||
costs[node.vertex] = node.cost | ||
|
||
if (node.vertex == target) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -95,8 +95,7 @@ extension Huffman { | |
while queue.count > 1 { | ||
// Find the two nodes with the smallest frequencies that do not have | ||
// a parent node yet. | ||
let node1 = queue.dequeue()! | ||
let node2 = queue.dequeue()! | ||
guard let node1 = queue.dequeue(), let node2 = queue.dequeue() else { return } | ||
|
||
|
||
// Create a new intermediate node. | ||
var parentNode = Node() | ||
|
@@ -115,8 +114,9 @@ extension Huffman { | |
} | ||
|
||
// The final remaining node in the queue becomes the root of the tree. | ||
let rootNode = queue.dequeue()! | ||
root = rootNode.index | ||
if let rootNode = queue.dequeue() { | ||
root = rootNode.index | ||
} | ||
} | ||
} | ||
|
||
|