{"id":18310893,"url":"https://github.com/jimschubert/ordered-map","last_synced_at":"2025-04-09T12:10:28.874Z","repository":{"id":65712017,"uuid":"597851038","full_name":"jimschubert/ordered-map","owner":"jimschubert","description":"An ordered map is a go data structure which retains key insertion order","archived":false,"fork":false,"pushed_at":"2023-02-07T03:54:08.000Z","size":35,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-02-15T05:46:20.377Z","etag":null,"topics":["go","golang"],"latest_commit_sha":null,"homepage":"https://pkg.go.dev/github.com/jimschubert/ordered-map","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jimschubert.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null},"funding":{"github":"jimschubert","patreon":"jimschubert"}},"created_at":"2023-02-05T20:22:42.000Z","updated_at":"2023-02-09T18:14:18.000Z","dependencies_parsed_at":"2023-02-19T14:50:18.552Z","dependency_job_id":null,"html_url":"https://github.com/jimschubert/ordered-map","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jimschubert%2Fordered-map","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jimschubert%2Fordered-map/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jimschubert%2Fordered-map/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jimschubert%2Fordered-map/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jimschubert","download_url":"https://codeload.github.com/jimschubert/ordered-map/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248036066,"owners_count":21037092,"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":["go","golang"],"created_at":"2024-11-05T16:15:48.599Z","updated_at":"2025-04-09T12:10:28.856Z","avatar_url":"https://github.com/jimschubert.png","language":"Go","funding_links":["https://github.com/sponsors/jimschubert","https://patreon.com/jimschubert"],"categories":[],"sub_categories":[],"readme":"# ordered-map\n\n[![Apache 2.0 License](https://img.shields.io/badge/License-Apache%202.0-blue)](./LICENSE)\n![Go Version](https://img.shields.io/github/go-mod/go-version/jimschubert/ordered-map)\n[![Go Build](https://github.com/jimschubert/ordered-map/actions/workflows/build.yml/badge.svg)](https://github.com/jimschubert/ordered-map/actions/workflows/build.yml)\n[![Go Report Card](https://goreportcard.com/badge/github.com/jimschubert/ordered-map)](https://goreportcard.com/report/github.com/jimschubert/ordered-map)\n\nPackage `orderedmap` defines a generic Ordered Map data structure with an API similar to that of [container/list](https://pkg.go.dev/container/list).\n\nThe intent of an ordered map is to retain a map's key insertion order, similar to [LinkedHashMap](https://docs.oracle.com/javase/8/docs/api/java/util/LinkedHashMap.html) from Java.\nIt is *not* to constrain a map to *sorted* order.\n\n## Usage\n\nGo does not allow for extensions to built-in maps. As such there is no \"range\" or keyed assignments.\n\nConstruct a map with contents as follows:\n\n\n```go\nmyMap := orderedmap.New[string, string].\n    Set(\"First\", \"1st\").\n    Set(\"Second\", \"2nd\").\n    Set(\"Third\", \"3rd\")\n```\n\nIterate the map with the provided iterator:\n\n```go\nit := myMap.Iterator()\nfor i := it.Next(); i != nil; i = it.Next() {\n    fmt.Printf(\"Shorthand for %q is %q.\\n\", i.Key, i.Value)\n}\n```\n\nOr, with lengthier for loops:\n\n```go\nit := myMap.Iterator()\nvar i *orderedmap.KeyValuePair[string, string]\nfor {\n    i = it.Next()\n    if i == nil {\n        break\n    }\n    fmt.Printf(\"Shorthand for %q is %q.\\n\", i.Key, i.Value)\n}\n````\n\nGet the value defined at some key:\n\n```go\nmyValue, ok := myMap.Get(\"Second\")\n```\n\nThere are also some utility functions:\n\n```go\nmyValue:= myMap.GetOrDefault(\"Tenth\", \"10th\")\nfirst := myMap.First()\nlast := myMap.Last()\n```\n\nThere are functions to manipulate the map as well (including the order of elements):\n\n```go\nremoved, ok := myMap.Remove(\"First\")\nerr := myMap.MoveToFront(\"Third\")\nerr := myMap.MoveToBack(\"Third\")\nerr := myMap.MoveAfter(\"Third\", \"Second\")\nerr := myMap.MoveBefore(\"Third\", \"Fourth\")\nerr := myMap.InsertAfter(\"Third\", \"3rd\", \"Second\")\nerr := myMap.InsertBefore(\"Third\", \"3rd\", \"Fourth\")\n```\n\n# Install\n\n```\ngo get -u github.com/jimschubert/ordered-map\n```\n\n# License\n\nThis project is [licensed](./LICENSE) under Apache 2.0.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjimschubert%2Fordered-map","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjimschubert%2Fordered-map","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjimschubert%2Fordered-map/lists"}