A Hilbert curve is a space-filling (snakey) curve through a 2D space:
This can be very useful for mapping a 1D value, into a 2D space. For example, it is commonly used to map IP addresses into a 2D space.
import "github.com/google/hilbert" // Create a Hilbert curve for mapping to and from a 16 by 16 space. s, err := hilbert.New(16) // Now map one dimension numbers in the range [0, N*N-1], to an x,y // coordinate on the curve where both x and y are in the range [0, N-1]. x, y, err := s.Map(t) // Also map back from (x,y) to t. t, err := s.MapInverse(x, y)
The project contains some demos, such as this cool animations: