{"id":21206204,"url":"https://github.com/rtmigo/bisection_dart","last_synced_at":"2026-05-07T21:38:19.187Z","repository":{"id":61972768,"uuid":"426712835","full_name":"rtmigo/bisection_dart","owner":"rtmigo","description":"Port of the Python bisect library to the Dart language","archived":false,"fork":false,"pushed_at":"2021-11-29T22:55:54.000Z","size":501,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"staging","last_synced_at":"2025-03-14T23:11:56.443Z","etag":null,"topics":["binary-search","bisect","bisection","dart","flutter","list","pubdev","python","search","sorted"],"latest_commit_sha":null,"homepage":"https://pub.dev/packages/bisection","language":"Dart","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/rtmigo.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-11-10T17:22:22.000Z","updated_at":"2021-12-24T18:39:27.000Z","dependencies_parsed_at":"2022-10-24T13:15:27.324Z","dependency_job_id":null,"html_url":"https://github.com/rtmigo/bisection_dart","commit_stats":null,"previous_names":[],"tags_count":14,"template":false,"template_full_name":null,"purl":"pkg:github/rtmigo/bisection_dart","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rtmigo%2Fbisection_dart","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rtmigo%2Fbisection_dart/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rtmigo%2Fbisection_dart/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rtmigo%2Fbisection_dart/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rtmigo","download_url":"https://codeload.github.com/rtmigo/bisection_dart/tar.gz/refs/heads/staging","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rtmigo%2Fbisection_dart/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32757461,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-07T02:14:30.463Z","status":"ssl_error","status_checked_at":"2026-05-07T02:14:29.405Z","response_time":62,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["binary-search","bisect","bisection","dart","flutter","list","pubdev","python","search","sorted"],"created_at":"2024-11-20T20:54:46.762Z","updated_at":"2026-05-07T21:38:19.156Z","avatar_url":"https://github.com/rtmigo.png","language":"Dart","funding_links":[],"categories":[],"sub_categories":[],"readme":"![Generic badge](https://img.shields.io/badge/status-it_works-ok.svg)\n[![Pub Package](https://img.shields.io/pub/v/bisection.svg)](https://pub.dev/packages/bisection)\n[![pub points](https://badges.bar/bisection/pub%20points)](https://pub.dev/packages/bisection/score)\n![Generic badge](https://img.shields.io/badge/testing_on-Windows_|_Linux-blue.svg)\n![Generic badge](https://img.shields.io/badge/testing_on-VM_|_Node_|_Chrome-blue.svg)\n\n# [bisection](https://github.com/rtmigo/bisection_dart)\n\nLibrary for searching in sorted lists and adding items while maintaining the\nsort order.\n\nPort of the Python [bisect](https://docs.python.org/3/library/bisect.html) with\nbinary [search functions](https://docs.python.org/3/library/bisect.html#searching-sorted-lists)\n.\n\nIf you import `bisect.dart`, you will get functions with names like in the\nPython `bisect` package. If you import `extension.dart`, you will get methods\nthat are more consistent with Dart design standards.\n\n`package:bisection/bisect.dart`  | `package:bisection/extension.dart`\n---------------------------------|--------------------------------------\n`bisect(arr, x)`                 | `arr.bisectRight(x)`\n`bisect_left(arr, x)`            | `arr.bisectLeft(x)`\n`bisect_right(arr, x)`           | `arr.bisectRight(x)`\n`insort(arr, x)`                 | `arr.insortRight(x)`\n`insort_left(arr, x)`            | `arr.insortLeft(x)`\n`insort_right(arr, x)`           | `arr.insortRight(x)`\n`index(arr, x)`                  | `arr[arr.bsearch(x)]]`\n`find_lt(arr, x)`                | `arr[arr.bsearchLessThan(x)]`\n`find_le(arr, x)`                | `arr[arr.bsearchLessThanOrEqualTo(x)]`\n`find_gt(arr, x)`                | `arr[arr.bsearchGreaterThan(x)]`\n`find_ge(arr, x)`                | `arr[arr.bsearchGreaterThanOrEqualTo(x)]`\n\n## Use bisect functions\n\n```dart\nimport 'package:bisection/bisect.dart';\n\nvoid main() {\n  // The list must be sorted\n  final arr = ['A', 'B', 'C', 'E'];\n\n  // Find the index of an item in a sorted list\n  print(bisect(arr, 'B'));  // 2\n\n  // Find the future index for a non-existent item\n  print(bisect_left(arr, 'D'));  // 3\n\n  // Add an item to the list while keeping the list sorted\n  insort(arr, 'D');\n  print(arr);  // [A, B, C, D, E]\n\n  // Locate leftmost value equal to 'C'\n  print(index(arr, 'C'));  // 2\n\n  // Find leftmost value greater than 'C'\n  print(find_gt(arr, 'C'));  // D\n}\n```\n\n## Use list extensions\n\n```dart\nimport 'package:bisection/extension.dart';\n\nvoid main() {\n  // The list must be sorted\n  final arr = ['A', 'B', 'C', 'E'];\n\n  // Find the index of an item in a sorted list\n  print(arr.bisectRight('B'));  // 2\n\n  // Find the future index for a non-existent item\n  print(arr.bisectLeft('D'));  // 3\n\n  // Add an item to the list while keeping the list sorted\n  arr.insortRight('D');\n  print(arr);  // [A, B, C, D, E]\n\n  // Locate leftmost value equal to 'C'\n  print(arr.bsearch('C'));  // 2\n\n  // Locate leftmost value greater than 'C'\n  print(arr.bsearchGreaterThan('C'));  // 3\n}\n```\n\n## Custom sorting\n\nFunctions `bisect_*` and `insort_*` take the `key` argument, similar to the\nargument with the same name in Python.\n\n```dart\nimport 'package:bisection/bisect.dart';\n\nvoid main() {\n  final arr = ['zebrA', 'craB', 'coyotE'];\n  // sorting by last char  \n  insort(arr, 'lizarD', key: (String s) =\u003e s[s.length - 1]);\n  print(arr); // [zebrA, craB, lizarD, coyotE]\n}\n```\n\nThe other functions and methods take the `compare` argument,\na [Comparator](https://api.flutter.dev/flutter/dart-core/Comparator.html)\nsimilar to the argument\nin [List.sort](https://api.flutter.dev/flutter/dart-core/List/sort.html).\n\n```dart\nimport 'package:bisection/extension.dart';\n\nvoid main() {\n  final arr = ['zebrA', 'craB', 'coyotE'];\n\n  String lastChar(String s) =\u003e s[s.length - 1];\n\n  arr.insortRight(\n      'lizarD',\n      compare: (a, b) =\u003e lastChar(a).compareTo(lastChar(b)));\n\n  print(arr); // [zebrA, craB, lizarD, coyotE]\n}\n```\n\n## Differences from Python bisect\n\nThe library is written with the intention of repeating the results of Python\nfunctions as accurately as possible. The consistency of the results is\nby [Dart unit tests](https://github.com/rtmigo/bisection_dart/tree/dev/test/generated)\n, generated by\n[Python scripts](https://github.com/rtmigo/bisection_dart/tree/dev/test/generators)\n.\n\nThe only difference is that this library does not accept negative values of the\n`hi` argument. If `hi` value is negative, an exception will be thrown. In the\ncase of Python, a rather mysterious value would be returned.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frtmigo%2Fbisection_dart","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frtmigo%2Fbisection_dart","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frtmigo%2Fbisection_dart/lists"}