{"id":17683043,"url":"https://github.com/shomali11/maps","last_synced_at":"2025-05-12T23:51:24.173Z","repository":{"id":57523939,"uuid":"99450490","full_name":"shomali11/maps","owner":"shomali11","description":"Concurrent Map","archived":false,"fork":false,"pushed_at":"2019-06-08T14:53:02.000Z","size":86,"stargazers_count":4,"open_issues_count":0,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-13T03:49:07.586Z","etag":null,"topics":["concurrent","concurrent-map","map","multimap","shard","sharding"],"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/shomali11.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}},"created_at":"2017-08-05T22:15:01.000Z","updated_at":"2024-10-02T01:11:22.000Z","dependencies_parsed_at":"2022-09-15T18:23:56.751Z","dependency_job_id":null,"html_url":"https://github.com/shomali11/maps","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shomali11%2Fmaps","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shomali11%2Fmaps/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shomali11%2Fmaps/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shomali11%2Fmaps/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/shomali11","download_url":"https://codeload.github.com/shomali11/maps/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253843167,"owners_count":21972868,"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":["concurrent","concurrent-map","map","multimap","shard","sharding"],"created_at":"2024-10-24T09:44:11.454Z","updated_at":"2025-05-12T23:51:24.142Z","avatar_url":"https://github.com/shomali11.png","language":"Go","readme":"# maps [![Build Status](https://travis-ci.com/shomali11/maps.svg?branch=master)](https://travis-ci.com/shomali11/maps) [![Go Report Card](https://goreportcard.com/badge/github.com/shomali11/maps)](https://goreportcard.com/report/github.com/shomali11/maps) [![GoDoc](https://godoc.org/github.com/shomali11/maps?status.svg)](https://godoc.org/github.com/shomali11/maps) [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)\n\nA collection of various maps with concurrent versions that supports concurrent reads and writes.\n\n## Features\n\n* Thread safe\n* Available types:\n    * Maps:\n        * Multi Map\n    * Concurrent Maps:\n        * Concurrent Map\n        * Concurrent Multi Map\n    * Sharded Concurrent Maps:\n        * Sharded Concurrent Map\n        * Sharded Concurrent Multi Map\n\n_Note: Sharded versions provides improved performance by reducing the number of write locks_\n\n## Dependencies\n\n* `util` [github.com/shomali11/util](https://github.com/shomali11/util)\n\n# Examples\n\n## Example 1\n\nUsing `NewConcurrentMap` to create a concurrent map\n\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\t\"github.com/shomali11/maps\"\n)\n\nfunc main() {\n\tconcurrentMap := maps.NewConcurrentMap()\n\tconcurrentMap.Set(\"name\", \"Raed Shomali\")\n\n\tfmt.Println(concurrentMap.ContainsKey(\"name\")) // true\n\tfmt.Println(concurrentMap.Get(\"name\"))      // \"Raed Shomali\" true\n\tfmt.Println(concurrentMap.Size())           // 1\n\tfmt.Println(concurrentMap.IsEmpty())        // false\n\tfmt.Println(concurrentMap.Keys())           // [\"name\"]\n\n\tconcurrentMap.Remove(\"name\")\n\n\tfmt.Println(concurrentMap.ContainsKey(\"name\")) // false\n\tfmt.Println(concurrentMap.Get(\"name\"))      // \u003cnil\u003e false\n\tfmt.Println(concurrentMap.Size())           // 0\n\tfmt.Println(concurrentMap.IsEmpty())        // true\n\tfmt.Println(concurrentMap.Keys())           // []\n\n\tconcurrentMap.Set(\"name\", \"Raed Shomali\")\n\tconcurrentMap.Clear()\n\n\tfmt.Println(concurrentMap.ContainsKey(\"name\")) // false\n\tfmt.Println(concurrentMap.Get(\"name\"))      // \u003cnil\u003e false\n\tfmt.Println(concurrentMap.Size())           // 0\n\tfmt.Println(concurrentMap.IsEmpty())        // true\n\tfmt.Println(concurrentMap.Keys())           // []\n}\n```\n\n## Example 2\n\nUsing `NewShardedConcurrentMap` to create a sharded concurrent map. _Default shards are 16_\n\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\t\"github.com/shomali11/maps\"\n)\n\nfunc main() {\n\tconcurrentMap := maps.NewShardedConcurrentMap()\n\tconcurrentMap.Set(\"name\", \"Raed Shomali\")\n\n\tfmt.Println(concurrentMap.ContainsKey(\"name\")) // true\n\tfmt.Println(concurrentMap.Get(\"name\"))      // \"Raed Shomali\" true\n\tfmt.Println(concurrentMap.Size())           // 1\n\tfmt.Println(concurrentMap.IsEmpty())        // false\n\tfmt.Println(concurrentMap.Keys())           // [\"name\"]\n\n\tconcurrentMap.Remove(\"name\")\n\n\tfmt.Println(concurrentMap.ContainsKey(\"name\")) // false\n\tfmt.Println(concurrentMap.Get(\"name\"))      // \u003cnil\u003e false\n\tfmt.Println(concurrentMap.Size())           // 0\n\tfmt.Println(concurrentMap.IsEmpty())        // true\n\tfmt.Println(concurrentMap.Keys())           // []\n\n\tconcurrentMap.Set(\"name\", \"Raed Shomali\")\n\tconcurrentMap.Clear()\n\n\tfmt.Println(concurrentMap.ContainsKey(\"name\")) // false\n\tfmt.Println(concurrentMap.Get(\"name\"))      // \u003cnil\u003e false\n\tfmt.Println(concurrentMap.Size())           // 0\n\tfmt.Println(concurrentMap.IsEmpty())        // true\n\tfmt.Println(concurrentMap.Keys())           // []\n}\n```\n\n## Example 3\n\nUsing `WithNumberOfShards` to override default number of shards\n\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\t\"github.com/shomali11/maps\"\n)\n\nfunc main() {\n\tconcurrentMap := maps.NewShardedConcurrentMap(maps.WithNumberOfShards(100))\n\tconcurrentMap.Set(\"name\", \"Raed Shomali\")\n\n\tfmt.Println(concurrentMap.ContainsKey(\"name\")) // true\n\tfmt.Println(concurrentMap.Get(\"name\"))      // \"Raed Shomali\" true\n\tfmt.Println(concurrentMap.Size())           // 1\n\tfmt.Println(concurrentMap.IsEmpty())        // false\n\tfmt.Println(concurrentMap.Keys())           // [\"name\"]\n\n\tconcurrentMap.Remove(\"name\")\n\n\tfmt.Println(concurrentMap.ContainsKey(\"name\")) // false\n\tfmt.Println(concurrentMap.Get(\"name\"))      // \u003cnil\u003e false\n\tfmt.Println(concurrentMap.Size())           // 0\n\tfmt.Println(concurrentMap.IsEmpty())        // true\n\tfmt.Println(concurrentMap.Keys())           // []\n\n\tconcurrentMap.Set(\"name\", \"Raed Shomali\")\n\tconcurrentMap.Clear()\n\n\tfmt.Println(concurrentMap.ContainsKey(\"name\")) // false\n\tfmt.Println(concurrentMap.Get(\"name\"))      // \u003cnil\u003e false\n\tfmt.Println(concurrentMap.Size())           // 0\n\tfmt.Println(concurrentMap.IsEmpty())        // true\n\tfmt.Println(concurrentMap.Keys())           // []\n}\n```\n\n## Example 4\n\nUsing `NewConcurrentMultiMap` to create a concurrent multi map\n\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\t\"github.com/shomali11/maps\"\n)\n\nfunc main() {\n\tconcurrentMap := maps.NewConcurrentMultiMap()\n\tconcurrentMap.Set(\"names\", []interface{}{\"Raed Shomali\"})\n\tconcurrentMap.Append(\"names\", \"Dwayne Johnson\")\n\n\tfmt.Println(concurrentMap.ContainsKey(\"names\")) // true\n\tfmt.Println(concurrentMap.Get(\"names\"))      // [\"Raed Shomali\" \"Dwayne Johnson\"] true\n\tfmt.Println(concurrentMap.Size())            // 1\n\tfmt.Println(concurrentMap.IsEmpty())         // false\n\tfmt.Println(concurrentMap.Keys())            // [\"name\"]\n\n\tconcurrentMap.Remove(\"names\")\n\n\tfmt.Println(concurrentMap.ContainsKey(\"names\")) // false\n\tfmt.Println(concurrentMap.Get(\"names\"))      // [] false\n\tfmt.Println(concurrentMap.Size())            // 0\n\tfmt.Println(concurrentMap.IsEmpty())         // true\n\tfmt.Println(concurrentMap.Keys())            // []\n\n\tconcurrentMap.Append(\"names\", \"Raed Shomali\")\n\tconcurrentMap.Clear()\n\n\tfmt.Println(concurrentMap.ContainsKey(\"names\")) // false\n\tfmt.Println(concurrentMap.Get(\"names\"))      // [] false\n\tfmt.Println(concurrentMap.Size())            // 0\n\tfmt.Println(concurrentMap.IsEmpty())         // true\n\tfmt.Println(concurrentMap.Keys())            // []\n}\n```\n\n## Example 5\n\nUsing `NewShardedConcurrentMultiMap` to create a sharded concurrent multi map. _Default shards are 16_\n\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\t\"github.com/shomali11/maps\"\n)\n\nfunc main() {\n\tconcurrentMap := maps.NewShardedConcurrentMultiMap()\n\tconcurrentMap.Set(\"names\", []interface{}{\"Raed Shomali\"})\n\tconcurrentMap.Append(\"names\", \"Dwayne Johnson\")\n\n\tfmt.Println(concurrentMap.ContainsKey(\"names\")) // true\n\tfmt.Println(concurrentMap.Get(\"names\"))      // [\"Raed Shomali\" \"Dwayne Johnson\"] true\n\tfmt.Println(concurrentMap.Size())            // 1\n\tfmt.Println(concurrentMap.IsEmpty())         // false\n\tfmt.Println(concurrentMap.Keys())            // [\"name\"]\n\n\tconcurrentMap.Remove(\"names\")\n\n\tfmt.Println(concurrentMap.ContainsKey(\"names\")) // false\n\tfmt.Println(concurrentMap.Get(\"names\"))      // [] false\n\tfmt.Println(concurrentMap.Size())            // 0\n\tfmt.Println(concurrentMap.IsEmpty())         // true\n\tfmt.Println(concurrentMap.Keys())            // []\n\n\tconcurrentMap.Append(\"names\", \"Raed Shomali\")\n\tconcurrentMap.Clear()\n\n\tfmt.Println(concurrentMap.ContainsKey(\"names\")) // false\n\tfmt.Println(concurrentMap.Get(\"names\"))      // [] false\n\tfmt.Println(concurrentMap.Size())            // 0\n\tfmt.Println(concurrentMap.IsEmpty())         // true\n\tfmt.Println(concurrentMap.Keys())            // []\n}\n```\n\n## Example 6\n\nUsing `WithNumberOfShards` to override default number of shards\n\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\t\"github.com/shomali11/maps\"\n)\n\nfunc main() {\n\tconcurrentMap := maps.NewShardedConcurrentMultiMap(maps.WithNumberOfShards(100))\n\tconcurrentMap.Set(\"names\", []interface{}{\"Raed Shomali\"})\n\tconcurrentMap.Append(\"names\", \"Dwayne Johnson\")\n\n\tfmt.Println(concurrentMap.ContainsKey(\"names\")) // true\n\tfmt.Println(concurrentMap.Get(\"names\"))      // [\"Raed Shomali\" \"Dwayne Johnson\"] true\n\tfmt.Println(concurrentMap.Size())            // 1\n\tfmt.Println(concurrentMap.IsEmpty())         // false\n\tfmt.Println(concurrentMap.Keys())            // [\"name\"]\n\n\tconcurrentMap.Remove(\"names\")\n\n\tfmt.Println(concurrentMap.ContainsKey(\"names\")) // false\n\tfmt.Println(concurrentMap.Get(\"names\"))      // [] false\n\tfmt.Println(concurrentMap.Size())            // 0\n\tfmt.Println(concurrentMap.IsEmpty())         // true\n\tfmt.Println(concurrentMap.Keys())            // []\n\n\tconcurrentMap.Append(\"names\", \"Raed Shomali\")\n\tconcurrentMap.Clear()\n\n\tfmt.Println(concurrentMap.ContainsKey(\"names\")) // false\n\tfmt.Println(concurrentMap.Get(\"names\"))      // [] false\n\tfmt.Println(concurrentMap.Size())            // 0\n\tfmt.Println(concurrentMap.IsEmpty())         // true\n\tfmt.Println(concurrentMap.Keys())            // []\n}\n```","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshomali11%2Fmaps","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fshomali11%2Fmaps","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshomali11%2Fmaps/lists"}