Skip to content
Merged
Changes from 1 commit
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
5429d3b
Add partial sort algorithm
rakaramos Oct 8, 2020
4362197
Add in place partial sorting
rockbruno Oct 9, 2020
f299df1
Guide docs
rockbruno Oct 9, 2020
6cd2870
Use Indexes
rockbruno Oct 9, 2020
63b2dd0
Merge pull request #1 from rakaramos/guide
rakaramos Oct 9, 2020
88216e1
Add partial sort tests
rakaramos Oct 9, 2020
afe7111
Indent up to 80 columns
rakaramos Oct 9, 2020
4652ae7
Fix heapify stopping before it should
rockbruno Oct 9, 2020
37d494a
Update PartialSort.md
rockbruno Oct 9, 2020
83d5f1e
Update PartialSort.md
rockbruno Oct 9, 2020
bf31ba1
Update PartialSort.swift
rockbruno Oct 9, 2020
acb3583
Cleaning up iterators logic
rockbruno Oct 9, 2020
6227bd8
Update PartialSort.swift
rockbruno Oct 9, 2020
d4a2e6b
Cleaning docs
rockbruno Oct 9, 2020
62ee6f2
Change implementation and name
rakaramos Oct 21, 2020
f674851
DocDocs
rockbruno Oct 21, 2020
5bdea96
Merge remote-tracking branch 'origin/fix-algo' into docdocs
rockbruno Oct 21, 2020
dd15b5a
Docs
rockbruno Oct 21, 2020
7ac3915
Merge pull request #3 from rakaramos/docdocs
rockbruno Oct 21, 2020
c68537f
Docs
rockbruno Oct 21, 2020
e8504fd
Optimize
rockbruno Oct 21, 2020
36e9a39
Fix header and remove assert
rakaramos Oct 28, 2020
1d22ef9
Add more tests (#4)
rakaramos Oct 31, 2020
62096e1
Update PartialSortTests.swift
rockbruno Oct 31, 2020
d0c1ccd
Merge pull request #5 from rakaramos/rockbruno-patch-1
rockbruno Oct 31, 2020
23bf863
Update Sources/Algorithms/PartialSort.swift
rockbruno Nov 1, 2020
379609b
Update Sources/Algorithms/PartialSort.swift
rockbruno Nov 1, 2020
435a38c
Update Sources/Algorithms/PartialSort.swift
rockbruno Nov 1, 2020
70973a2
Documentation fixes
rockbruno Nov 1, 2020
70a263c
Add tests for massive inputs
rockbruno Dec 2, 2020
1d3dcaf
isLastElement
rockbruno Dec 2, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions Tests/SwiftAlgorithmsTests/PartialSortTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -114,4 +114,33 @@ final class PartialSortTests: XCTestCase {
[1, 2, 3, 4, 7, 20, 70, 90, 100]
)
}

func testSortedPrefixWithHugePrefix() {
XCTAssertEqual(
[4, 2, 1, 3].sortedPrefix(.max),
[1, 2, 3, 4]
)
}

func testStability() {
assertStability([1,1,1,2,5,7,3,6,2,5,7,3,6], withPrefix: 3)
assertStability([1,1,1,2,5,7,3,6,2,5,7,3,6], withPrefix: 6)
assertStability([1,1,1,2,5,7,3,6,2,5,7,3,6], withPrefix: 20)
assertStability([1,1,1,2,5,7,3,6,2,5,7,3,6], withPrefix: 1000)
}

func assertStability(
_ actual: [Int],
withPrefix prefixCount: Int,
file: StaticString = #file,
line: UInt = #line
) {
let indexed = actual.enumerated()
let sorted = indexed.map { $0 } .sortedPrefix(prefixCount) { $0.element < $1.element }

for element in Set(actual) {
let filtered = sorted.filter { $0.element == element }.map(\.offset)
XCTAssertEqual(filtered, filtered.sorted())
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
}
}

}
}