canApply method

  1. @override
bool canApply(
  1. List<int> input,
  2. SelectorHint hint
)
override

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) {
  final size = hint.n ?? input.length;

  return size >= _sequentialThreshold;
}