{"id":25654198,"url":"https://github.com/kirill-scherba/omap","last_synced_at":"2026-02-28T02:38:07.811Z","repository":{"id":277364883,"uuid":"931674310","full_name":"kirill-scherba/omap","owner":"kirill-scherba","description":"Omap is Golang package for working with thread safe ordered maps.","archived":false,"fork":false,"pushed_at":"2025-12-31T07:47:02.000Z","size":239,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2026-01-04T09:43:10.534Z","etag":null,"topics":["caching","data-processing","data-structure","go","index","map","omap","ordered-map"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/kirill-scherba.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,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-02-12T17:08:35.000Z","updated_at":"2025-12-31T07:49:03.000Z","dependencies_parsed_at":"2025-05-26T11:33:47.193Z","dependency_job_id":null,"html_url":"https://github.com/kirill-scherba/omap","commit_stats":null,"previous_names":["kirill-scherba/omap"],"tags_count":13,"template":false,"template_full_name":null,"purl":"pkg:github/kirill-scherba/omap","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kirill-scherba%2Fomap","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kirill-scherba%2Fomap/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kirill-scherba%2Fomap/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kirill-scherba%2Fomap/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kirill-scherba","download_url":"https://codeload.github.com/kirill-scherba/omap/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kirill-scherba%2Fomap/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29923410,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-27T19:37:42.220Z","status":"online","status_checked_at":"2026-02-28T02:00:07.010Z","response_time":90,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":["caching","data-processing","data-structure","go","index","map","omap","ordered-map"],"created_at":"2025-02-23T20:18:28.715Z","updated_at":"2026-02-28T02:38:07.795Z","avatar_url":"https://github.com/kirill-scherba.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Ordered map\n\nOmap is Golang package for working with thread safe ordered maps. The ordered\nmap contains the golang map, list and mutex to execute Ordered Map functions.\n\nThe Ordered Map is a map that remembers the order of items. The map can be\niterated over to retrieve the items in the order they were added.\n\n[![GoDoc](https://godoc.org/github.com/kirill-scherba/omap?status.svg)](https://godoc.org/github.com/kirill-scherba/omap/)\n[![Go Report Card](https://goreportcard.com/badge/github.com/kirill-scherba/omap)](https://goreportcard.com/report/github.com/kirill-scherba/omap)\n\n![Omap](img/omap.jpg)\n\n## Introduction to the omap Go Package\n\nThe omap Go package is a lightweight and efficient library for working with\nordered maps in Go. An ordered map is a data structure that combines the\nbenefits of a map and a list, allowing you to store key-value pairs in a\nspecific order.\n\n## What is omap?\n\nOmap is a Go package that provides an implementation of an ordered map. It is\ndesigned to be fast, efficient, and easy to use. Omap is particularly useful\nwhen you need to store data in a specific order, such as when working with\nconfiguration files, caching, or data processing pipelines.\n\n## Key Features of omap\n\n- Ordered: omap preserves the order in which key-value pairs are inserted,\nallowing you to iterate over the map in a specific order.\n\n- Fast lookups: omap uses a hash table to store key-value pairs, making lookups\nfast and efficient.\n\n- Efficient insertion and deletion: omap uses a linked list to store the order of\nkey-value pairs, making insertion and deletion operations efficient.\n\n## Using omap\n\nTo use omap, you can install it using the following command:\n\n```bash\ngo get github.com/kirill-scherba/omap\n```\n\nHere is an example of how to use omap:\n\n```go\npackage main\n\nimport (\n    \"fmt\"\n    \"log\"\n\n    \"github.com/kirill-scherba/omap\"\n)\n\nfunc main() {\n    // Create a new ordered map\n    m, err := omap.New[string, string]()\n    if err != nil {\n        log.Fatal(err)\n    }\n\n    // Insert some key-value pairs\n    m.Set(\"key1\", \"value1\")\n    m.Set(\"key2\", \"value2\")\n    m.Set(\"key3\", \"value3\")\n\n    // Iterate over the omap in order\n    for _, pair := range m.Pairs() {\n        fmt.Printf(\"%s: %s\\n\", pair.Key, pair.Value)\n    }\n}\n```\n\nThis code creates a new omap, inserts some key-value pairs, and then iterates over the omap in order, printing out each key-value pair.\n\nExecute this example on Go playground: [https://go.dev/play/p/LzauNwMuezB](https://go.dev/play/p/LzauNwMuezB)\n\nOr run it on your local machine: `go run ./examples/pairs/`\n\n## Conclusion\n\nThe omap Go package is a useful library for working with ordered maps in Go. Its fast lookups, efficient insertion and deletion, and ordered iteration make it a great choice for a variety of use cases. Whether you're working with configuration files, caching, or data processing pipelines, omap is definitely worth considering.\n\n## Example Use Cases\n\n- Configuration files: Use omap to store configuration data in a specific order, making it easy to iterate over the configuration and apply settings in the correct order.\n\n- Caching: Use omap to store cached data in a specific order, making it easy to iterate over the cache and evict items in the correct order.\n\n- Data processing pipelines: Use omap to store data in a specific order, making it easy to iterate over the data and process it in the correct order.\n\n## Examples\n\n### Basic usage example\n\n```go\npackage main\n\nimport (\n    \"fmt\"\n    \"log\"\n\n    \"github.com/kirill-scherba/omap\"\n)\n\nfunc main() {\n    fmt.Println(\"Ordered map basic example\")\n\n    // Struct to store in ordered map\n    type Person struct {\n        Name string\n        Age  int\n    }\n\n    // Create new ordered map\n    o, err := omap.New[string, *Person]()\n    if err != nil {\n        log.Fatal(err)\n    }\n\n    // Add records to ordered map\n    o.Set(\"John\", \u0026Person{Name: \"John\", Age: 30})\n    o.Set(\"Jane\", \u0026Person{Name: \"Jane\", Age: 25})\n    o.Set(\"Bob\", \u0026Person{Name: \"Bob\", Age: 40})\n    o.Set(\"Alice\", \u0026Person{Name: \"Alice\", Age: 35})\n\n    // Print all records\n    fmt.Print(\"\\nList records ordered by default (insertion):\\n\\n\")\n    o.ForEach(func(key string, data *Person) {\n        fmt.Println(key, data)\n    })\n}\n```\n\nExecute this example on Go playground: [https://go.dev/play/p/T1VMf1J5n4_H](https://go.dev/play/p/T1VMf1J5n4_H)\n\nOr run it on your local machine: `go run ./examples/basic/`\n\n### Multiple indexes example\n\nBy default, the ordered map is created with one default (insertion) index.\n\nYou can create additional indexes by adding there sort functions and names to\nthe ordered map creation function. All indexes are recalculated on each\noperation with map.\n\n```go\npackage main\n\nimport (\n    \"fmt\"\n    \"log\"\n    \"strings\"\n\n    \"github.com/kirill-scherba/omap\"\n)\n\n// Struct to store in ordered map\ntype Person struct {\n    Name string\n    Age  int\n}\n\nfunc main() {\n    fmt.Println(\"Ordered map multiple indexes example\")\n\n    // Create new ordered map with indexes by Name and Age\n    o, err := omap.New(\n        omap.Index[string, *Person]{Key: \"Name\", Func: CompareByName},\n        omap.Index[string, *Person]{Key: \"Key\", Func: omap.CompareByKey[string, *Person]},\n        omap.Index[string, *Person]{Key: \"AgeAsc\", Func: CompareByAgeAsc},\n        omap.Index[string, *Person]{Key: \"AgeDesc\", Func: CompareByAgeDesc},\n    )\n    if err != nil {\n        log.Fatal(err)\n    }\n\n    // Add records to ordered map\n    o.Set(\"John\", \u0026Person{Name: \"John\", Age: 30})\n    o.Set(\"Jane\", \u0026Person{Name: \"Jane\", Age: 25})\n    o.Set(\"Bob\", \u0026Person{Name: \"Bob\", Age: 40})\n    o.Set(\"Alice\", \u0026Person{Name: \"Alice\", Age: 35})\n\n    // Print all records\n    fmt.Print(\"\\nList records ordered by default (insertion):\\n\\n\")\n    o.ForEach(func(key string, data *Person) {\n        fmt.Println(key, data)\n    })\n\n    // Print all records by Name index\n    fmt.Print(\"\\nList records ordered by Name index:\\n\\n\")\n    o.ForEach(func(key string, data *Person) {\n        fmt.Println(key, data)\n    }, \"Name\")\n\n    // Print all records by Age ascending index\n    fmt.Print(\"\\nList records ordered by Age index:\\n\\n\")\n    o.ForEach(func(key string, data *Person) {\n        fmt.Println(key, data)\n    }, \"AgeAsc\")\n\n    // Print all records by Age descending index\n    fmt.Print(\"\\nList records ordered by Age index:\\n\\n\")\n    o.ForEach(func(key string, data *Person) {\n        fmt.Println(key, data)\n    }, \"AgeDesc\")\n}\n\nfunc CompareByName(r1, r2 *omap.Record[string, *Person]) int {\n    return strings.Compare(\n        strings.ToLower(r1.Data().Name), strings.ToLower(r2.Data().Name),\n    )\n}\n\nfunc CompareByAgeAsc(r1, r2 *omap.Record[string, *Person]) int {\n    return r1.Data().Age - r2.Data().Age\n}\n\nfunc CompareByAgeDesc(r1, r2 *omap.Record[string, *Person]) int {\n    return r2.Data().Age - r1.Data().Age\n}\n\n```\n\nExecute this example on Go playground: [https://go.dev/play/p/ppUx3Afn7ky](https://go.dev/play/p/ppUx3Afn7ky)\n\nOr run it on your local machine: `go run ./examples/multiple_index/`\n\n## Licence\n\n[BSD](LICENSE)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkirill-scherba%2Fomap","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkirill-scherba%2Fomap","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkirill-scherba%2Fomap/lists"}