UNPKG

hazelcast-client

Version:

Hazelcast - open source In-Memory Data Grid - client for NodeJS

92 lines 2.98 kB
"use strict"; var DataKeyedHashMap = (function () { function DataKeyedHashMap() { this.internalStore = new Map(); this.size = 0; } DataKeyedHashMap.prototype.clear = function () { this.size = 0; this.internalStore = new Map(); }; DataKeyedHashMap.prototype.delete = function (key) { var existingIndex = this.findIndexInBucket(key); if (existingIndex === -1) { return false; } else { this.getOrCreateBucket(key.hashCode()).splice(existingIndex, 1); this.size--; return true; } }; DataKeyedHashMap.prototype.has = function (key) { return this.findIndexInBucket(key) !== -1; }; DataKeyedHashMap.prototype.get = function (key) { var keyHash = key.hashCode(); var existingIndex = this.findIndexInBucket(key); if (existingIndex !== -1) { return this.getOrCreateBucket(keyHash)[existingIndex].value; } else { return undefined; } }; DataKeyedHashMap.prototype.set = function (key, value) { var keyHash = key.hashCode(); var existingIndex = this.findIndexInBucket(key); if (existingIndex !== -1) { this.getOrCreateBucket(keyHash)[existingIndex].value = value; } else { this.getOrCreateBucket(keyHash).push({ key: key, value: value }); this.size++; } return this; }; DataKeyedHashMap.prototype.values = function () { var snapshot = []; this.internalStore.forEach(function (bucket) { snapshot.push.apply(snapshot, (bucket.map(function (item) { return item.value; }))); }); return snapshot; }; DataKeyedHashMap.prototype.entries = function () { var snapshot = []; this.internalStore.forEach(function (bucket) { snapshot.push.apply(snapshot, (bucket.map(function (item) { return [item.key, item.value]; }))); }); return snapshot; }; DataKeyedHashMap.prototype.findIndexInBucket = function (key) { var keyHash = key.hashCode(); var bucket = this.internalStore.get(keyHash); if (bucket === undefined) { return -1; } else { return bucket.findIndex(function (item) { return item.key.equals(key); }); } }; DataKeyedHashMap.prototype.getOrCreateBucket = function (key) { var bucket; bucket = this.internalStore.get(key); if (bucket === undefined) { bucket = []; this.internalStore.set(key, bucket); } return bucket; }; return DataKeyedHashMap; }()); exports.DataKeyedHashMap = DataKeyedHashMap; var InternalRecord = (function () { function InternalRecord() { } return InternalRecord; }()); //# sourceMappingURL=DataStoreHashMap.js.map