Init
This commit is contained in:
41
node_modules/sweet-collections/dist/map/SizedMap.js
generated
vendored
Normal file
41
node_modules/sweet-collections/dist/map/SizedMap.js
generated
vendored
Normal file
@ -0,0 +1,41 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.SizedMap = void 0;
|
||||
class SizedMap {
|
||||
constructor(limit) {
|
||||
if (limit < 0) {
|
||||
throw new Error('Map size limit should positive.');
|
||||
}
|
||||
this.limit = limit;
|
||||
this.map = new Map();
|
||||
}
|
||||
delete(key) {
|
||||
return this.map.delete(key);
|
||||
}
|
||||
keys() {
|
||||
return this.map.keys();
|
||||
}
|
||||
values() {
|
||||
return [...this.map.values()].map((node) => node.value)[Symbol.iterator]();
|
||||
}
|
||||
entries() {
|
||||
return [...this.map.values()]
|
||||
.map((node) => [node.key, node.value])[Symbol.iterator]();
|
||||
}
|
||||
isFull() {
|
||||
return this.size === this.limit;
|
||||
}
|
||||
clear() {
|
||||
this.map.clear();
|
||||
}
|
||||
[Symbol.iterator]() {
|
||||
return this.entries();
|
||||
}
|
||||
forEach(cb, thisArg) {
|
||||
this.map.forEach((item) => cb.call(thisArg, item.value, item.key, this));
|
||||
}
|
||||
get size() {
|
||||
return this.map.size;
|
||||
}
|
||||
}
|
||||
exports.SizedMap = SizedMap;
|
||||
Reference in New Issue
Block a user