{"url":"https://api.github.com/gists/5423680","forks_url":"https://api.github.com/gists/5423680/forks","commits_url":"https://api.github.com/gists/5423680/commits","id":"5423680","node_id":"MDQ6R2lzdDU0MjM2ODA=","git_pull_url":"https://gist.github.com/5423680.git","git_push_url":"https://gist.github.com/5423680.git","html_url":"https://gist.github.com/mbostock/5423680","files":{".block":{"filename":".block","type":"text/plain","language":null,"raw_url":"https://gist.githubusercontent.com/mbostock/5423680/raw/703d310b399098a243a76a50bc209167e924cfd2/.block","size":17,"truncated":false,"content":"license: gpl-3.0\n","encoding":"utf-8"},"README.md":{"filename":"README.md","type":"text/markdown","language":"Markdown","raw_url":"https://gist.githubusercontent.com/mbostock/5423680/raw/1796574074a6109b97c3d899cea2b96b60f39390/README.md","size":82,"truncated":false,"content":"Testing a possible hash function for points (pairs of floating-point coordinates).","encoding":"utf-8"},"index.html":{"filename":"index.html","type":"text/html","language":"HTML","raw_url":"https://gist.githubusercontent.com/mbostock/5423680/raw/45c9d296ef1f589993840cbd974ddae93f588876/index.html","size":2620,"truncated":false,"content":"<!DOCTYPE html>\n<meta charset=\"utf-8\">\n<style>\n\n.bar {\n  fill: steelblue;\n}\n\n.axis line,\n.axis path {\n  fill: none;\n  stroke: #000;\n  shape-rendering: crispEdges;\n}\n\n.axis text {\n  display: none;\n}\n\n</style>\n<body>\n<script src=\"//d3js.org/d3.v3.min.js\"></script>\n<script src=\"//d3js.org/topojson.v1.min.js\"></script>\n<script>\n\nvar m = 256,\n    bins = d3.range(m).map(function() { return 0; });\n\nvar margin = {top: 20, right: 30, bottom: 30, left: 40},\n    width = 960 - margin.left - margin.right,\n    height = 500 - margin.top - margin.bottom;\n\nvar x = d3.scale.ordinal()\n    .domain(d3.range(m))\n    .rangeBands([0, width], .1);\n\nvar y = d3.scale.linear()\n    .range([height, 0]);\n\nvar xAxis = d3.svg.axis()\n    .scale(x)\n    .orient(\"bottom\")\n    .tickSize(4, 0);\n\nvar svg = d3.select(\"body\").append(\"svg\")\n    .attr(\"width\", width + margin.left + margin.right)\n    .attr(\"height\", height + margin.top + margin.bottom)\n  .append(\"g\")\n    .attr(\"transform\", \"translate(\" + margin.left + \",\" + margin.top + \")\");\n\nsvg.append(\"g\")\n    .attr(\"class\", \"bar\")\n  .selectAll(\"rect\")\n    .data(bins)\n  .enter().append(\"rect\")\n    .attr(\"y\", height)\n    .attr(\"width\", x.rangeBand())\n    .attr(\"x\", function(d, i) { return x(i); });\n\nsvg.append(\"g\")\n    .attr(\"class\", \"x axis\")\n    .attr(\"transform\", \"translate(0,\" + height + \")\")\n    .call(xAxis);\n\nvar bars = svg.selectAll(\".bar rect\")[0].map(d3.select);\n\nd3.json(\"/mbostock/raw/4090846/us.json\", function(error, us) {\n  if (error) throw error;\n\n  var collection = topojson.feature(us, us.objects.counties), points = [];\n\n  collection.features.forEach(function(f) {\n    var g = f.geometry;\n    if (g) switch (g.type) {\n      case \"MultiPolygon\": g.coordinates.forEach(polygon); break;\n      case \"Polygon\": g.coordinates.forEach(ring); break;\n    }\n  });\n\n  function polygon(coordinates) {\n    coordinates.forEach(ring);\n  }\n\n  function ring(coordinates) {\n    coordinates.forEach(point);\n  }\n\n  function point(coordinates) {\n    points.push(coordinates);\n  }\n\n  y.domain([0, points.length / m * 2]);\n\n  d3.timer(function() {\n    for (var k = 0, p; k < 100; ++k) {\n      if (!(p = points.pop())) return true;\n      var i = Math.abs(hash2(p[0], p[1]) % m), j = ++bins[i];\n      bars[i].attr(\"y\", y(j)).attr(\"height\", height - y(j));\n    }\n  });\n});\n\nvar buffer = new ArrayBuffer(8),\n    floats = new Float64Array(buffer),\n    ints = new Int32Array(buffer);\n\nfunction hash1(x) {\n  floats[0] = x;\n  x = ints[1] ^ ints[0];\n  x ^= (x >>> 20) ^ (x >>> 12);\n  x ^= (x >>> 7) ^ (x >>> 4);\n  return x;\n}\n\nfunction hash2(x, y) {\n  return (hash1(x) + 31 * hash1(y)) | 0;\n}\n\n</script>\n","encoding":"utf-8"}},"public":true,"created_at":"2013-04-19T22:33:31Z","updated_at":"2016-02-09T02:06:26Z","description":"Hashing Points","comments":0,"user":null,"comments_enabled":true,"comments_url":"https://api.github.com/gists/5423680/comments","owner":{"login":"mbostock","id":230541,"node_id":"MDQ6VXNlcjIzMDU0MQ==","avatar_url":"https://avatars.githubusercontent.com/u/230541?v=4","gravatar_id":"","url":"https://api.github.com/users/mbostock","html_url":"https://github.com/mbostock","followers_url":"https://api.github.com/users/mbostock/followers","following_url":"https://api.github.com/users/mbostock/following{/other_user}","gists_url":"https://api.github.com/users/mbostock/gists{/gist_id}","starred_url":"https://api.github.com/users/mbostock/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mbostock/subscriptions","organizations_url":"https://api.github.com/users/mbostock/orgs","repos_url":"https://api.github.com/users/mbostock/repos","events_url":"https://api.github.com/users/mbostock/events{/privacy}","received_events_url":"https://api.github.com/users/mbostock/received_events","type":"User","user_view_type":"public","site_admin":false},"forks":[{"url":"https://api.github.com/gists/5435680","user":{"login":"ctJemm","id":3215348,"node_id":"MDQ6VXNlcjMyMTUzNDg=","avatar_url":"https://avatars.githubusercontent.com/u/3215348?v=4","gravatar_id":"","url":"https://api.github.com/users/ctJemm","html_url":"https://github.com/ctJemm","followers_url":"https://api.github.com/users/ctJemm/followers","following_url":"https://api.github.com/users/ctJemm/following{/other_user}","gists_url":"https://api.github.com/users/ctJemm/gists{/gist_id}","starred_url":"https://api.github.com/users/ctJemm/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ctJemm/subscriptions","organizations_url":"https://api.github.com/users/ctJemm/orgs","repos_url":"https://api.github.com/users/ctJemm/repos","events_url":"https://api.github.com/users/ctJemm/events{/privacy}","received_events_url":"https://api.github.com/users/ctJemm/received_events","type":"User","user_view_type":"public","site_admin":false,"name":null,"company":null,"blog":"","location":null,"email":null,"hireable":null,"bio":null,"twitter_username":null,"public_repos":4,"public_gists":3,"followers":0,"following":0,"created_at":"2013-01-08T11:41:25Z","updated_at":"2018-06-22T17:03:03Z"},"id":"5435680","created_at":"2013-04-22T14:51:42Z","updated_at":"2015-12-16T12:38:56Z"},{"url":"https://api.github.com/gists/8503592","user":{"login":"harelc","id":3287673,"node_id":"MDQ6VXNlcjMyODc2NzM=","avatar_url":"https://avatars.githubusercontent.com/u/3287673?v=4","gravatar_id":"","url":"https://api.github.com/users/harelc","html_url":"https://github.com/harelc","followers_url":"https://api.github.com/users/harelc/followers","following_url":"https://api.github.com/users/harelc/following{/other_user}","gists_url":"https://api.github.com/users/harelc/gists{/gist_id}","starred_url":"https://api.github.com/users/harelc/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/harelc/subscriptions","organizations_url":"https://api.github.com/users/harelc/orgs","repos_url":"https://api.github.com/users/harelc/repos","events_url":"https://api.github.com/users/harelc/events{/privacy}","received_events_url":"https://api.github.com/users/harelc/received_events","type":"User","user_view_type":"public","site_admin":false,"name":"Harel Cain","company":"Lightricks","blog":"","location":null,"email":"harel@lightricks.com","hireable":null,"bio":null,"twitter_username":null,"public_repos":33,"public_gists":2,"followers":18,"following":0,"created_at":"2013-01-16T17:03:58Z","updated_at":"2025-09-05T13:46:33Z"},"id":"8503592","created_at":"2014-01-19T11:28:11Z","updated_at":"2016-01-03T18:39:12Z"}],"history":[{"user":{"login":"mbostock","id":230541,"node_id":"MDQ6VXNlcjIzMDU0MQ==","avatar_url":"https://avatars.githubusercontent.com/u/230541?v=4","gravatar_id":"","url":"https://api.github.com/users/mbostock","html_url":"https://github.com/mbostock","followers_url":"https://api.github.com/users/mbostock/followers","following_url":"https://api.github.com/users/mbostock/following{/other_user}","gists_url":"https://api.github.com/users/mbostock/gists{/gist_id}","starred_url":"https://api.github.com/users/mbostock/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mbostock/subscriptions","organizations_url":"https://api.github.com/users/mbostock/orgs","repos_url":"https://api.github.com/users/mbostock/repos","events_url":"https://api.github.com/users/mbostock/events{/privacy}","received_events_url":"https://api.github.com/users/mbostock/received_events","type":"User","user_view_type":"public","site_admin":false},"version":"c6c7aafad77c236f852f43027aa2999b7275bc1c","committed_at":"2016-02-09T02:06:25Z","change_status":{"total":1,"additions":1,"deletions":0},"url":"https://api.github.com/gists/5423680/c6c7aafad77c236f852f43027aa2999b7275bc1c"},{"user":{"login":"mbostock","id":230541,"node_id":"MDQ6VXNlcjIzMDU0MQ==","avatar_url":"https://avatars.githubusercontent.com/u/230541?v=4","gravatar_id":"","url":"https://api.github.com/users/mbostock","html_url":"https://github.com/mbostock","followers_url":"https://api.github.com/users/mbostock/followers","following_url":"https://api.github.com/users/mbostock/following{/other_user}","gists_url":"https://api.github.com/users/mbostock/gists{/gist_id}","starred_url":"https://api.github.com/users/mbostock/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mbostock/subscriptions","organizations_url":"https://api.github.com/users/mbostock/orgs","repos_url":"https://api.github.com/users/mbostock/repos","events_url":"https://api.github.com/users/mbostock/events{/privacy}","received_events_url":"https://api.github.com/users/mbostock/received_events","type":"User","user_view_type":"public","site_admin":false},"version":"fb94a52b4c03c34cf023aae03c071ba35a7a66e3","committed_at":"2015-10-31T01:40:41Z","change_status":{"total":4,"additions":2,"deletions":2},"url":"https://api.github.com/gists/5423680/fb94a52b4c03c34cf023aae03c071ba35a7a66e3"},{"user":{"login":"mbostock","id":230541,"node_id":"MDQ6VXNlcjIzMDU0MQ==","avatar_url":"https://avatars.githubusercontent.com/u/230541?v=4","gravatar_id":"","url":"https://api.github.com/users/mbostock","html_url":"https://github.com/mbostock","followers_url":"https://api.github.com/users/mbostock/followers","following_url":"https://api.github.com/users/mbostock/following{/other_user}","gists_url":"https://api.github.com/users/mbostock/gists{/gist_id}","starred_url":"https://api.github.com/users/mbostock/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mbostock/subscriptions","organizations_url":"https://api.github.com/users/mbostock/orgs","repos_url":"https://api.github.com/users/mbostock/repos","events_url":"https://api.github.com/users/mbostock/events{/privacy}","received_events_url":"https://api.github.com/users/mbostock/received_events","type":"User","user_view_type":"public","site_admin":false},"version":"37e0caf14bc5a89e5a611abb12b858788f882370","committed_at":"2015-06-11T19:23:58Z","change_status":{"total":6,"additions":4,"deletions":2},"url":"https://api.github.com/gists/5423680/37e0caf14bc5a89e5a611abb12b858788f882370"},{"user":{"login":"mbostock","id":230541,"node_id":"MDQ6VXNlcjIzMDU0MQ==","avatar_url":"https://avatars.githubusercontent.com/u/230541?v=4","gravatar_id":"","url":"https://api.github.com/users/mbostock","html_url":"https://github.com/mbostock","followers_url":"https://api.github.com/users/mbostock/followers","following_url":"https://api.github.com/users/mbostock/following{/other_user}","gists_url":"https://api.github.com/users/mbostock/gists{/gist_id}","starred_url":"https://api.github.com/users/mbostock/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mbostock/subscriptions","organizations_url":"https://api.github.com/users/mbostock/orgs","repos_url":"https://api.github.com/users/mbostock/repos","events_url":"https://api.github.com/users/mbostock/events{/privacy}","received_events_url":"https://api.github.com/users/mbostock/received_events","type":"User","user_view_type":"public","site_admin":false},"version":"87312d3fa4abe03c8e87bceac329f40a1f27f85b","committed_at":"2013-04-19T22:33:32Z","change_status":{"total":118,"additions":118,"deletions":0},"url":"https://api.github.com/gists/5423680/87312d3fa4abe03c8e87bceac329f40a1f27f85b"}],"truncated":false}