Giter Site home page Giter Site logo

panagiotisrep / hilbert-curve Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 112 KB

C++ code for Hilbert Curve. Map data to the points of a hypercube lattice of n dimensions and compute their Hilber values.

Home Page: https://panagiotisrep.github.io/Hilbert-Curve

License: Other

CMake 3.75% C++ 96.25%

hilbert-curve's Introduction

Hilbert Curve

A C++ package for the Hilbert Curve in n dimensions. To use the code, just include the header file in folder 'include'.

To initialize the class:

HilbertCurve::HilbertCurve hilbertCurve(n, p);

where

  • n is the number of dimensions
  • p is the number of iterations

To get the Hilbert value of point (5, 5, 5)

std::vector<unsigned long> point{5, 5, 5};
unsigned long hilbertValue = hilbertCurve.hilbertNumberFromPoint(point);

To get the point with Hilbert value 100

std::vector<unsigned long> point = hilbertCurve.pointFromHilbertNumber(100)

You can also create a custom class and functor to sort with respect to Hilbert values (see the example)

// create some entities
Entity e1(1, 30, 2, 1000);
Entity e2(2, 32, 6, 1500.5);
Entity e3(3, 40, 15, 780.8);
Entity e4(4, 31, 4, 860.6);
Entity e5(5, 45, 20, 2043.4);

std::vector<Entity *> entities{&e1, &e2, &e3, &e4, &e5};

// sort the entities w.r.t. Hilber value
std::vector<unsigned long> hilbertValues;
hilbertCurve.sortData<Entity, struct myFunctor>(entities, myFunctor, hilbertValues);

You can find more documentation in the project's page.

Example

There is an example in the folder src. We create a custom class Entity, a functor which takes an instance of that class and maps it to a point in the hypercube lattice in 3D, and then we sort a vector of Entity objects, with respect to their Hilbert value.

To run the example:

cmake .
make
./hilbertCurve

Issues

  • Let n be the number of dimensions and p the number of iterations. Due to the way we compute the binary representation of numbers, it must hold that np < size_of(long) * 8. In most computers that would be np < 64.

hilbert-curve's People

Contributors

panagiotisrep avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.