{"id":22762273,"url":"https://github.com/xusworld/dconcurrent-map","last_synced_at":"2025-03-30T09:21:30.437Z","repository":{"id":57617204,"uuid":"368149331","full_name":"xusworld/dconcurrent-map","owner":"xusworld","description":"Golang high performance current hashmap.","archived":false,"fork":false,"pushed_at":"2021-07-14T07:02:22.000Z","size":30,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-12-11T10:08:18.464Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","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/xusworld.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":"2021-05-17T10:44:24.000Z","updated_at":"2022-07-08T01:59:14.000Z","dependencies_parsed_at":"2022-08-29T05:31:51.789Z","dependency_job_id":null,"html_url":"https://github.com/xusworld/dconcurrent-map","commit_stats":null,"previous_names":["xusworld/concurrentmap"],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xusworld%2Fdconcurrent-map","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xusworld%2Fdconcurrent-map/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xusworld%2Fdconcurrent-map/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xusworld%2Fdconcurrent-map/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/xusworld","download_url":"https://codeload.github.com/xusworld/dconcurrent-map/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246297535,"owners_count":20754805,"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":[],"created_at":"2024-12-11T10:07:16.510Z","updated_at":"2025-03-30T09:21:30.414Z","avatar_url":"https://github.com/xusworld.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# dconcurrent-map\n\ndconcurrent-map based on orcaman's cool job [concurrent-map](https://github.com/orcaman/concurrent-map)\n\n## API\n\n```go\n// create a brand new thread safe map\nsm := New()\n\t\n// set key/val pair to map\nsm.Set(\"Hello\", \"World\")\n\t\n// get the specified element\nsm.Get(\"Hello\")\n\t\n// remove the specified key/val pair from map \nsm.Remove(\"Hello\")\n\t\n// returns the number of elements within the map\nsm.Count()\n\t\n// checks if map is empty\nsm.IsEmpty()\n\t\n// removes all items from map\nsm.Clear()\n\t\n// returns all items as map[interface{}]interface{}\nsm.Items()\n\t\n// returns all keys as []interface{}\nsm.Keys()\n\t\n// looks up an item under specified key\nsm.Has(\"Hello\")\n\t\n// removes an element from the map and returns it\nsm.Pop(\"Hello\")\n\t\n\t\nitems := map[interface{}]interface{}{\n\t\"Hello\":\"world\",\n}\n// set all items of parameter  to map\nsm.MSet(items)\n\t\n```\n\n## hash function \n\n`hash()` can many golang build-in type.\n\n```go\nfunc hash(key interface{}) uint32 {\n\tbuff, err := toBytes(key)\n\tif err != nil {\n\t\tpanic(\"toBytes() error\")\n\t\treturn 0\n\t}\n\treturn crc32.ChecksumIEEE(buff)\n}\n\nfunc toBytes(key interface{}) ([]byte, error) {\n\tbs := make([]byte, 8)\n\tbuff := bytes.NewBuffer(bs)\n\tswitch v := key.(type) {\n\tcase *string:\n\t\treturn []byte(*v), nil\n\tcase string:\n\t\treturn []byte(v), nil\n\tcase *bool:\n\t\tif *v {\n\t\t\tbuff.WriteByte(byte(1))\n\t\t} else {\n\t\t\tbuff.WriteByte(byte(0))\n\t\t}\n\t\treturn buff.Bytes()[:1], nil\n\tcase bool:\n\t\tif v {\n\t\t\tbuff.WriteByte(byte(1))\n\t\t} else {\n\t\t\tbuff.WriteByte(byte(0))\n\t\t}\n\t\treturn buff.Bytes()[:1], nil\n\tcase *int8:\n\t\tbuff.WriteByte(byte(*v))\n\t\treturn buff.Bytes()[:1], nil\n\tcase int8:\n\t\tbuff.WriteByte(byte(v))\n\t\treturn buff.Bytes()[:1], nil\n\tcase *uint8:\n\t\tbuff.WriteByte(*v)\n\t\treturn buff.Bytes()[:1], nil\n\tcase uint8:\n\t\tbuff.WriteByte(v)\n\t\treturn buff.Bytes()[:1], nil\n\tcase *int16:\n\t\t_ = binary.Write(buff, binary.BigEndian, v)\n\t\treturn buff.Bytes()[:2], nil\n\tcase int16:\n\t\t_ = binary.Write(buff, binary.BigEndian, v)\n\t\treturn buff.Bytes()[:2], nil\n\tcase *int32:\n\t\t_ = binary.Write(buff, binary.BigEndian, v)\n\t\treturn buff.Bytes()[:4], nil\n\tcase int32:\n\t\t_ = binary.Write(buff, binary.BigEndian, v)\n\t\treturn buff.Bytes()[:4], nil\n\tcase *int64:\n\t\t_ = binary.Write(buff, binary.BigEndian, v)\n\t\treturn buff.Bytes()[:8], nil\n\tcase int64:\n\t\t_ = binary.Write(buff, binary.BigEndian, v)\n\t\treturn buff.Bytes()[:8], nil\n\tdefault:\n\t\treturn nil, errInvalidKeyType\n\t}\n}\n\n```\n\n\n## TODO\n1. change key type to interface{} will cause performance loss  \n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxusworld%2Fdconcurrent-map","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fxusworld%2Fdconcurrent-map","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxusworld%2Fdconcurrent-map/lists"}