GithubHelp home page GithubHelp logo

d-link-list's Introduction

D-Link-List

  • A typescript double linked list implementation with added length, accessors, removers, and inserter utils. As well as a map function that returns an index on each iteration. Avoids copies -- which is also something to be aware of when mutating objects
Install

d-link-list npm registry

yarn add d-link-list
Sample
import { DLinkList } from "d-link-list";

const doubleList = new DLinkList<string>();
doubleList.push("apple");
doubleList.push("banana");
doubleList.push("cherry");

console.log("push");
doubleList.map((str, index) => {
  console.log(`${index}: ${str}`);
});

console.log("remove");
doubleList.remove("banana");

doubleList.map((str, index) => {
  console.log(`${index}: ${str}`);
});

console.log("removeIndex");
doubleList.removeIndex(0);

doubleList.map((str, index) => {
  console.log(`${index}: ${str}`);
});

console.log("unshift");
doubleList.unshift("apple");
doubleList.unshift("banana");

doubleList.map((str, index) => {
  console.log(`${index}: ${str}`);
});

console.log("shift");
doubleList.shift();

doubleList.map((str, index) => {
  console.log(`${index}: ${str}`);
});

console.log("pop");
doubleList.pop();

doubleList.map((str, index) => {
  console.log(`${index}: ${str}`);
});

console.log("getAtIndex");
let nodeAtIndex = doubleList.getAtIndex(0);
console.log(nodeAtIndex);

console.log("addNext");
doubleList.addNext("apple_next", nodeAtIndex!);
doubleList.map((str, index) => {
  console.log(`${index}: ${str}`);
});

console.log("addNextToIndex");
doubleList.addNextToIndex("apple_next_to_index", doubleList.length - 1);
doubleList.map((str, index) => {
  console.log(`${index}: ${str}`);
});

console.log("tailValue");
console.log(doubleList.tailValue());

console.log("getIndexOfNode");
let index = doubleList.getIndexOfNode(nodeAtIndex!);
console.log(`index of ${nodeAtIndex?.value}: ${index}`);

console.log("getByValue");
let nodeByValue = doubleList.getByValue("apple_next");
console.log(nodeByValue?.value);

console.log("removeNode");
doubleList.removeNode(nodeAtIndex!);
doubleList.map((str, index) => {
  console.log(`${index}: ${str}`);
});

console.log("addPrev");
nodeAtIndex = doubleList.getAtIndex(0);
doubleList.addPrev("apple_prev", nodeAtIndex!);
doubleList.map((str, index) => {
  console.log(`${index}: ${str}`);
});

console.log("addPrevToIndex");
doubleList.addPrevToIndex("apple_prev_to_index", 0);
doubleList.map((str, index) => {
  console.log(`${index}: ${str}`);
});

console.log("headValue");
console.log(doubleList.headValue());

console.log("toArray");
console.log(doubleList.toArray());

console.log("removeAtIndex");
doubleList.removeAtIndex(0);

doubleList.map((str, index) => {
  console.log(`${index}: ${str}`);
});

console.log("headValue");
console.log(doubleList.headValue());

console.log("removeAtIndex");
doubleList.removeAtIndex(2);

console.log("tailValue");
console.log(doubleList.tailValue());

console.log("for of iterator");
for (let item of doubleList) {
  console.log(item);
}

console.log("values iterator (less copies)");
for (let item of doubleList.values()) {
  console.log(item);
}

d-link-list's People

Contributors

lucasmoskun avatar

Watchers

 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.