{"id":19158740,"url":"https://github.com/kerollmops/slice-group-by","last_synced_at":"2025-04-07T15:07:28.375Z","repository":{"id":54518146,"uuid":"136631262","full_name":"Kerollmops/slice-group-by","owner":"Kerollmops","description":"An implementation of the `group_by` Haskell function for slice and strings","archived":false,"fork":false,"pushed_at":"2023-05-03T14:00:06.000Z","size":167,"stargazers_count":53,"open_issues_count":2,"forks_count":3,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-04-05T14:05:42.656Z","etag":null,"topics":["algorithms","array","group-by","rust","slice"],"latest_commit_sha":null,"homepage":"https://docs.rs/slice-group-by","language":"Rust","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/Kerollmops.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,"governance":null,"roadmap":null,"authors":null}},"created_at":"2018-06-08T14:44:31.000Z","updated_at":"2024-09-11T06:05:03.000Z","dependencies_parsed_at":"2023-12-16T21:13:49.229Z","dependency_job_id":"adbb40dd-ee6d-449a-b3c0-1d0e80032a00","html_url":"https://github.com/Kerollmops/slice-group-by","commit_stats":{"total_commits":98,"total_committers":4,"mean_commits":24.5,"dds":"0.29591836734693877","last_synced_commit":"668ee8146c494b26f4c0d279bfc8b7999a0f19b3"},"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Kerollmops%2Fslice-group-by","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Kerollmops%2Fslice-group-by/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Kerollmops%2Fslice-group-by/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Kerollmops%2Fslice-group-by/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Kerollmops","download_url":"https://codeload.github.com/Kerollmops/slice-group-by/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247675597,"owners_count":20977376,"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":["algorithms","array","group-by","rust","slice"],"created_at":"2024-11-09T08:44:50.847Z","updated_at":"2025-04-07T15:07:28.352Z","avatar_url":"https://github.com/Kerollmops.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# slice-group-by\n\n[![slice-group-by crate](https://img.shields.io/crates/v/slice-group-by.svg)](https://crates.io/crates/slice-group-by)\n[![slice-group-by documentation](https://docs.rs/slice-group-by/badge.svg)](https://docs.rs/slice-group-by)\n[![dependency status](https://deps.rs/repo/github/Kerollmops/slice-group-by/status.svg)](https://deps.rs/repo/github/Kerollmops/slice-group-by)\n[![build \u0026 tests worflow](https://github.com/Kerollmops/slice-group-by/actions/workflows/ci.yml/badge.svg)](https://github.com/Kerollmops/slice-group-by/actions/workflows/ci.yml)\n[![License](https://img.shields.io/github/license/Kerollmops/slice-group-by.svg)](https://github.com/Kerollmops/slice-group-by)\n\nAn implementation of the [`groupBy` Haskell function], providing tools for efficiently iterating over `slice` and `str` by groups defined by a function that specifies if two elements are in the same group.\n\n### Differences with `Itertools::group_by`\n\nThe [`Itertools::group_by`] method use a key to compare elements, this library works like, say, [`slice::sort_by`], it uses a comparison function. It works on every `Iterator` type, `slice-group-by` work only with `slice` and `str`, which is the power of this library, it is fast thanks to [data locality].\n\nAlso `slice-group-by` support multiple search algorithms (i.e. [linear], [binary] and [exponential search]) and can return groups starting from the end.\n\n[`groupBy` Haskell function]: http://hackage.haskell.org/package/base-4.12.0.0/docs/Data-List.html#v:groupBy\n[`Itertools::group_by`]: https://docs.rs/itertools/0.8.0/itertools/trait.Itertools.html#method.group_by\n[`slice::sort_by`]: https://doc.rust-lang.org/std/primitive.slice.html#method.sort_by\n[data locality]: https://en.wikipedia.org/wiki/Locality_of_reference\n[linear]: https://en.wikipedia.org/wiki/Linear_search\n[binary]: https://en.wikipedia.org/wiki/Binary_search_algorithm\n[exponential search]: https://en.wikipedia.org/wiki/Exponential_search\n\n## Examples\n\n### Linear Searched Immutable Groups\n\nYou will only need to define a function that returns `true` if two elements are in the same group.\n\nThe `LinearGroupBy` iterator will always gives contiguous elements to the predicate function.\n\n```rust\nuse slice_group_by::GroupBy;\n\nlet slice = \u0026[1, 1, 1, 3, 3, 2, 2, 2];\n\nlet mut iter = slice.linear_group_by(|a, b| a == b);\n\nassert_eq!(iter.next(), Some(\u0026[1, 1, 1][..]));\nassert_eq!(iter.next(), Some(\u0026[3, 3][..]));\nassert_eq!(iter.next(), Some(\u0026[2, 2, 2][..]));\nassert_eq!(iter.next(), None);\n```\n\n### Linear Searched Immutable Str Groups\n\nYou will only need to define a function that returns `true` if two `char` are in the same group.\n\nThe `LinearStrGroupBy` iterator will always gives contiguous `char` to the predicate function.\n\n```rust\nuse slice_group_by::StrGroupBy;\n\nlet string = \"aaaabbbbb饰饰cccc\";\n\nlet mut iter = string.linear_group_by(|a, b| a == b);\n\nassert_eq!(iter.next(), Some(\"aaaa\"));\nassert_eq!(iter.next(), Some(\"bbbbb\"));\nassert_eq!(iter.next(), Some(\"饰饰\"));\nassert_eq!(iter.next(), Some(\"cccc\"));\nassert_eq!(iter.next(), None);\n```\n\n### Binary Searched Mutable Groups\n\nIt is also possible to get mutable non overlapping groups of a slice.\n\nThe `BinaryGroupBy/Mut` and `ExponentialGroupBy/Mut` iterators will not necessarily\ngives contiguous elements to the predicate function. The predicate function should implement\nan order consistent with the sort order of the slice.\n\n```rust\nuse slice_group_by::GroupByMut;\n\nlet slice = \u0026mut [1, 1, 1, 2, 2, 2, 3, 3];\n\nlet mut iter = slice.binary_group_by_mut(|a, b| a == b);\n\nassert_eq!(iter.next(), Some(\u0026mut [1, 1, 1][..]));\nassert_eq!(iter.next(), Some(\u0026mut [2, 2, 2][..]));\nassert_eq!(iter.next(), Some(\u0026mut [3, 3][..]));\nassert_eq!(iter.next(), None);\n```\n\n### Exponential Searched Mutable Groups starting from the End\n\nIt is also possible to get mutable non overlapping groups of a slice even starting from end of it.\n\n```rust\nuse slice_group_by::GroupByMut;\n\nlet slice = \u0026mut [1, 1, 1, 2, 2, 2, 3, 3];\n\nlet mut iter = slice.exponential_group_by_mut(|a, b| a == b).rev();\n\nassert_eq!(iter.next(), Some(\u0026mut [3, 3][..]));\nassert_eq!(iter.next(), Some(\u0026mut [2, 2, 2][..]));\nassert_eq!(iter.next(), Some(\u0026mut [1, 1, 1][..]));\nassert_eq!(iter.next(), None);\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkerollmops%2Fslice-group-by","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkerollmops%2Fslice-group-by","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkerollmops%2Fslice-group-by/lists"}