canApply method
Fast check if this strategy can be applied to the given input and hint.
This method should be:
- Fast: avoid expensive computations or validations
- Pure: no side effects or state modifications
- Conservative: return false if uncertain
Example implementations:
// Binary search requires sorted input
bool canApply(List\<int\> input, SelectorHint hint) => hint.sorted == true;
// Insertion sort works well for small datasets
bool canApply(List\<int\> input, SelectorHint hint) => (hint.n ?? input.length) <= 50;
Implementation
@override
bool canApply(List<int> input, SelectorHint hint) {
// Optimized version works well for all sizes above threshold
final n = hint.n ?? input.length;
if (n < _insertionSortThreshold) return false;
if (hint.memoryBudgetBytes != null && hint.memoryBudgetBytes! < 2048) {
return false; // Needs slightly more memory for optimization
}
return true;
}