Skip to content

Instantly share code, notes, and snippets.

@solowt
Created May 3, 2017 23:08
Show Gist options
  • Save solowt/3c56a882735f27b02a2971af846be2e7 to your computer and use it in GitHub Desktop.
Save solowt/3c56a882735f27b02a2971af846be2e7 to your computer and use it in GitHub Desktop.

https://en.wikipedia.org/wiki/Z-order_curve

def cmp_zorder(a, b):
    j = 0
    k = 0
    x = 0
    for k in range(dim):
        y = a[k] ^ b[k]
        if less_msb(x, y):
            j = k
            x = y
    return a[j] - b[j]
    
def less_msb(x, y):
    return x < y and x < (x ^ y)

It is also possible to compare floating point numbers using the same technique. The less_msb function is modified to first compare the exponents. Only when they are equal is the standard less_msb function used on the mantissas.[5]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment