code: def _xy2hash(x, y, dim):
      
      d = 0
      lvl = dim >> 1
      while (lvl > 0):
          rx = int((x & lvl) > 0)
          ry = int((y & lvl) > 0)
          d += lvl * lvl * ((3 * rx) ^ ry)
          x, y = _rotate(lvl, x, y, rx, ry)
          lvl >>= 1
      return d
docs: Convert (x, y) to hashcode.
  
      Based on the implementation here:
          https://en.wikipedia.org/w/index.php?title=Hilbert_curve&oldid=797332503
  
      Pure python implementation.
  
      Parameters:
          x: int        x value of point [0, dim) in dim x dim coord system
          y: int        y value of point [0, dim) in dim x dim coord system
          dim: int      Number of coding points each x, y value can take.
                        Corresponds to 2^level of the hilbert curve.
  
      Returns:
          int: hashcode  ∈ [0, dim**2)