Copyright 2018 Jared Boice (MIT License / Open Source)
List-Runner - Summarized Documentation
"Within Cells Interlinked"
get the full documentation at gitHub.
Donations - Bitcoin: 19XgiRojJnv9VDhyW9HmF6oKQeVc7k9McU
(use this address until 2022)
this codebase has survived 65 unit tests
Description
List-Runner is a lightweight linked-list implementation that offers both Singly (next) and Doubly data structures (next and previous).
Nodes are referred to as cells and the list is referred to as a stem.
Singly cell instances have getNext() and setNext() methods. Doubly cell instances additionally have getPrev() and setPrev() methods. All other operations are controlled by the Stem instance. There are two types of stems, one for singly data structures and one for doubly data structures.
Install, Import & Instantiate
Install
npm install --save list-runner
Import
importing the commonly needed classes
;
importing the constants
;
importing the sidekick functions
;
importing less commonly needed classes
;
Instantiate
solo instantiation
const cell = ; const stem = cell;
connective instantiation
const cell1 = ; const cell2 = ; const cell3 = ; const stemCells = cell1 cell2 cell3; const structureType = DOUBLY; // imported constant const stem = ;
code examples: stem and cell classes
// assume the following are not stringsconst baseline = 'some arbitrary cell on the stem'; // substitute a cell on the stemconst cell = 'some new cell'; // substitute a newly instantiated cellconst cells = 'an array of cells'; // substitute an array of unlinked cells /* CELL OPERATIONS */const nextCell = cell;const prevCell = cell; // only DOUBLY data-structure /* STEM OPERATIONS */const head = stem;const tail = stem; // only DOUBLY data-structure; // returns true || false based on success; // returns extracted cell || false based on success; // returns true || false based on success; // returns extracted cell || false based on success; // only DOUBLY data-structure / returns true || false based on success; // only DOUBLY data-structure / returns extracted cell || false based on success; // returns true || false based on successdeletebaseline; // returns true || false based on success
code examples: sidekick functions
// assume the following are not stringsconst comparator = 'a callback function that returns true when the right cell is found'; // receives each cellconst callBackParams = 'any kind of parameters that you want to pass to the callBack function';const callBack = 'a custom callback function that will receive each cell from a loop and also callBackParams'; // receives each cell and callBackParams /* SIDEKICK FUNCTIONS */;const foundCell1 = ;const foundCell2 = ;// lastCellInLoop1 will be cell.type === SENTINEL if it loops to the edge of the stem (by not triggering a custom short-circuit condition)const lastCellInLoop1 = ;const lastCellInLoop2 = ;const totalCount1 = ;const totalCount2 = ; /* findForward / findBackward comparator callback examples */ // standardconst findComparator1 = { return cellid === 'KD6-3.7';}; // curriedconst findComparator2 = { return { return cellid === id; };}; const myComparator = ;const foundCell3 = ; /* runForward / runBackward callback examples */ // standardconst runCallBack1 = { // do stuff const continueLoop = cellid !== id; return continueLoop;}; // curriedconst runCallBack2 = { return { // do stuff const continueLoop = cellid !== id; return continueLoop; };}; const myCallBack = ;// lastCellInLoop3 will be cell.type === SENTINEL if it loops to the edge of the stem (by not triggering a custom short-circuit condition)const lastCellInLoop3 = ;