{"id":16133159,"url":"https://github.com/infogulch/uniq","last_synced_at":"2025-06-25T01:38:48.227Z","repository":{"id":12792044,"uuid":"15465768","full_name":"infogulch/uniq","owner":"infogulch","description":"Package uniq provides primitives for getting the first unique elements of (aka deduplicate) your existing sorted sort.Interface.","archived":false,"fork":false,"pushed_at":"2014-05-13T21:14:24.000Z","size":228,"stargazers_count":7,"open_issues_count":0,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-06-01T02:01:58.595Z","etag":null,"topics":["deduplicate","distinct","go","golang","uniq"],"latest_commit_sha":null,"homepage":"","language":"Go","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/infogulch.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2013-12-27T03:42:51.000Z","updated_at":"2020-04-02T12:34:38.000Z","dependencies_parsed_at":"2022-09-06T10:50:12.913Z","dependency_job_id":null,"html_url":"https://github.com/infogulch/uniq","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"purl":"pkg:github/infogulch/uniq","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/infogulch%2Funiq","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/infogulch%2Funiq/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/infogulch%2Funiq/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/infogulch%2Funiq/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/infogulch","download_url":"https://codeload.github.com/infogulch/uniq/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/infogulch%2Funiq/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":261786040,"owners_count":23209408,"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":["deduplicate","distinct","go","golang","uniq"],"created_at":"2024-10-09T22:37:36.393Z","updated_at":"2025-06-25T01:38:48.206Z","avatar_url":"https://github.com/infogulch.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# uniq\n    import \"github.com/infogulch/uniq\"\n\nPackage uniq provides primitives for getting the first unique elements of slices\nor user-defined collections from an *already sorted* list using your existing\nsort.Interface. Under the MIT license (see [LICENSE.txt](LICENSE.txt)).\n\n#### Example\n    a := []int{1, 2, 3, 3, 3, 4, 5, 6, 7, 8, 9, 9, 9} // already sorted\n    a = a[:uniq.Ints(a)]\n    fmt.Println(a)\n\nOutput: `[1 2 3 4 5 6 7 8 9]`\n\nThe unique functions return the length of the unique portion of the collection,\nand using the return value as the start or end index in a slice operation (as in\nthe example above) makes it easy to get the result you need when using slices.\n\n*Why use this instead of a map?* uniq doesn't need extra memory. If you're\nsorting already or the result needs to be sorted uniq is faster. Uniq is much\neasier to use and implement in your code, and more easily extended.\n\n*Why use a sort.Interface?* Because the algorithms require the data be sorted\nbeforehand anyway, so you don't have to have to implement anything else, and\nbecause they don't need any more. `Uniq` is O(n) and probably couldn't be\nmuch faster even considering the sort step without using more memory. `Stable`\nis slower and I've considered extending the interface to support copying\nelements to a duplicates buffer but nobody has expressed a need.\n\n--\n#### Index\n* [func Uniq(data Interface) int](#func-uniq)\n* [func Stable(data Interface) int](#func-stable)\n* [func IsUnique(data Interface) bool](#func-isunique)\n* [func Float64s(a []float64) int](#func-float64s)\n* [func Float64sAreUnique(a []float64) bool](#func-float64sareunique)\n* [func Ints(a []int) int](#func-ints)\n* [func IntsAreUnique(a []int) bool](#func-intsareunique)\n* [func Strings(a []string) int](#func-strings)\n* [func StringsAreUnique(a []string) bool](#func-stringsareunique)\n* [type Interface](#type-interface)\n\n--\n#### func Uniq\n    func Uniq(data Interface) int\n\nUniq moves the first unique elements to the beginning of the *sorted* collection\nand returns the number of unique elements.\n\nIt makes one call to data.Len to determine n, n-1 calls to data.Less, and O(n)\ncalls to data.Swap. The unique elements remain in original sorted order, but the\nduplicate elements do not.\n\n--\n#### func Stable\n    func Stable(data Interface) int\n\nStable moves the first unique elements to the beginning of the *sorted*\ncollection and returns the number of unique elements, but also keeps the\noriginal order of duplicate elements.\n\nIt makes one call to data.Len, O(n) calls to data.Less, and O(n*log(n)) calls to\ndata.Swap.\n\n--\n#### func IsUnique\n    func IsUnique(data Interface) bool\n\nIsUnique reports whether data is sorted and unique.\n\n--\n#### func Float64s\n    func Float64s(a []float64) int\n\nFloat64s calls unique on a slice of float64.\n\n--\n#### func Float64sAreUnique\n    func Float64sAreUnique(a []float64) bool\n\nFloat64sAreUnique tests whether the slice of float64 is sorted and unique.\n\n--\n#### func Ints\n    func Ints(a []int) int\n\nInts calls unique on a slice of int.\n\n--\n#### func IntsAreUnique\n    func IntsAreUnique(a []int) bool\n\nIntsAreUnique tests whether the slice of int is sorted and unique.\n\n--\n#### func Strings\n    func Strings(a []string) int\n\nStrings calls unique on a slice of string.\n\n--\n#### func StringsAreUnique\n    func StringsAreUnique(a []string) bool\n\nStringsAreUnique tests whether the slice of string is sorted and unique.\n\n--\n#### type Interface\n    type Interface interface {\n        // Len returns the number of elements.\n        Len() int\n        // Less tells if the element at index i should come\n        // before the element at index j.\n        Less(i, j int) bool\n        // Swap swaps the elements at indexes i and j.\n        Swap(i, j int)\n    }\n\nInterface to use the uniq package. Identical to sort.Interface.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Finfogulch%2Funiq","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Finfogulch%2Funiq","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Finfogulch%2Funiq/lists"}