Gis Zorder
Gis Zorder
Laura Toma
Bowdoin College
Space filling curves
https://mathsbyagirl.wordpress.com/tag/curve/
p Z_index(p)
(0,0) 0
p Z_index(p)
(0,0) 0
(0,1) 1
1 3
(1,0) 2
(1,1) 3
x
0 2
k=1 bit
p Z_index(p)
(0,0) 0
(0,1) 1
1 3
(1,0) 2
(1,1) 3
x
0 2
p Z_index(p)
(00,00) 0000=0
k=2 bits (00,01) 0001=1
(00,10) 0100=4
Find the Z-order!
(00,11) 0101=5
(01,00)
(01,01)
y (01,10)
(01,11)
(10,00)
(10,01)
(10,10)
(10,11)
(11,00)
(11,01)
x
(11,10)
(11,11)
k=2 bits
x
k=3 bits
x
Computing the Z-index
• Consider an x-coordinate x1x2x3 in the square [0,…8)
• x1=0 means the point will reside in the first half
• x1=1 means the point will reside in the second half
x
x=0** x=1**
Computing the Z-index
• Consider an y-coordinate y1y2y3 in the square [0,…8)
• y1=0 means the point will reside in the first half
• y1=1 means the point will reside in the second half
y=1**
y=0**
x
Computing the Z-index
• Consider an y-coordinate y1y2y3 in the square [0,…8)
• y1=0 means the point will reside in the first half
• y1=1 means the point will reside in the second half
x=0** x=1**
y=1** y=1**
x=0** x=1**
y=0** y=0**
x
Computing the Z-index
• Consider an y-coordinate y1y2y3 in the square [0,…8)
• y1=0 means the point will reside in the first half
• y1=1 means the point will reside in the second half
y y
x=0** x=1**
y=0** y=0**
Z=00** Z=10**
x x
Computing the Z-index
• Consider an y-coordinate y1y2y3 in the square [0,…8)
• y1=0 means the point will reside in the first half
• y1=1 means the point will reside in the second half
y y
Z=01** Z=11**
Z=00** Z=10**
x x
Computing the Z-index
• Consider an y-coordinate y1y2y3 in the square [0,…8)
• y1=0 means the point will reside in the first half
• y1=1 means the point will reside in the second half
y y
Z=01** Z=11**
Z=00** Z=10**
x x
Computing the Z-index
• Consider an y-coordinate y1y2y3 in the square [0,…8)
• y1=0 means the point will reside in the first half
• y1=1 means the point will reside in the second half
y y
Z=01** Z=11**
Z=00** Z=10**
x x
Computing the Z-index
• Consider an y-coordinate y1y2y3 in the square [0,…8)
• y1=0 means the point will reside in the first half
• y1=1 means the point will reside in the second half
y y
Z=01** Z=11**
Z=00** Z=10**
x x
Computing the Z-index
• Consider an y-coordinate y1y2y3 in the square [0,…8)
• y1=0 means the point will reside in the first half
• y1=1 means the point will reside in the second half
y y
Z=01** Z=11**
Z=00** Z=10**
x x
Z-order space filling curves
y
y
• At the limit, it will reach all points in the square ==> space filling curve
Z-order and quadtrees
visit quadrants recursively in this order: NW, NE, SW, SE
• At the limit, it will reach all points in the square ==> space filling curve
Z-order and quadtrees
visit quadrants recursively in this order: NW, NE, SW, SE
• At the limit, it will reach all points in the square ==> space filling curve
Z-order and quadtrees
visit quadrants recursively in this order: NW, NE, SW, SE
• At the limit, it will reach all points in the square ==> space filling curve
Z-order and quadtrees
visit quadrants recursively in this order: NW, NE, SW, SE
• and so on…..
Z-order and quadtrees
visit quadrants recursively in this order: NW, NE, SW, SE
• and so on…..
Z-order and quadtrees
visit quadrants recursively in this order: NW, NE, SW, SE
Zindex(a) Zindex(b)
Z_index : R2 —> R
For simplicity assume points with integer coordinates on k bits
• What is the largest integer representable on k bits?
Z-index(p)
Space-filling curves
• Z-order curves are a special type of space-filling curves
• First SFC were described by Peano and Hilbert
Peano curve
Hilbert curve
Spatial locality
Spatial applications usually have spatial locality in their access to data, i.e. they
are likely to access together points that are close to each other in space
We would like points “close” in 2D to be stored “close” to each other in the data structure
Spatial locality
Spatial applications usually have spatial locality in their access to data, i.e. they
are likely to access together points that are close to each other in space
We would like points “close” in 2D to be stored “close” to each other in the data structure
Spatial locality
Spatial applications usually have spatial locality in their access to data, i.e. they
are likely to access together points that are close to each other in space
We would like points “close” in 2D to be stored “close” to each other in the data structure
Spatial locality
Spatial applications usually have spatial locality in their access to data, i.e. they
are likely to access together points that are close to each other in space
We would like points “close” in 2D to be stored “close” to each other in the data structure
Spatial locality
Spatial applications usually have spatial locality in their access to data, i.e. they
are likely to access together points that are close to each other in space
We would like points “close” in 2D to be stored “close” to each other in the data structure
Grid default layout: row-major order
…
Grid default layout: row-major order
… …
Spatial locality
… …
Spatial locality
… …
Spatial locality
… …
Spatial locality
… …
Spatial locality
… …
Spatial locality
… …
Spatial locality
… …
Spatial locality
… …
Spatial locality
• Arranging data in order of a space-filling curve improves spatial locality
• points that are close together in space, will be stored close to each
other
• data will be in the same blocks as previous data
• data will be found in cache
• improvements at all levels of the memory hierarchy
• Hilbert curve has better locality than z-order, but slower to compute
• Z-order used with Strassen’s algorithm —> speedups (2002)
SFC in art