{"id":37144370,"url":"https://github.com/pigfu/orderedmap","last_synced_at":"2026-01-14T16:57:09.753Z","repository":{"id":213558333,"uuid":"733925907","full_name":"pigfu/orderedmap","owner":"pigfu","description":"a go ordered map that supports custom sorting rule","archived":false,"fork":false,"pushed_at":"2023-12-23T10:17:18.000Z","size":7,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-06-21T17:01:49.765Z","etag":null,"topics":["custom-sort-rule","golang","maps","order","orderedmap"],"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/pigfu.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}},"created_at":"2023-12-20T12:56:29.000Z","updated_at":"2024-04-11T02:14:23.000Z","dependencies_parsed_at":"2024-06-21T15:38:33.049Z","dependency_job_id":"1987d3a9-1b18-4e13-80b4-2cac000c0521","html_url":"https://github.com/pigfu/orderedmap","commit_stats":null,"previous_names":["pigfu/orderedmap"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/pigfu/orderedmap","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pigfu%2Forderedmap","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pigfu%2Forderedmap/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pigfu%2Forderedmap/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pigfu%2Forderedmap/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pigfu","download_url":"https://codeload.github.com/pigfu/orderedmap/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pigfu%2Forderedmap/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28427164,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-14T16:38:47.836Z","status":"ssl_error","status_checked_at":"2026-01-14T16:34:59.695Z","response_time":107,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5: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":["custom-sort-rule","golang","maps","order","orderedmap"],"created_at":"2026-01-14T16:57:09.186Z","updated_at":"2026-01-14T16:57:09.744Z","avatar_url":"https://github.com/pigfu.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# orderedmap\na go ordered map that supports custom sorting rule\n\n## install\n```sh\ngo get github.com/pigfu/orderedmap\n```\n\n## Benchmarks\n\n```go\nvar (\n\tN = int64(100000)\n)\n\nfunc BenchmarkNew(b *testing.B) {\n\tm := New[int64, int]()\n\tfor i := 0; i \u003c b.N; i++ {\n\t\tm.Set(rand.Int63n(N), i)\n\t}\n}\n\nfunc cmp(k1, k2 int64) int {\n\tif k1 \u003c k2 {\n        return -1\n    }\n    if k1 \u003e k2 {\n        return 1\n    }\n    return 0\n}\nfunc BenchmarkNewCmp(b *testing.B) {\n\tm := NewCmp[int64, int](cmp)\n\tfor i := 0; i \u003c b.N; i++ {\n\t\tm.Set(rand.Int63n(N), i)\n\t}\n}\n\nfunc cmpVal(v1, v2 int) int {\n    if v1 \u003c v2 {\n        return -1\n    }\n    if v1 \u003e v2 {\n        return 1\n    }\n    return 0\n}\nfunc BenchmarkNewCmpVal(b *testing.B) {\n\tm := NewCmpVal[int64, int](cmpVal)\n\tfor i := 0; i \u003c b.N; i++ {\n\t\tm.Set(rand.Int63n(N), i)\n\t}\n}\n```\n```bash\ngoos: windows\ngoarch: amd64\npkg: github.com/pigfu/orderedmap\ncpu: Intel(R) Core(TM) i7-8750H CPU @ 2.20GHz\nBenchmarkNew-12                 17014821                71.68 ns/op\nBenchmarkNewCmp-12              14796138                76.79 ns/op\nBenchmarkNewCmpVal-12            2105310               576.1 ns/op\nPASS\nok      github.com/pigfu/orderedmap     6.172s\n```\n### explain\n\n1. the New function use double linked list,so Set and Del is O(1).\n2. the NewCmp function use skip list,so Set is O(logN) (but update is O(1)) and Del is O(1),because every level is double linked list.\n3. the NewCmpValue function also use skip list,Set is O(logN) (but update is O(logN),because compare value need firstly delete key and then insert) and Del is O(1).\n\n## example\n```go\npackage main\n\nimport (\n\t. \"github.com/pigfu/orderedmap\"\n\t\"fmt\"\n)\n\nvar (\n\tinsertKeys = []int{9, 2, 6, 8, 599, 4, 9, 10, 5, 8, 100}\n\tdeleteKeys = []int{5, 8, 9, 7, 999}\n)\n//key order by insert \nfunc testNew() {\n\tm := New[int, int]()\n\tfor i, k := range insertKeys {\n\t\tm.Set(k, i)\n\t}\n\tfor iter := m.Iter(); iter.Next(); {\n\t\tfmt.Println(iter.KV())\n\t}\n\tfmt.Println(\"------testNew------\")\n\tfor _, k := range deleteKeys {\n\t\tm.Del(k)\n\t}\n\n\tfor iter := m.Iter(); iter.Next(); {\n\t\tfmt.Println(iter.KV())\n\t}\n}\n\nfunc cmp(k1, k2 int) int {\n\tif k1 \u003c k2 {\n\t\treturn -1\n\t}\n\tif k1 \u003e k2 {\n\t\treturn 1\n\t}\n\n\treturn 0\n}\n\n// compare with key\nfunc testNewCmp() {\n\tm := NewCmp[int, int32](cmp)\n\tfor i, k := range insertKeys {\n\t\tm.Set(k, int32(i))\n\t}\n\tfor iter := m.Iter(); iter.Next(); {\n\t\tfmt.Println(iter.KV())\n\t}\n\tfmt.Println(\"------testNewCmp------\")\n\tfor _, k := range deleteKeys {\n\t\tm.Del(k)\n\t}\n\n\tfor iter := m.Iter(); iter.Next(); {\n\t\tfmt.Println(iter.KV())\n\t}\n}\n\nfunc cmpVal(v1, v2 int32) int {\n\tif v1 \u003c v2 {\n\t\treturn -1\n\t}\n\tif v1 \u003e v2 {\n\t\treturn 1\n\t}\n\treturn 0\n}\n//compare with value\nfunc testNewCmpVal() {\n\tm := NewCmpVal[int, int32](cmpVal)\n\tfor i, k := range insertKeys {\n\t\tm.Set(k, int32(i))\n\t}\n\tfor iter := m.Iter(); iter.Next(); {\n\t\tfmt.Println(iter.KV())\n\t}\n\tfmt.Println(\"------testNewCmpVal------\")\n\tfor _, k := range deleteKeys {\n\t\tm.Del(k)\n\t}\n\n\tfor iter := m.Iter(); iter.Next(); {\n\t\tfmt.Println(iter.KV())\n\t}\n}\n\nfunc main() {\n\ttestNew()\n\ttestNewCmp()\n\ttestNewCmpVal()\n}\n```\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpigfu%2Forderedmap","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpigfu%2Forderedmap","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpigfu%2Forderedmap/lists"}