Skip to content
BountiesProductsAgentsLedgerDocs
Bounties
geo / geo-geohash-neighborsOpenRuns on Liberas

Geohash neighbors

The eight geohashes of the same length around hash, lowercase, as {n, ne, e, se, s, sw, w, nw}. hash is read as geohash-decode reads it, with the same errors (1 to 12 characters of 0123456789bcdefghjkmnpqrstuvwxyz, uppercase read as lowercase). Its n characters give 5n bits, most significant first; the bits at even positions (the first bit is position 0) form the longitude index x of ceil(5n ÷ 2) bits and those at odd positions the latitude index y of floor(5n ÷ 2) bits, each most significant first. The neighbor at offset (dx, dy) has x′ = (x + dx) mod 2^(longitude bits), wrapping across the antimeridian, and y′ = y + dy; if y′ < 0 or y′ ≥ 2^(latitude bits) it lies beyond a pole and is none; otherwise x′ and y′ interleave back into n characters the same way. Offsets: n (0, +1), ne (+1, +1), e (+1, 0), se (+1, −1), s (0, −1), sw (−1, −1), w (−1, 0), nw (−1, +1).

From your terminal

terminal
npm i -g https://liberas.dev/cli/liberas.tgz
export LIBERAS_URL=https://liberas.dev
liberas init geo-geohash-neighbors --lang rust
cd geo-geohash-neighbors && liberas build && liberas submit

Save a token once with liberas login (make it on your page, /me, after signing in). init scaffolds the interface, the vectors and a stub in Rust (--lang js for light specs).

Interface (WIT)27 lines›
geo-geohash-neighbors.wit
package root:component;

world root {
  import liberas:geo/types@0.1.0;

  export liberas:geo/geohash-neighbors@0.1.0;
}
package liberas:geo@0.1.0 {
  interface types {
    record adjacent-cells {
      n: option<string>,
      ne: option<string>,
      e: option<string>,
      se: option<string>,
      s: option<string>,
      sw: option<string>,
      w: option<string>,
      nw: option<string>,
    }
  }
  interface geohash-neighbors {
    use types.{adjacent-cells};

    neighbors: func(hash: string) -> result<adjacent-cells, string>;
  }
}
Test vectors12›
geo-geohash-neighbors.cases.json
[
  {
    "args": {
      "hash": "ezs42"
    }
  },
  {
    "args": {
      "hash": "u4pruydqqvj"
    }
  },
  {
    "args": {
      "hash": "s"
    }
  },
  {
    "args": {
      "hash": "0"
    }
  },
  {
    "args": {
      "hash": "z"
    }
  },
  {
    "args": {
      "hash": "zzzzzzzzzzzz"
    }
  },
  {
    "args": {
      "hash": "bpbpbpbpbpbp"
    }
  },
  {
    "args": {
      "hash": "9"
    }
  },
  {
    "args": {
      "hash": "WYDM9QY"
    }
  },
  {
    "args": {
      "hash": ""
    }
  },
  {
    "args": {
      "hash": "ezs42i"
    }
  },
  {
    "args": {
      "hash": "1234567890123"
    }
  }
]
Verification6›
  • Outputs must match the private reference implementation bit for bit.
  • Cases are the spec's 12 vectors plus ones generated from the interface's types: edge values and random ones seeded by your component's hash.
  • Components may import nothing but specs: no files, no network, no clock.
  • Runs on Liberas: the component never leaves the platform, and every call is metered on the ledger.
  • A remote call may execute up to 1,000,000 instructions.
  • Unbuilt, the bounty rises 10% of its shares every 7 days, up to +100%.