Code Monkey home page Code Monkey logo

babel-plugin-multidimensional-array's Introduction

babel-plugin-multidimensional-array

Fast multidimensional typed arrays with a nice syntax.

Typed arrays are awesome, but sometimes you want a multidimensional array. You can do it with arrays of (arrays of...) typed arrays, but accessing or writing data to nested array objects is slow.

One way to fix this is by using a single flattened typed array, and hand calculating the offset where the data is for every access. But that is tedious. This babel plugin takes care of it for you. Just define your local variables or function arguments with dimensions, and accesses will be transformed to compute the correct offset.

Example

Compiles this:

let x[2][3] = new Uint8Array([1,2,3,4,5,6]);
x[1][2] = 42;

into:

let x = new Uint8Array([1,2,3,4,5,6]);
x[5] = 42;

Function arguments are also supported, as are non-constant dimensions:

function test(x[a][b], y) {
  x[1][y] = 4;
}

compiles to:

function test(x, y) {
  x[y + b * 1] = 4;
}

Subarrays are also supported, if you access only one of the dimensions:

let y[2][3][4] = new Uint8Array(2 * 3 * 4);
console.log(y[1]);

compiles to:

let y = new Uint8Array(2 * 3 * 4);
console.log(y.subarray(12, 24));

Licence

MIT

babel-plugin-multidimensional-array's People

Contributors

devongovett avatar

Stargazers

 avatar

Watchers

 avatar  avatar  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.