fastIterationMap
A typescript implementation of a ES6 Map with Array like performance for iteration and O(1) for lookup but O(2n for deletion).
It uses an ES6 Map for storing keys and corresponding index of elements the array that is use for iteration.
npm install fastiterationmap --save
use src/FastIterationMap.ts for typescript or dist/fastIterationMap.min.js for browser distribution
interface IFastIterationMap<K V> ; deletekey: K: boolean; : V : boolean; : boolean; : boolean; : boolean; keys: Map<K number> length: number; ; ; size: number; values: V;
interface ISimpleObject prop1:string; prop2:number;let myFMap = <string ISimpleObject>; myFMap;// same as myFMap;//myFMap.length == 2 // updating an element by setting with an existing keymyFMap;//myFMap.length == 2 // inserting element before another one myFMap;// inserting element after another one myFMap; // iterate values// for loop is faster than forEachlet size = myFMaplength;forlet i = 0; i < size; ++i console; // output : // 1// 3// 4// 2 // element lookup by keylet o1 = myFMap; //o1 = {'prop1':"abc", 'prop2':1} //does the collection hold an element with a given key ?myFMap; // return true // removing an elementmyFMap;myFMap; // return false; //removing everythingmyFMapclear;// myFMap.length === 0