bisection 0.4.3+1 copy "bisection: ^0.4.3+1" to clipboard
bisection: ^0.4.3+1 copied to clipboard

Searching in sorted lists. Adding items while maintaining the sort order. Port of the Python bisect library.

example/main.dart

import 'package:bisection/bisect.dart';

void main() {
  // The list must be sorted
  final arr = ['A', 'B', 'C', 'E'];

  // Find the index of an item in a sorted list
  print(bisect(arr, 'B')); // 2

  // Find the future index for a non-existent item
  print(bisect_left(arr, 'D')); // 3

  // Add an item to the list while keeping the list sorted
  insort(arr, 'D');
  print(arr); // [A, B, C, D, E]

  // Locate leftmost value equal to 'C'
  print(index(arr, 'C')); //2

  // Find leftmost value greater than 'C'
  print(find_gt(arr, 'C')); // D
}
2
likes
150
points
9
downloads

Publisher

verified publisherrevercode.com

Weekly Downloads

Searching in sorted lists. Adding items while maintaining the sort order. Port of the Python bisect library.

Repository (GitHub)

Documentation

API reference

License

MIT (license)

More

Packages that depend on bisection