Skip to content

Commit

Permalink
preserve sort integrity between executions to calculate heads raw
Browse files Browse the repository at this point in the history
minor
  • Loading branch information
miguelangel-dev committed Jul 12, 2024
1 parent 5fa3988 commit 84896a2
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
4 changes: 2 additions & 2 deletions Sources/Automerge/ChangeHash.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public extension Set<ChangeHash> {
/// and retrieval of document states.
func raw() -> Data {
let rawBytes = map(\.bytes).sorted { lhs, rhs in
lhs.hashValue > rhs.hashValue
lhs.debugDescription > rhs.debugDescription
}
return Data(rawBytes.joined())
}
Expand All @@ -28,7 +28,7 @@ public extension Data {

/// Returns the related set of changes of a state representation within an Automerge document.
func heads() -> Set<ChangeHash>? {
let rawBytes = Array(self)
let rawBytes: [UInt8] = Array(self)
guard rawBytes.count % 32 == 0 else { return nil }
let totalHashes = rawBytes.count / 32
let heads = (0..<totalHashes).map { index in
Expand Down
2 changes: 1 addition & 1 deletion Tests/AutomergeTests/TestChanges.swift
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ class ChangeSetTests: XCTestCase {
try doc.merge(other: doc2)
try doc.merge(other: doc3)

let rawHashes = (0..<100).map { _ in doc.heads().raw().hashValue }
let rawHashes = (0..<500).map { _ in doc.heads().raw() }

XCTAssertEqual(Set(rawHashes).count, 1)
}
Expand Down

0 comments on commit 84896a2

Please sign in to comment.