Security News
tea.xyz Spam Plagues npm and RubyGems Package Registries
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
@mootable/hashmap
Advanced tools
Changelog
1.0.7
Readme
This project provides HashMap
and LinkedHashMap
classes that works both on Node.js and the browser.
Hashmap
is not guaranteed to meet order of insertion when iterating over it. If you want guaranteed insertion order when iterating, use LinkedHashMap
.Using npm:
$ npm install @mootable/hashmap
You can download the last stable version from the releases page.
If you like risk, you can download the latest master version, it's usually stable.
To run the tests:
$ npm test
To run the benchmarks: (Ensure you have the memory to run them)
If you don't you can reduce the memory size (in MB) accordingly --max_old_space_size
and remove the last items in MAP_SIZES
$ node --max_old_space_size=24576 --expose-gc test\benchmark.js
import {HashMap, LinkedHashMap} from '@mootable/hashmap';
const {HashMap, LinkedHashMap} = require('@mootable/hashmap');
<!-- Or one of the other provided alternates (see dist folder) -->
<script src="pathToFile/hashmap.umd.min.js"></script>
<script type="text/javascript">
// By Default Mootable is on the global scope.
const HashMap = Mootable.HashMap;
const LinkedHashMap = Mootable.LinkedHashMap;
</script>
This HashMap is backed by a hashtrie.
new HashMap()
creates an empty hashmapnew HashMap(copy:Iterable)
creates a hashmap which is a copy of the provided iterable.
copy
eitherMap.forEach
, such as Map
or this HashMap
and LinkedHashMap
[['key1','val1'], ['key2','val2']]
.LinkedHashMap maintains insertion order of keys, it has a slightly larger memory footprint and is a little slower.
new LinkedHashMap()
creates an empty linked hashmapnew LinkedHashMap(copy:Iterable)
creates a linked hashmap which is a copy of the provided iterable.
copy
eitherMap.forEach
, such as Map
or this HashMap
and LinkedHashMap
[['key1','val1'], ['key2','val2']]
.HashMap and LinkedHashMaps, have the same constructor options, and are created in the same way..
Create an empty HashMap
const hashmap = new HashMap();
// hashmap.size === 0;
Create a LinkedHashMap from an array of key value pairs
const arr = [[1,'value1'],[2,'value2'],[3,'value3']];
const hashmap = new LinkedHashMap(arr);
// hashmap.size === 3;
Create HashMap from another map
const map = new Map([[1,'value1'],[2,'value2'],[3,'value3']])
const hashmap = new HashMap(map);
// hashmap.size === 3;
Create LinkedHashMap from another HashMap
const first = new HashMap([[1,'value1'],[2,'value2'],[3,'value3']])
const hashmap = new LinkedHashMap(first);
// hashmap.size === 3;
Create a HashMap from a class with symbol
class MyIterable {
*[Symbol.iterator] () {
yield ["key1", "value1"];
yield ["key2", "value2"];
yield ["key3", "value3"];
yield ["key4", "value4"];
}
}
const iterable = new MyIterable();
const hashmap = new HashMap(iterable);
// hashmap.size === 4;
// it doesn't have to be a generator, an iterator works too.
Create a LinkedHashMap from an object with an entries' generator function
const entriesObj = {
entries: function* () {
yield ["key1", "value1"];
yield ["key2", "value2"];
yield ["key3", "value3"];
yield ["key4", "value4"];
}
}
const hashmap = new LinkedHashMap(entriesObj);
// hashmap.size === 4;
// it doesn't have to be a generator, an iterator works too.
Create HashMap from an object with a forEach function
const forEachObj = {
forEach: (callback, ctx) => {
for (let i = 1; i <= 4; i++) {
callback.call(ctx, 'value' + i, 'key' + i);
}
}
};
const hashmap = new HashMap(forEachObj);
// hashmap.size === 4;
The MIT License (MIT)
Copyright (c) 2021 Jack Moxley
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
FAQs
HashMap, LinkedHashMap and Higher Order Functions for all other Iterables, such as Map, Set and Array
The npm package @mootable/hashmap receives a total of 158 weekly downloads. As such, @mootable/hashmap popularity was classified as not popular.
We found that @mootable/hashmap demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.
Security News
UnitedHealth Group disclosed that the ransomware attack on Change Healthcare compromised protected health information for millions in the U.S., with estimated costs to the company expected to reach $1 billion.