{"id":22409781,"url":"https://github.com/go-faster/city","last_synced_at":"2025-10-07T01:27:21.863Z","repository":{"id":44783947,"uuid":"428861012","full_name":"go-faster/city","owner":"go-faster","description":"go cityhash implementation","archived":false,"fork":false,"pushed_at":"2022-08-07T19:39:48.000Z","size":668,"stargazers_count":37,"open_issues_count":0,"forks_count":3,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-04-09T19:18:40.598Z","etag":null,"topics":["cityhash","go","golang","hashing"],"latest_commit_sha":null,"homepage":"https://clickhouse.com/docs/en/native-protocol/hash","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/go-faster.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-11-17T00:46:40.000Z","updated_at":"2025-02-22T00:11:12.000Z","dependencies_parsed_at":"2022-08-30T16:02:06.597Z","dependency_job_id":null,"html_url":"https://github.com/go-faster/city","commit_stats":null,"previous_names":[],"tags_count":12,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/go-faster%2Fcity","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/go-faster%2Fcity/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/go-faster%2Fcity/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/go-faster%2Fcity/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/go-faster","download_url":"https://codeload.github.com/go-faster/city/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248094990,"owners_count":21046770,"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":["cityhash","go","golang","hashing"],"created_at":"2024-12-05T12:09:42.225Z","updated_at":"2025-10-07T01:27:16.814Z","avatar_url":"https://github.com/go-faster.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# city [![](https://img.shields.io/badge/go-pkg-00ADD8)](https://pkg.go.dev/github.com/go-faster/city#section-documentation) [![](https://img.shields.io/codecov/c/github/go-faster/city?label=cover)](https://codecov.io/gh/go-faster/city) [![stable](https://img.shields.io/badge/-stable-brightgreen)](https://go-faster.org/docs/projects/status#stable)\n[CityHash](https://github.com/google/cityhash) in Go. Fork of [tenfyzhong/cityhash](https://github.com/tenfyzhong/cityhash).\n\nNote: **prefer [xxhash](https://github.com/cespare/xxhash) as non-cryptographic hash algorithm**, this package is intended \nfor places where CityHash is already used.\n\nCityHash **is not compatible** to [FarmHash](https://github.com/google/farmhash), use [go-farm](https://github.com/dgryski/go-farm).\n\n```console\ngo get github.com/go-faster/city\n```\n\n```go\ncity.Hash128([]byte(\"hello\"))\n```\n\n* Faster\n* Supports ClickHouse hash\n\n```\nname            old time/op    new time/op    delta\nCityHash64-32      333ns ± 2%     108ns ± 3%   -67.57%  (p=0.000 n=10+10)\nCityHash128-32     347ns ± 2%     112ns ± 2%   -67.74%  (p=0.000 n=9+10)\n\nname            old speed      new speed      delta\nCityHash64-32   3.08GB/s ± 2%  9.49GB/s ± 3%  +208.40%  (p=0.000 n=10+10)\nCityHash128-32  2.95GB/s ± 2%  9.14GB/s ± 2%  +209.98%  (p=0.000 n=9+10)\n```\n\n## Examples\n\nLet's take 64-bit hash from `Moscow` string.\n\n```sql\n:) SELECT cityHash64('Moscow')\n12507901496292878638\n```\n\n```go\ns := []byte(\"Moscow\")\nfmt.Print(\"ClickHouse: \")\nfmt.Println(city.CH64(s))\nfmt.Print(\"CityHash:   \")\nfmt.Println(city.Hash64(s))\n// Output:\n// ClickHouse: 12507901496292878638\n// CityHash:   5992710078453357409\n```\n\nYou can use [test data corpus](https://github.com/go-faster/city/blob/main/_testdata/data.json) to check your implementation of ClickHouse CityHash variant if needed.\n\n```json\n{\n  \"Seed\": {\n    \"Low\": 5577006791947779410,\n    \"High\": 8674665223082153551\n  },\n  \"entries\": [\n    {\n      \"Input\": \"Moscow\",\n      \"City32\": 431367057,\n      \"City64\": 5992710078453357409,\n      \"City128\": {\n        \"Low\": 10019773792274861915,\n        \"High\": 12276543986707912152\n      },\n      \"City128Seed\": {\n        \"Low\": 13396466470330251720,\n        \"High\": 5508504338941663328\n      },\n      \"ClickHouse64\": 12507901496292878638,\n      \"ClickHouse128\": {\n        \"Low\": 3377444358654451565,\n        \"High\": 2499202049363713365\n      },\n      \"ClickHouse128Seed\": {\n        \"Low\": 568168482305327346,\n        \"High\": 1719721512326527886\n      }\n    }\n  ]\n}\n```\n\n## Benchmarks\n\n```\ngoos: linux\ngoarch: amd64\npkg: github.com/go-faster/city\ncpu: AMD Ryzen 9 5950X 16-Core Processor\nBenchmarkClickHouse128/16     2213.98 MB/s\nBenchmarkClickHouse128/64     4712.24 MB/s\nBenchmarkClickHouse128/256    7561.58 MB/s\nBenchmarkClickHouse128/1024  10158.98 MB/s\nBenchmarkClickHouse64        10379.89 MB/s\nBenchmarkCityHash32           3140.54 MB/s\nBenchmarkCityHash64           9508.45 MB/s\nBenchmarkCityHash128          9304.27 MB/s\nBenchmarkCityHash64Small      2700.84 MB/s\nBenchmarkCityHash128Small     1175.65 MB/s\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgo-faster%2Fcity","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgo-faster%2Fcity","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgo-faster%2Fcity/lists"}