1.0.35 • Published 7 years ago

dynamic-array v1.0.35

Weekly downloads
189
License
-
Repository
-
Last release
7 years ago

dynamic-array

View on GitHub View on npmjs.org View on Tonic

Dynamic array extension for Node.js offering better performance for use as a stack or queue

Purpose: This extension wraps a C++ std::deque giving Node.js developers asymptotically optimal queues and stacks.

Requirements: Node.js, node-gyp, gcc and g++

Build instructions: cd to download directory, node-gyp configure, node-gyp build

NPM: Can be installed from NPM via: npm install dynamic-array

Usage:

var arr = require('dynamic-array').DynamicArray();

// use as a queue

console.log("Use as a queue");
console.log("Should list 0 - 9");

for (var i = 0; i < 10; i++)
  arr.enqueue(i);

while(arr.size() > 0)
  console.log(arr.dequeue());

// use as a stack

console.log("Use as a stack");
console.log("Should list 9 - 0");

for (var i = 0; i < 10; i++)
  arr.push(i);

while(arr.size() > 0)
  console.log(arr.pop());

// iteration

console.log("Iteration");
console.log("Should list 0 - 9");

for (var i = 0; i < 10; i++)
  arr.push_back(i);

arr.each(function(item) {
  console.log(item);
});

arr.clear();

// sorting

console.log("Sorting");
console.log("Should list 0 - 9");

for (var i = 0; i < 10; i++)
  arr.push_back(i);

arr.each(function(item) {
  console.log(item);
});

console.log("Should now be reversed")

arr.sort(function(a, b) {
  return (a > b);
});

arr.each(function(item) {
  console.log(item);
});

arr.clear();

// assignment

console.log("Assignment");
console.log("Should list 0 - 8, 8");

for(var i = 0; i < 10; i++)
  arr.push_back(i);

arr.assign(9, 8);

arr.each(function(item) {
  console.log(item);
});

// retrieval

console.log("Retrieval");
console.log("Should list 7, 8");

console.log(arr.at(7));
console.log(arr.at(8));

arr.clear();

// bounds checking

console.log("Should throw exceptions for being out of bounds");
console.log("This bounds checking is to prevent memory leaks and other programming errors");

try {
  arr.at(1);
} catch (e) {
  console.log(e);
}

try {
  arr.assign(1, 0);
} catch (e) {
  console.log(e);
}

Node dynamic array

1.0.35

7 years ago

1.0.34

7 years ago

1.0.33

8 years ago

1.0.32

8 years ago

1.0.31

8 years ago

1.0.30

8 years ago

1.0.28

8 years ago

1.0.27

8 years ago

1.0.26

10 years ago

1.0.25

10 years ago

1.0.24

10 years ago

1.0.23

10 years ago

1.0.22

10 years ago

1.0.21

10 years ago

1.0.20

10 years ago

1.0.19

10 years ago

1.0.18

10 years ago

1.0.17

10 years ago

1.0.16

10 years ago

1.0.15

10 years ago

1.0.14

10 years ago

1.0.13

10 years ago

1.0.12

10 years ago

1.0.11

10 years ago

1.0.10

10 years ago

1.0.9

10 years ago

1.0.8

10 years ago

1.0.7

10 years ago

1.0.6

10 years ago

1.0.5

10 years ago

1.0.4

10 years ago

1.0.3

10 years ago

1.0.2

10 years ago

1.0.1

10 years ago

1.0.0

10 years ago