mirror of
https://github.com/dscyrescotti/Memola.git
synced 2026-03-21 00:49:27 +01:00
feat: update ordering
This commit is contained in:
@@ -40,4 +40,17 @@ enum Element: Equatable, Comparable {
|
||||
photo.createdAt
|
||||
}
|
||||
}
|
||||
|
||||
static func < (lhs: Element, rhs: Element) -> Bool {
|
||||
switch (lhs, rhs) {
|
||||
case let (.stroke(leftStroke), .stroke(rightStroke)):
|
||||
leftStroke < rightStroke
|
||||
case let (.photo(leftPhoto), .photo(rightPhoto)):
|
||||
leftPhoto < rightPhoto
|
||||
case let (.photo(photo), .stroke(stroke)):
|
||||
photo.createdAt < stroke.value.createdAt
|
||||
case let (.stroke(stroke), .photo(photo)):
|
||||
stroke.value.createdAt < photo.createdAt
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -38,7 +38,11 @@ class RTree<T> where T: Equatable & Comparable {
|
||||
.sorted(by: <)
|
||||
result = _merge(result, children)
|
||||
} else {
|
||||
queue.append(contentsOf: node.children)
|
||||
let nodes = node.children.sorted {
|
||||
guard let first = $0.value, let second = $1.value else { return false }
|
||||
return first < second
|
||||
}
|
||||
queue.append(contentsOf: nodes)
|
||||
}
|
||||
}
|
||||
return result
|
||||
|
||||
Reference in New Issue
Block a user