Skip to content

Commit

Permalink
BTreeMerger: Fix bugs with common subtree detection.
Browse files Browse the repository at this point in the history
Merge methods (i.e., set operations) sometimes did not correctly handle duplicate keys at the boundaries of common subtrees.

This is extremely hard to reproduce using conventional means.

Affected methods:
- BTree.distinctUnion
- BTree.subtracting
- BTree.bagSubtracting
- BTree.symmetricDifference
- BTree.bagSymmetricDifference
- BTree.intersection
- BTree.bagIntersection

- BTreeMerger.copyCommonElementsFromSecond
- BTreeMerger.copyMatchingNumberOfCommonElementsFromSecond
- BTreeMerger.skipCommonElements
- BTreeMerger.skipMatchingNumberOfCommonElements

This fixes issue #20.
  • Loading branch information
lorentey committed Nov 5, 2016
1 parent b6f8f8c commit 27534c2
Show file tree
Hide file tree
Showing 3 changed files with 172 additions and 95 deletions.
10 changes: 5 additions & 5 deletions Sources/BTreeComparisons.swift
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,11 @@ extension BTree {
return false
}
while a.key < b.key {
a.nextPart(until: b.key, inclusive: false)
a.nextPart(until: .excluding(b.key))
if a.isAtEnd { break outer }
}
while b.key < a.key {
b.nextPart(until: a.key, inclusive: false)
b.nextPart(until: .excluding(a.key))
if b.isAtEnd { break outer }
}
}
Expand Down Expand Up @@ -164,10 +164,10 @@ extension BTree {
}
let key = a.key
repeat {
a.nextPart(until: key, inclusive: true)
a.nextPart(until: .including(key))
} while !a.isAtEnd && a.key == key
repeat {
b.nextPart(until: key, inclusive: true)
b.nextPart(until: .including(key))
} while !b.isAtEnd && b.key == key
if a.isAtEnd {
knownStrict = knownStrict || !b.isAtEnd
Expand All @@ -177,7 +177,7 @@ extension BTree {
}
while b.key < a.key {
knownStrict = true
b.nextPart(until: a.key, inclusive: false)
b.nextPart(until: .excluding(a.key))
if b.isAtEnd { return false }
}
}
Expand Down
Loading

0 comments on commit 27534c2

Please sign in to comment.