{"id":13397050,"url":"https://github.com/elliotchance/orderedmap","last_synced_at":"2025-05-12T15:25:19.120Z","repository":{"id":41432434,"uuid":"221787679","full_name":"elliotchance/orderedmap","owner":"elliotchance","description":"🔃 An ordered map in Go with amortized O(1) for Set, Get, Delete and Len.","archived":false,"fork":false,"pushed_at":"2025-04-16T15:47:24.000Z","size":71,"stargazers_count":944,"open_issues_count":17,"forks_count":73,"subscribers_count":15,"default_branch":"master","last_synced_at":"2025-04-23T17:15:28.514Z","etag":null,"topics":["data-structures","golang","maps","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/elliotchance.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":"2019-11-14T21:12:26.000Z","updated_at":"2025-04-23T08:11:11.000Z","dependencies_parsed_at":"2024-01-13T23:08:02.693Z","dependency_job_id":"8699bd64-009f-4fe3-b973-3bac6517d4a8","html_url":"https://github.com/elliotchance/orderedmap","commit_stats":{"total_commits":20,"total_committers":12,"mean_commits":"1.6666666666666667","dds":0.7,"last_synced_commit":"9767ae76ac94a5c8ee50538ef6480c25629071c4"},"previous_names":[],"tags_count":30,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elliotchance%2Forderedmap","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elliotchance%2Forderedmap/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elliotchance%2Forderedmap/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elliotchance%2Forderedmap/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/elliotchance","download_url":"https://codeload.github.com/elliotchance/orderedmap/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253764471,"owners_count":21960585,"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":["data-structures","golang","maps","orderedmap"],"created_at":"2024-07-30T18:01:10.197Z","updated_at":"2025-05-12T15:25:19.094Z","avatar_url":"https://github.com/elliotchance.png","language":"Go","funding_links":[],"categories":["开源类库","Open source library","Go"],"sub_categories":["数据结构","Data Structure"],"readme":"# 🔃 github.com/elliotchance/orderedmap/v3 [![GoDoc](https://godoc.org/github.com/elliotchance/orderedmap/v3?status.svg)](https://godoc.org/github.com/elliotchance/orderedmap/v3)\n\n## Basic Usage\n\nAn `*OrderedMap` is a high performance ordered map that maintains amortized O(1)\nfor `Set`, `Get`, `Delete` and `Len`:\n\n```go\nimport \"github.com/elliotchance/orderedmap/v3\"\n\nfunc main() {\n\tm := orderedmap.NewOrderedMap[string, any]()\n\n\tm.Set(\"foo\", \"bar\")\n\tm.Set(\"qux\", 1.23)\n\tm.Set(\"123\", true)\n\n\tm.Delete(\"qux\")\n}\n```\n\n\u003e [!NOTE]\n\u003e\n\u003e - _v3 requires Go v1.23_ - If you need to support Go 1.18-1.22, you can use v2.\n\u003e - _v2 requires Go v1.18 for generics_ - If you need to support Go 1.17 or below, you can use v1.\n\nInternally an `*OrderedMap` uses the composite type\n[map](https://go.dev/blog/maps) combined with a\ntrimmed down linked list to maintain the order.\n\n## Iterating\n\nThe following methods all return\n[iterators](https://go.dev/doc/go1.23#iterators) that can be used to loop over\nelements in an ordered map:\n\n- `AllFromFront()`\n- `AllFromBack()`\n- `Keys()`\n- `Values()`\n\n```go\n// Iterate through all elements from oldest to newest:\nfor key, value := range m.AllFromFront() {\n\tfmt.Println(key, value)\n}\n```\n\nIterators are safe to use bidirectionally, and will return `nil` once it goes\nbeyond the first or last item. If the map is changing while the iteration is\nin-flight it may produce unexpected behavior.\n\nIf you want to get a slice of the map keys or values, you can use the standard\n`slices.Collect` method with the iterator returned from `Keys()` or `Values()`:\n\n```go\nfmt.Println(slices.Collect(m.Keys())\n// [A B C]\n```\n\nLikewise, calling `maps.Collect` on the iterator returned from `AllFromFront()`\nwill create a regular unordered map from the ordered one:\n\n```go\nfmt.Println(maps.Collect(m.AllFromFront())\n// [A:1 B:2 C:3]\n```\n\nIf you don't want to use iterators, you can also manually loop over the elements\nusing `Front()` or `Back()` with `Next()`:\n\n```go\n// Iterate through all elements from oldest to newest:\nfor el := m.Front(); el != nil; el = el.Next() {\n    fmt.Println(el.Key, el.Value)\n}\n\n// You can also use Back and Prev to iterate in reverse:\nfor el := m.Back(); el != nil; el = el.Prev() {\n    fmt.Println(el.Key, el.Value)\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Felliotchance%2Forderedmap","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Felliotchance%2Forderedmap","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Felliotchance%2Forderedmap/lists"}