项目作者: TheGreatRambler

项目描述 :
Two dimensional arrays stored in one dimensional arrays Javascript
高级语言: JavaScript
项目地址: git://github.com/TheGreatRambler/2D-Array-JS.git
创建时间: 2017-12-13T17:24:34Z
项目社区:https://github.com/TheGreatRambler/2D-Array-JS

开源协议:MIT License

下载


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

  1. tdarrayindex: {
  2. encode: function(x, y, method, negative), // method & negative are optional
  3. decode: function(value, method, negative) // method & negative are optional
  4. }

Methods

  1. method = "szudzik";

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

  1. method = "triangle";

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

  1. method = "interleave";

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

  1. method = "primefactor";

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

  1. method = "cantorpair";

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

  1. method = "bitwise";

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

  1. method = "hopullman";

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

  1. 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:

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

Negative

  1. negative = false

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

  1. 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 :star: would be appreciated!