Go package for mapping values to and from space-filling curves, such as Hilbert and Peano curves.

Hilbert Build Status Coverage Report card GoDoc Libraries.io

Go package for mapping values to and from space-filling curves, such as Hilbert and Peano curves.

Image of 8 by 8 Hilbert curve

Documentation available here

This is not an official Google product (experimental or otherwise), it is just code that happens to be owned by Google.

How to use

Install:

go get github.com/google/hilbert

Example:

import "github.com/google/hilbert"
	
// Create a Hilbert curve for mapping to and from a 16 by 16 space.
s, err := hilbert.NewHilbert(16)

// Create a Peano curve for mapping to and from a 27 by 27 space.
//s, err := hilbert.NewPeano(27)

// 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)

Demo

The demo directory contains an example on how to draw an images of Hilbert and Peano curves, as well as animations of varying sizes for both.

go run $GOPATH/src/github.com/google/hilbert/demo/demo.go

and the following images are generated.

Simple 8x8 Hibert curve:

8x8 Hilbert curve image

Simple 9x9 Peano curve:

9x9 Hilbert curve image

Animation of Hibert curve with N in the range 1..8:

Hilbert curve animation

Animation of Peano curve with N in the range 1..6:

Peano curve animation

Licence (Apache 2)

Copyright 2015 Google Inc. All Rights Reserved.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Owner
Google
Google ❤️ Open Source
Google
Similar Resources

Package for indexing zip files and storing a compressed index

zipindex zipindex provides a size optimized representation of a zip file to allow decompressing the file without reading the zip file index. It will o

Nov 30, 2022

Go package implementing bitsets

bitset Go language library to map between non-negative integers and boolean values Description Package bitset implements bitsets, a mapping between no

Jan 1, 2023

Go package implementing Bloom filters

Bloom filters A Bloom filter is a representation of a set of n items, where the main requirement is to make membership queries; i.e., whether an item

Dec 30, 2022

Go package implementing an indexable ordered multimap

PACKAGE package skiplist import "github.com/glenn-brown/skiplist" Package skiplist implements fast indexable ordered multimaps. This sk

Jul 2, 2022

A package for Go that can be used for range queries on large number of intervals

go-stree go-stree is a package for Go that can be used to process a large number of intervals. The main purpose of this module is to solve the followi

May 14, 2022

parody of some of the basic python core features (collections package)

collections import "github.com/marcsantiago/collections" Overview Index Subdirectories Overview Index func StringEncoder(encoder *bytes.Buffer, data D

Jan 14, 2022

Package mafsa implements Minimal Acyclic Finite State Automata in Go, essentially a high-speed, memory-efficient, Unicode-friendly set of strings.

MA-FSA for Go Package mafsa implements Minimal Acyclic Finite State Automata (MA-FSA) with Minimal Perfect Hashing (MPH). Basically, it's a set of str

Oct 27, 2022

peanut is a Go package to write tagged data structs to disk in a variety of formats.

peanut peanut is a Go package to write tagged data structs to disk in a variety of formats. Its primary purpose is to provide a single consistent inte

Dec 16, 2022

Go package implementing Bloom filters

Bloom filters A Bloom filter is a concise/compressed representation of a set, where the main requirement is to make membership queries; i.e., whether

Dec 28, 2022
Comments
  • Corrected order of operations. Made runnable.

    Corrected order of operations. Made runnable.

    This is a pretty petty PR, but the order of the operations in the example in the README is non-sensical. I flipped them and also restructured the example so that it was copy-and-paste executable (including defining x and y).

  • Added 64-bit support

    Added 64-bit support

    I added uint64 support in addition to the original int support. I've created new 64-bit types in order to maintain backwards-compatibility as well as cloning the existing tests for both Hilbert and Peano.

    My use-case is to use larger-than-32-bit numbers.

HyperLogLog with lots of sugar (Sparse, LogLog-Beta bias correction and TailCut space reduction)

An improved version of HyperLogLog for the count-distinct problem, approximating the number of distinct elements in a multiset using 33-50% less space

Dec 31, 2022
Surprisingly space efficient trie in Golang(11 bits/key; 100 ns/get).
Surprisingly space efficient trie in Golang(11 bits/key; 100 ns/get).

Slim - surprisingly space efficient data types in Golang Slim is collection of surprisingly space efficient data types, with corresponding serializati

Jan 2, 2023
Decode / encode XML to/from map[string]interface{} (or JSON); extract values with dot-notation paths and wildcards. Replaces x2j and j2x packages.

mxj - to/from maps, XML and JSON Decode/encode XML to/from map[string]interface{} (or JSON) values, and extract/modify values from maps by key or key-

Dec 22, 2022
Convert Go values to their AST

valast - convert Go values to their AST Valast converts Go values at runtime into their go/ast equivalent,

Dec 21, 2022
Enforce default values on structs in Go

Defaults Enforce default values on struct fields. type User struct { Name string `default:"Goku"` Power float64 `default:"9000.01"` } var u

Aug 23, 2022
Print Go values as Go source.

printsrc: Printing Go Values as Source There are many packages that print Go values so people can read them. This package prints Go values so the Go c

Dec 27, 2021
Go library for encoding native Go structures into generic map values.

wstructs origin: github.com/things-go/structs Go library for encoding native Go structures into generic map values. Installation Use go get. go ge

Jan 10, 2022
Package set is a small wrapper around the official reflect package that facilitates loose type conversion and assignment into native Go types.

Package set is a small wrapper around the official reflect package that facilitates loose type conversion and assignment into native Go types. Read th

Dec 27, 2022
Package iter provides generic, lazy iterators, functions for producing them from primitive types, as well as functions and methods for transforming and consuming them.

iter Package iter provides generic, lazy iterators, functions for producing them from primitive types, as well as functions and methods for transformi

Dec 16, 2022
Package ring provides a high performance and thread safe Go implementation of a bloom filter.

ring - high performance bloom filter Package ring provides a high performance and thread safe Go implementation of a bloom filter. Usage Please see th

Nov 20, 2022