{"id":28990491,"url":"https://github.com/babenkoivan/orderedset","last_synced_at":"2025-06-25T00:11:45.373Z","repository":{"id":299800040,"uuid":"1003646235","full_name":"babenkoivan/orderedset","owner":"babenkoivan","description":"The package provides a generic, goroutine-safe ordered set data structure in Go.","archived":false,"fork":false,"pushed_at":"2025-06-18T10:28:39.000Z","size":6,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-06-18T11:30:18.078Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/babenkoivan.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,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-06-17T13:05:55.000Z","updated_at":"2025-06-18T10:27:33.000Z","dependencies_parsed_at":"2025-06-18T11:42:29.039Z","dependency_job_id":null,"html_url":"https://github.com/babenkoivan/orderedset","commit_stats":null,"previous_names":["babenkoivan/orderedset"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/babenkoivan/orderedset","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/babenkoivan%2Forderedset","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/babenkoivan%2Forderedset/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/babenkoivan%2Forderedset/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/babenkoivan%2Forderedset/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/babenkoivan","download_url":"https://codeload.github.com/babenkoivan/orderedset/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/babenkoivan%2Forderedset/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":261777776,"owners_count":23208130,"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":[],"created_at":"2025-06-25T00:11:43.184Z","updated_at":"2025-06-25T00:11:45.313Z","avatar_url":"https://github.com/babenkoivan.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# orderedset\n\nPackage orderedset provides a generic, goroutine-safe ordered set implementation in Go.\n\nIt maintains insertion order of unique elements and supports common set operations efficiently.\n\n## Installation\n\n```bash\ngo get github.com/babenkoivan/orderedset\n```\n\n## Overview\n\nThe `OrderedSet[T comparable]` type supports:\n\n* Adding and removing unique elements\n* Checking element presence\n* Accessing elements by index\n* Finding index of an element\n* Removing elements by value or index\n* Cloning and slicing subsets\n* Sorting elements by custom comparator\n* Set operations: Union, Intersect, Difference\n* JSON marshalling/unmarshalling\n* Thread-safe operations for concurrent use\n\n## Usage\n\n```go\npackage main\n\nimport (\n    \"fmt\"\n    \"github.com/babenkoivan/orderedset\"\n)\n\nfunc main() {\n    s := orderedset.New[int]()\n    s.Add(1)\n    s.Add(2)\n    s.Add(2) // duplicate ignored\n\n    fmt.Println(\"Values:\", s.Values()) // Output: Values: [1 2]\n\n    s.Remove(1)\n    fmt.Println(\"Has 1?\", s.Has(1))   // Output: Has 1? false\n    fmt.Println(\"Length:\", s.Len())   // Output: Length: 1\n\n    val, ok := s.At(0)\n    if ok {\n        fmt.Println(\"Value at index 0:\", val) // Output: Value at index 0: 2\n    }\n\n    index := s.IndexOf(2)\n    fmt.Println(\"Index of 2:\", index) // Output: Index of 2: 0\n\n    removedVal, removed := s.RemoveAt(0)\n    if removed {\n        fmt.Println(\"Removed value:\", removedVal) // Output: Removed value: 2\n    }\n\n    s.Add(3)\n    s.Add(4)\n\n    s2 := orderedset.New[int]()\n    s2.Add(4)\n    s2.Add(5)\n\n    union := s.Union(s2)\n    fmt.Println(\"Union:\", union.Values()) // Output: Union: [3 4 5]\n\n    intersect := s.Intersect(s2)\n    fmt.Println(\"Intersect:\", intersect.Values()) // Output: Intersect: [4]\n\n    diff := s.Difference(s2)\n    fmt.Println(\"Difference:\", diff.Values()) // Output: Difference: [3]\n\n    slice, err := union.Slice(1, 3)\n    if err == nil {\n        fmt.Println(\"Slice:\", slice.Values()) // Output: Slice: [4 5]\n    }\n\n    union.SortBy(func(a, b int) bool {\n        return a \u003e b\n    })\n    fmt.Println(\"Sorted descending:\", union.Values()) // Output: Sorted descending: [5 4 3]\n}\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbabenkoivan%2Forderedset","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbabenkoivan%2Forderedset","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbabenkoivan%2Forderedset/lists"}