References to Morton codes (also known as z-order and Lebesgue curves):
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]
Type: List(Integer) axiom [morton(0,0,hash i,1) for i in 1..5] axiom Compiling function bits with type (NonNegativeInteger,
NonNegativeInteger,NonNegativeInteger) -> SingleIntegeraxiom Compiling function bits with type (Integer,PositiveInteger,
NonNegativeInteger) -> SingleIntegeraxiom Compiling function morton with type (NonNegativeInteger,
NonNegativeInteger,Integer,PositiveInteger) -> SingleInteger
Type: List(SingleInteger) axiom listHash([1]) axiom Compiling function bits with type (SingleInteger,NonNegativeInteger,
NonNegativeInteger) -> SingleIntegeraxiom Compiling function morton with type (SingleInteger,
NonNegativeInteger,Integer,PositiveInteger) -> SingleIntegeraxiom Compiling function listHash with type List(PositiveInteger) ->
SingleInteger
Type: SingleInteger axiom matrix [[listHash([i,j]) for j in 1..5] for i in 1..5]
Type: Matrix(SingleInteger) axiom matrix [[listHash([1,i,j]) for j in 1..5] for i in 1..5]
Type: Matrix(SingleInteger) axiom matrix [[listHash([2,i,j]) for j in 1..5] for i in 1..5]
Type: Matrix(SingleInteger) Interleave bits by Binary Magic NumbersThis is a fast bit manipulation for combining two hash codes that does not use MOD of a large prime number. Based on the an algorithm by By Sean Eron Anderson. Ref: http://graphics.stanford.edu/~seander/bithacks.html#InterleaveBMN spad )abbrev package MORTON Morton
Morton() : with
morton2: (SingleInteger,SingleInteger) -> SingleInteger
== add
spad Compiling FriCAS source code from file
/var/zope2/var/LatexWiki/3849729568657923935-25px003.spad using
old system compiler.
MORTON abbreviates package Morton
------------------------------------------------------------------------
initializing NRLIB MORTON for Morton
compiling into NRLIB MORTON
compiling local spread : SingleInteger -> SingleInteger
Time: 0.03 SEC.axiom matrix [[morton2(hash i,hash j) for j in 1..5] for i in 1..5]
Type: Matrix(SingleInteger) |



