Giter Club home page Giter Club logo

hashgrid's Introduction

Hashgrid

Rust

Current version: 0.2.x

The hashgrid library is an implementation of the hash grid data structure written in pure rust. It provides a N-dimensional, agnostic grid abstraction to store and manipulate data in contiguous uniform cells. Some features of this crate include:

  • N-Dimensional: You can represent any space by simply defining the dimensionality. It becomes specially useful if the implementation requires grids in 2 and 3 dimensional spaces at the same time or if you are doing some high dimensional calculations (k-neighbors for example)

  • Agnostic: Store any type of data that implements the Clone and Cardinality traits.

  • Memory safe: Run cocurrent code without fear using the IsoHashGrid struct and the MultiThreaded trait.

  • Periodic images: Specially useful for physics, the current implementation allows to create periodic images of the grid and move/locate element through the periodic image in a very simple and convenient manner.

Use Hashgrid

Initializing a hashgrid is very simple. You can initialize an empty grid based on the dimensions of it or by passing an initialized vector of HashCell.

// Define a 3-dimensional grid that stores `Point3D` elements and is divided in 3 by 3 by 3 cell 
// of edge 1.0. Periodicity is set for all faces of the grid

use hashgrid::{HashGrid, PeriodicImage, ReadGrid, WriteGrid};
use hashgrid::common::Point3D;

let mut grid:HashGrid<3, Point3D> = HashGrid::generate_uniform_grid(
        [3, 3, 3],  
        [PeriodicImage::BOTH; 3],
        Point3D::new([1.0, 1.0, 1.0])
    );

// Populate the grid with Point3D elements at random location. 
    let mut l = 0;
    for i in 0..3 {
        for j in 0..3 {
            for k in 0..3 {
                grid.set_dwellers([i, j, k], vec![Point3D::from_scalar(l as f32), 
                Point3D::from_scalar((l+1) as f32), 
                Point3D::from_scalar((l+2) as f32)
            ]);
                l += 3;
            }
        }
    }

From here, you can access the elements of the grid using the get_ and get_mut_ methods. More complex examples of implementing this API for fast spatial calculations can be found in the examples directory.

License

The current repository is protected by the MIT License. See the LICENSE.md file for further information.

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.