getBestAlgorithm<P extends GpsPoint, C extends GpsPointsView<P> , F> static method
SearchAlgorithm<GpsPoint, GpsPointsView<GpsPoint> , dynamic>
getBestAlgorithm<P extends GpsPoint, C extends GpsPointsView<P> , F>(
- C collection,
- bool isSorted,
- SearchCompareDiff<
C, F> compareDiff
Determines which algorithm is best suited for the search in the given
collection
.
Implementation
static SearchAlgorithm
getBestAlgorithm<P extends GpsPoint, C extends GpsPointsView<P>, F>(
C collection, bool isSorted, SearchCompareDiff<C, F> compareDiff) {
if (isSorted) {
// Sorted collection can do a binary search.
if (collection is GpcEfficient) {
return BinarySearchInGpcEfficient<P, F>(collection as GpcEfficient<P>,
compareDiff as SearchCompareDiff<GpcEfficient<P>, F>);
} else {
return BinarySearchInSlowCollection<P, F>(collection, compareDiff);
}
} else {
// Unsorted collection requires linear search.
if (collection is GpcEfficient) {
return LinearSearchInGpcEfficient<P, F>(collection as GpcEfficient<P>,
compareDiff as SearchCompareDiff<GpcEfficient<P>, F>);
} else {
return LinearSearchInSlowCollection<P, F>(collection, compareDiff);
}
}
}