<s>
The	O
Hilbert	B-Algorithm
curve	I-Algorithm
(	O
also	O
known	O
as	O
the	O
Hilbert	O
space-filling	B-Algorithm
curve	I-Algorithm
)	O
is	O
a	O
continuous	O
fractal	B-Algorithm
space-filling	B-Algorithm
curve	I-Algorithm
first	O
described	O
by	O
the	O
German	O
mathematician	O
David	O
Hilbert	O
in	O
1891	O
,	O
as	O
a	O
variant	O
of	O
the	O
space-filling	O
Peano	B-Algorithm
curves	I-Algorithm
discovered	O
by	O
Giuseppe	O
Peano	O
in	O
1890	O
.	O
</s>
<s>
The	O
Hilbert	B-Algorithm
curve	I-Algorithm
is	O
constructed	O
as	O
a	O
limit	O
of	O
piecewise	O
linear	O
curves	O
.	O
</s>
<s>
Both	O
the	O
true	O
Hilbert	B-Algorithm
curve	I-Algorithm
and	O
its	O
discrete	O
approximations	O
are	O
useful	O
because	O
they	O
give	O
a	O
mapping	O
between	O
1D	O
and	O
2D	O
space	O
that	O
preserves	O
locality	O
fairly	O
well	O
.	O
</s>
<s>
Because	O
of	O
this	O
locality	O
property	O
,	O
the	O
Hilbert	B-Algorithm
curve	I-Algorithm
is	O
widely	O
used	O
in	O
computer	O
science	O
.	O
</s>
<s>
For	O
example	O
,	O
the	O
range	O
of	O
IP	B-Protocol
addresses	I-Protocol
used	O
by	O
computers	O
can	O
be	O
mapped	O
into	O
a	O
picture	O
using	O
the	O
Hilbert	B-Algorithm
curve	I-Algorithm
.	O
</s>
<s>
Code	O
to	O
generate	O
the	O
image	O
would	O
map	O
from	O
2D	O
to	O
1D	O
to	O
find	O
the	O
color	O
of	O
each	O
pixel	O
,	O
and	O
the	O
Hilbert	B-Algorithm
curve	I-Algorithm
is	O
sometimes	O
used	O
because	O
it	O
keeps	O
nearby	O
IP	B-Protocol
addresses	I-Protocol
close	O
to	O
each	O
other	O
in	O
the	O
picture	O
.	O
</s>
<s>
In	O
an	O
algorithm	O
called	O
Riemersma	O
dithering	O
,	O
grayscale	O
photograph	O
can	O
be	O
converted	O
to	O
a	O
dithered	O
black-and-white	O
image	O
using	O
thresholding	O
,	O
with	O
the	O
leftover	O
amount	O
from	O
each	O
pixel	O
added	O
to	O
the	O
next	O
pixel	O
along	O
the	O
Hilbert	B-Algorithm
curve	I-Algorithm
.	O
</s>
<s>
Code	O
to	O
do	O
this	O
would	O
map	O
from	O
1D	O
to	O
2D	O
,	O
and	O
the	O
Hilbert	B-Algorithm
curve	I-Algorithm
is	O
sometimes	O
used	O
because	O
it	O
does	O
not	O
create	O
the	O
distracting	O
patterns	O
that	O
would	O
be	O
visible	O
to	O
the	O
eye	O
if	O
the	O
order	O
were	O
simply	O
left	O
to	O
right	O
across	O
each	O
row	O
of	O
pixels	O
.	O
</s>
<s>
Hilbert	B-Algorithm
curves	I-Algorithm
in	O
higher	O
dimensions	O
are	O
an	O
instance	O
of	O
a	O
generalization	O
of	O
Gray	B-Device
codes	I-Device
,	O
and	O
are	O
sometimes	O
used	O
for	O
similar	O
purposes	O
,	O
for	O
similar	O
reasons	O
.	O
</s>
<s>
For	O
multidimensional	O
databases	O
,	O
Hilbert	O
order	O
has	O
been	O
proposed	O
to	O
be	O
used	O
instead	O
of	O
Z	B-Algorithm
order	I-Algorithm
because	O
it	O
has	O
better	O
locality-preserving	O
behavior	O
.	O
</s>
<s>
For	O
example	O
,	O
Hilbert	B-Algorithm
curves	I-Algorithm
have	O
been	O
used	O
to	O
compress	O
and	O
accelerate	O
R-tree	B-Library
indexes	O
(	O
see	O
Hilbert	B-Data_Structure
R-tree	I-Data_Structure
)	O
.	O
</s>
<s>
The	O
following	O
C	B-Language
code	O
performs	O
the	O
mappings	O
in	O
both	O
directions	O
,	O
using	O
iteration	O
and	O
bit	O
operations	O
rather	O
than	O
recursion	O
.	O
</s>
<s>
These	O
use	O
the	O
C	B-Language
conventions	O
:	O
the	O
&	O
symbol	O
is	O
a	O
bitwise	O
AND	O
,	O
the	O
^	O
symbol	O
is	O
a	O
bitwise	O
XOR	O
,	O
+	O
=	O
is	O
the	O
addition/assignment	O
operator	O
(	O
x	O
+	O
=	O
y	O
is	O
equivalent	O
to	O
x	O
=	O
x	O
+	O
y	O
)	O
,	O
and	O
/	O
=	O
is	O
the	O
division/assignment	O
operator	O
.	O
</s>
<s>
The	O
handling	O
of	O
booleans	O
in	O
C	B-Language
means	O
that	O
in	O
xy2d	O
,	O
the	O
variable	O
rx	O
is	O
set	O
to	O
0	O
or	O
1	O
to	O
match	O
bit	O
s	O
of	O
x	O
,	O
and	O
similarly	O
for	O
ry	O
.	O
</s>
<s>
It	O
is	O
possible	O
to	O
implement	O
Hilbert	B-Algorithm
curves	I-Algorithm
efficiently	O
even	O
when	O
the	O
data	O
space	O
does	O
not	O
form	O
a	O
square	O
.	O
</s>
<s>
Moreover	O
,	O
there	O
are	O
several	O
possible	O
generalizations	O
of	O
Hilbert	B-Algorithm
curves	I-Algorithm
to	O
higher	O
dimensions	O
.	O
</s>
<s>
The	O
Hilbert	B-Algorithm
Curve	I-Algorithm
can	O
be	O
expressed	O
by	O
a	O
rewrite	O
system	O
(	O
L-system	B-Language
)	O
.	O
</s>
<s>
Here	O
,	O
"	O
F	O
"	O
means	O
"	O
draw	O
forward	O
"	O
,	O
"	O
+	O
"	O
means	O
"	O
turn	O
left	O
90°	O
"	O
,	O
"	O
-	O
"	O
means	O
"	O
turn	O
right	O
90°	O
"	O
(	O
see	O
turtle	B-Application
graphics	I-Application
)	O
,	O
and	O
"	O
A	O
"	O
and	O
"	O
B	O
"	O
are	O
ignored	O
during	O
drawing	O
.	O
</s>
<s>
Graphics	O
Gems	O
II	O
discusses	O
Hilbert	B-Algorithm
curve	I-Algorithm
coherency	O
,	O
and	O
provides	O
implementation	O
.	O
</s>
<s>
The	O
Hilbert	B-Algorithm
Curve	I-Algorithm
is	O
commonly	O
used	O
among	O
rendering	O
images	O
or	O
videos	O
.	O
</s>
<s>
Common	O
programs	O
such	O
as	O
Blender	B-Application
and	O
Cinema	B-Device
4D	I-Device
use	O
the	O
Hilbert	B-Algorithm
Curve	I-Algorithm
to	O
trace	O
the	O
objects	O
,	O
and	O
render	O
the	O
scene	O
.	O
</s>
