@psenger/bidirectional-map
v1.0.6
Published
Bi Directional Map ( BIDI Map ) for NodeJS
Downloads
18
Maintainers
Readme
Bidirectional Map
A bidirectional map, is an associative data structure in which the pairs form a one-to-one relationship. The binary relation is functional in both direction: each value is mapped to a unique key.
Table of contents
API
BiDirectionalMap
Extends Map
- See: wikipedia for further information
Bi Directional Map is a Map, in which the keys and values are registered pointing to each other ( a binary relationship ). EG A->B and B->A. This is a Advanced Data Type and is some times called an Associative Data Structure.
Type: BiDirectionalMap
Parameters
props
Iterable? An Iterable object whose elements are key-value pairs (arrays with two elements, e.g. [[ 1, ['one','two'] ],[ 2, ['three'] ]]). Each key-value pair is added to the new Map; null values are treated as undefined.
Meta
- version: 1.0.5
set
Sets the value for the key in the Map object. Overriding the parent set
and returns the Map
object. Only works with String
or `Numbers.
Parameters
key
(string | number) The key of the element to add to theBiDirectionalMap
object.value
(string | number) The value of the element to add to theBiDirectionalMap
object.
Returns BiDirectionalMap
species
Overwrite BiDirectionalMap species to the parent Map constructor
Returns MapConstructor
Example Usage
const bidiMap = new BiDirectionalMap();
bidiMap.set(1, 2).set(3, 4);
console.log (`Key(1) = Value(${bidiMap.get(1)})` );
console.log (`Key(2) = Value(${bidiMap.get(2)})` );
console.log (`Key(3) = Value(${bidiMap.get(3)})` );
console.log (`Key(4) = Value(${bidiMap.get(4)})` );
// Key(1) = Value(2)
// Key(2) = Value(1)
// Key(3) = Value(4)
// Key(4) = Value(3)
for( let [Key,Value] of bidiMap.entries()){
console.log(`Key(${Key}) = Value(${Value})`);
}
// Key(1) = Value(2)
// Key(2) = Value(1)
// Key(3) = Value(4)
// Key(4) = Value(3)
Installation Instructions
npm install @psenger/bidirectional-map --save
or
yarn add @psenger/bidirectional-map
License
MIT License
Copyright (c) 2021 Philip A Senger
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Deployment Steps
- create a pull request from
dev
tomain
- check out
main
npm version patch -m "message here" or minor
npm publish
- Then switch to
dev
branch - And then merge
main
intodev
and pushdev
to origin