{"id":21331426,"url":"https://github.com/eibens/binary_search","last_synced_at":"2025-03-16T00:42:41.951Z","repository":{"id":62422204,"uuid":"384797072","full_name":"eibens/binary_search","owner":"eibens","description":"Binary search implemented in TypeScript for Deno.","archived":false,"fork":false,"pushed_at":"2021-07-10T21:40:53.000Z","size":4,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-22T19:39:50.400Z","etag":null,"topics":["algorithm","binary-search","deno","generic","performance","typescript"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","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/eibens.png","metadata":{"files":{"readme":"README.md","changelog":null,"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-07-10T21:34:24.000Z","updated_at":"2021-07-10T22:24:42.000Z","dependencies_parsed_at":"2022-11-01T17:31:27.064Z","dependency_job_id":null,"html_url":"https://github.com/eibens/binary_search","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eibens%2Fbinary_search","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eibens%2Fbinary_search/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eibens%2Fbinary_search/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eibens%2Fbinary_search/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/eibens","download_url":"https://codeload.github.com/eibens/binary_search/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243809848,"owners_count":20351407,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":["algorithm","binary-search","deno","generic","performance","typescript"],"created_at":"2024-11-21T22:33:05.254Z","updated_at":"2025-03-16T00:42:41.918Z","avatar_url":"https://github.com/eibens.png","language":"TypeScript","readme":"# binary_search\n\nThe [binary search algorithm] implemented in TypeScript for [Deno].\n\n[![License][license-shield]](LICENSE) [![Deno doc][deno-doc-shield]][deno-doc]\n[![Deno module][deno-land-shield]][deno-land]\n[![Github tag][github-shield]][github] [![Build][build-shield]][build]\n[![Code coverage][coverage-shield]][coverage]\n\n# Motivation\n\nSometimes one needs `O(log n)` search performance.\n\n# [mod.ts](mod.ts)\n\nThe `find` function can be used to find an `item` in an `array`. The array must\nbe sorted according to the `compare` function.\n\n```ts\nimport { find } from \"https://deno.land/x/binary_search/mod.ts\";\n\nconst array = [\"a\", \"b\", \"c\", \"d\", \"e\"];\nconst compare = (a: string, b: string) =\u003e a.charCodeAt(0) - b.charCodeAt(0);\nconst index = find(array, \"c\", compare);\n\nconsole.assert(index === 2);\n```\n\nIf the `item` is not in the `array`, a negative number is is returned. The\ncomplement of that number is the index at which one would have to insert the\n`item` to preserve the `order`.\n\n```ts\nimport { find } from \"https://deno.land/x/binary_search/mod.ts\";\n\nconst array = [0, 1, 2, 3, 4];\nconst index = find(array, 2.5, (a, b) =\u003e a - b);\n\nconsole.assert(index === -4);\nconsole.assert(~index === 3);\n```\n\nThe `findNumber` function is a special case of `find` for searching a number in\nan ordered sequence of numbers.\n\n```ts\nimport { findNumber } from \"https://deno.land/x/binary_search/mod.ts\";\n\nconst array = [0, 1, 2, 3, 4];\nconst index = findNumber(array, 2);\n\nconsole.assert(index === 2);\n```\n\n[binary_search]: #\n[Deno]: https://deno.land\n[binary search algorithm]: https://en.wikipedia.org/wiki/Binary_search_algorithm\n\n\u003c!-- badges --\u003e\n\n[github]: https://github.com/eibens/binary_search\n[github-shield]: https://img.shields.io/github/v/tag/eibens/binary_search?label\u0026logo=github\n[coverage-shield]: https://img.shields.io/codecov/c/github/eibens/binary_search?logo=codecov\u0026label\n[license-shield]: https://img.shields.io/github/license/eibens/binary_search?color=informational\n[coverage]: https://codecov.io/gh/eibens/binary_search\n[build]: https://github.com/eibens/binary_search/actions/workflows/ci.yml\n[build-shield]: https://img.shields.io/github/workflow/status/eibens/binary_search/ci?logo=github\u0026label\n[deno-doc]: https://doc.deno.land/https/deno.land/x/binary_search/mod.ts\n[deno-doc-shield]: https://img.shields.io/badge/doc-informational?logo=deno\n[deno-land]: https://deno.land/x/binary_search\n[deno-land-shield]: https://img.shields.io/badge/x/binary__search-informational?logo=deno\u0026label\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feibens%2Fbinary_search","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Feibens%2Fbinary_search","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feibens%2Fbinary_search/lists"}