Giter Club home page Giter Club logo

2d-array-js's Introduction

2D-Array-JS

Collection of functions that, given a x and y value, returns an index in a one dimensional array. These functions can also be used as pairing functions. Supports AMD and use in the browser.

API

tdarrayindex: {
  encode: function(x, y, method, negative), // method & negative are optional
  decode: function(value, method, negative) // method & negative are optional
}

Methods

method = "szudzik";

A index derived through the szudzik pairing function by Matthew Szudzik at Wolfram Research. Read about it here. This is the default.

method = "triangle";

A index derived through triangular numbers. Read about it here. Does not have decode function.

method = "interleave";

A index derived by rearranging the digits of each number. Read about it here.

method = "primefactor";

A index derived through prime factors. Read about it here. Note: this method creates very large arrays. Does not have decode function.

method = "cantorpair";

A index derived through the cantor pairing function. Read about it here and read source here.

method = "bitwise";

A index derived through bitwise functions. Read the source here.

method = "hopullman";

A index derived through a pairing function devised by Hopcroft and Ullman. Read about it here. Does not have decode function.

method = "rosenstrong";

A index derived through the Rosenburg-Strong pairing function. Read about it here. Does not have decode function.

To use tdarrayindex.decode, just input value from tdarrayindex.encode to get an array containing the x and y value.

Example:

  var test = tdarrayindex.encode(2, 4, "szudzik"); // 18
  var xandy = tdarrayindex.decode(test, "szudzik"); // [2, 4]

Negative

negative = false

this specifies that negative values for either x or y are not to be supported. This is the default.

negative = true

This specifies that negative values for either x or y are supported. Be warned that this method makes twice as large arrays if you only use positive values!

Check out this page for average function times and efficiency.

Note: This library only returns the index or gets x and y values from an index. It does not return a array or mutate an existing array.

If you like this javascript library, a โญ would be appreciated!

2d-array-js's People

Contributors

thegreatrambler avatar

Stargazers

 avatar

Watchers

 avatar

Forkers

cube3power

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.