3.0.0 • Published 7 years ago

extended-types v3.0.0

Weekly downloads
2
License
MIT
Repository
github
Last release
7 years ago

Extended-types

An implementation of missing data-types in JS.

Introduction

This project implements data-types from other languages in JavaScript. Please note that the main usage of these is to better describe what the code does (like using a Stack, instead of an Array that acts like a Stack). None of these types will provide the performance gain that their native implementations would.

Types

Implemented:

  • ArrayFixed
  • Matrix
  • Queue
  • Stack
  • LinkedList
  • LinkedListDouble

Planned:

  • Byte
  • Binary Tree
  • Restricted Int/Float

Usage:

All constructors can be found in the _types Object:

const fixedArray = new _types.ArrayFixed(12);
const matrix = new _types.Matrix(4, 5);

const stack = new _types.Stack();
const queue = new _types.Queue();

const linkedList = new _types.LinkedList();
const linkedList = new _types.LinkedListDouble();

Types

Array-like types

FixedArray

FixedArray is a variant of a normal Array that has a constant length which is set upon initialization.

const fixedArray = new _types.ArrayFixed(12);

fixedArray[3] = 4; //works
fixedArray[99] = 14 //throws range error
Matrix

Matrix is a simple, 2 dimensional FixedArray, with similiar restrictions.

const matrix = new _types.Matrix(4, 5);

matrix.set(0, 2, "foo"); //works
matrix.set(0, 6, "foo"); //throws exception

matrix.get(3, 0); //works
matrix.get(6, 7); //throws exception
Stack
const stack = new _types.Stack();

stack.push("foo");
stack.push("bar");
stack.pop(); //=>"bar"
Queue
const queue = new _types.Queue();

stack.enqueue("foo");
stack.enqueue("bar");
stack.dequeue(); //=>"foo"

Lists

LinkedList/LinkedListDouble

LinkedList is implemented by an Object-Node chain where each Node contains a data value and a reference to the next Node.

const ll = new _types.LinkedList();

ll.push("foo");
ll.push("bar");
ll.nodeAt(1); //=>Node
ll.valueAt(1); //=>"bar"

ll.find("foo"); //=>Node
ll.findIndex("foo"); //=> 1

ll.first(); //=>First Node
ll.last(); //=>Last Node

ll.remove(2);
ll.insert(2, "foo");
3.0.0

7 years ago

2.4.0

7 years ago

2.3.1

7 years ago

2.3.0

7 years ago

2.2.0

7 years ago

2.1.0

7 years ago

2.0.0

7 years ago

1.1.1

7 years ago

1.0.0

7 years ago