UNPKG

@hclsoftware/secagent

Version:

IAST agent

77 lines (65 loc) 1.89 kB
//IASTIGNORE /* * **************************************************** * Licensed Materials - Property of HCL. * (c) Copyright HCL Technologies Ltd. 2017, 2025. * Note to U.S. Government Users *Restricted Rights. * **************************************************** */ const {IASTHashMap} = require('./IASTHashMap') const Utils = require('./Utils') module.exports.IASTHashSet = class IASTHashSet { constructor (equals, hashFunc) { this.hashMap = new IASTHashMap(equals, hashFunc) } add (value) { this.hashMap.set(value, 1) } delete (key) { return this.hashMap.delete(key) } contains (key) { return this.hashMap.containsKey(key) } get length () { return this.hashMap.length } equals (other) { if (other.length !== this.length) { return false } for (const item of other) { if (!this.contains(item)) { return false } } return true } join (delimeter) { const stringBuilder = [] for (const item of this) { stringBuilder.push(item.toString()) } return stringBuilder.join(delimeter) } [Symbol.iterator] () { return { iter: this.hashMap[Symbol.iterator](), next () { const next = this.iter.next() return { value: (next.value != null ? next.value.key : null), done: next.done } } } } get hashCode () { const hashObj = Utils.createHashObject() for (const item of this) { hashObj.update(item.hashCode) } return hashObj.produce() } forEach (callback) { // Iterate over the keys in the HashMap and apply the callback to each key this.hashMap.keys().forEach(key => callback(key)); } }