login  home  contents  what's new  discussion  bug reports     help  links  subscribe  changes  refresh  edit

Edit detail for MortonCode revision 1 of 4

1 2 3 4
Editor: Bill Page
Time: 2009/11/04 00:32:20 GMT-8
Note: new

changed:
-
References to Morton codes:

- http://www.codexon.com/posts/morton-codes

- http://en.wikipedia.org/wiki/Z-order_%28curve%29

- http://www.cs.umd.edu/~hjs/pubs/bulkload.pdf

\begin{axiom}
-- i'th group of n bits of h
bits(h,n,i) == And(mask n,shift(h,-n*i))

-- mix groups of n bits of h with groups of m bits of k
morton(h,n,k,m) ==
 r:SingleInteger:=0
 if n+m > 0 then
   i:=0
   -- stop before fixnum overflow
   while (i+1)*(n+m) <= 29 repeat
     mix:=Or(shift(bits(h,n,i),m),bits(k,m,i))
     r:=Or(r,shift(mix,i*(n+m)))
     i:=i+1
 r

listHash(l) ==
 r:SingleInteger:=0
 i:=0
 while not empty?(l) repeat
   -- equalize hash weight by number of elements
   r:=morton(r,i,hash first l,1)
   l:=rest l
   i:=i+1
 r
\end{axiom}

\begin{axiom}
[hash i for i in 1..5]
[morton(0,0,hash i,1) for i in 1..5]
listHash([1])
matrix [[listHash([i,j]) for j in 1..5] for i in 1..5]
matrix [[listHash([1,i,j]) for j in 1..5] for i in 1..5]
matrix [[listHash([2,i,j]) for j in 1..5] for i in 1..5]
\end{axiom}


References to Morton codes:

axiom
-- i'th group of n bits of h
bits(h,n,i) == And(mask n,shift(h,-n*i))
Type: Void
axiom
-- mix groups of n bits of h with groups of m bits of k
morton(h,n,k,m) ==
 r:SingleInteger:=0
 if n+m > 0 then
   i:=0
   -- stop before fixnum overflow
   while (i+1)*(n+m) <= 29 repeat
     mix:=Or(shift(bits(h,n,i),m),bits(k,m,i))
     r:=Or(r,shift(mix,i*(n+m)))
     i:=i+1
 r
Type: Void
axiom
listHash(l) ==
 r:SingleInteger:=0
 i:=0
 while not empty?(l) repeat
   -- equalize hash weight by number of elements
   r:=morton(r,i,hash first l,1)
   l:=rest l
   i:=i+1
 r
Type: Void

axiom
[hash i for i in 1..5]

\label{eq1}\left[{361475674}, \:{361475691}, \:{361475707}, \:{361475592}, \:{361475608}\right](1)
Type: List(Integer)
axiom
[morton(0,0,hash i,1) for i in 1..5]
axiom
Compiling function bits with type (NonNegativeInteger,
      NonNegativeInteger,NonNegativeInteger) -> SingleInteger
axiom
Compiling function bits with type (Integer,PositiveInteger,
      NonNegativeInteger) -> SingleInteger
axiom
Compiling function morton with type (NonNegativeInteger,
      NonNegativeInteger,Integer,PositiveInteger) -> SingleInteger

\label{eq2}\left[{361475674}, \:{361475691}, \:{361475707}, \:{361475592}, \:{361475608}\right](2)
Type: List(SingleInteger)
axiom
listHash([1])
axiom
Compiling function bits with type (SingleInteger,NonNegativeInteger,
      NonNegativeInteger) -> SingleInteger
axiom
Compiling function morton with type (SingleInteger,
      NonNegativeInteger,Integer,PositiveInteger) -> SingleInteger
axiom
Compiling function listHash with type List(PositiveInteger) -> 
      SingleInteger

\label{eq3}361475674(3)
Type: SingleInteger
axiom
matrix [[listHash([i,j]) for j in 1..5] for i in 1..5]

\label{eq4}\left[ 
\begin{array}{ccccc}
{217854924}&{217855693}&{217855949}&{217850568}&{217850824}
\
{217856462}&{217857231}&{217857487}&{217852106}&{217852362}
\
{217856974}&{217857743}&{217857999}&{217852618}&{217852874}
\
{217846212}&{217846981}&{217847237}&{217841856}&{217842112}
\
{217846724}&{217847493}&{217847749}&{217842368}&{217842624}
(4)
Type: Matrix(SingleInteger)
axiom
matrix [[listHash([1,i,j]) for j in 1..5] for i in 1..5]

\label{eq5}\left[ 
\begin{array}{ccccc}
{1867320}&{1895993}&{1900089}&{1601072}&{1605168}
\
{1924666}&{1953339}&{1957435}&{1658418}&{1662514}
\
{1932858}&{1961531}&{1965627}&{1666610}&{1670706}
\
{1334824}&{1363497}&{1367593}&{1068576}&{1072672}
\
{1343016}&{1371689}&{1375785}&{1076768}&{1080864}
(5)
Type: Matrix(SingleInteger)
axiom
matrix [[listHash([2,i,j]) for j in 1..5] for i in 1..5]

\label{eq6}\left[ 
\begin{array}{ccccc}
{1982012}&{2010685}&{2014781}&{1715764}&{1719860}
\
{2039358}&{2068031}&{2072127}&{1773110}&{1777206}
\
{2047550}&{2076223}&{2080319}&{1781302}&{1785398}
\
{1449516}&{1478189}&{1482285}&{1183268}&{1187364}
\
{1457708}&{1486381}&{1490477}&{1191460}&{1195556}
(6)
Type: Matrix(SingleInteger)