https://github.com/exaexa/hilbert-curve-o1
Constant-time integer transform to 2D Hilbert curve
https://github.com/exaexa/hilbert-curve-o1
Last synced: 3 days ago
JSON representation
Constant-time integer transform to 2D Hilbert curve
- Host: GitHub
- URL: https://github.com/exaexa/hilbert-curve-o1
- Owner: exaexa
- Created: 2021-08-30T07:54:30.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2021-08-30T08:17:11.000Z (almost 5 years ago)
- Last Synced: 2025-02-24T03:45:40.230Z (over 1 year ago)
- Language: C
- Size: 1000 Bytes
- Stars: 2
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Const-time Hilbert curve with integer operations
The code in `intbert.c` computes the position of *n*-th "node" of the 2D Hilbert
curve in *O(1)* time, using only bitwise integer operation.
The method is loosely based on transforming the U-curve (aka Gray code) with
consecutive accumulated rotations and flips, then deinterleaving (as in Morton
Z-curve).
To run a demo (order 14 curve):
```sh
make intbert
./intbert 14 > hilbert14.tsv
```
To plot the results (here using `R`):
```r
d <- read.table('hilbert14.tsv')[,3:4]
# plot interactively
plot(d, pch=20, cex=.5, col=rainbow(2^14))
lines(d)
# plot to SVG
svg('hilbert14.svg', 20, 20)
plot(d, type='l', lwd=2, xlab='', ylab='')
points(d, pch=20, col=rainbow(2^14))
dev.off()
```
**TODOs:**
- reverse transform (2D coords to 1D Hilbert)
- optimized versions (x86 asm, shaders, lower-than-64bit versions, ...)
## License
Public domain.
(But I'll be happy if you link back to this repo.)