import { keyString } from './buffer_string' ; import cloneDeep = require ( 'lodash.clonedeep' ) ; export class BufferSet { private _data : { [ key ] : Buffer ; } = { } ; public constructor ( data ? ) { this . _data = { } ; if ( data ) { for ( const d of data ) { this . add ( d ) ; } } } public delete ( key ) { delete this . _data [ keyString ( key ) ] ; } public add ( value ) { this . _data [ keyString ( value ) ] = value ; } public has ( value ) { return this . _data [ keyString ( value ) ] !== undefined ; } public clone ( ) { return new BufferSet ( cloneDeep ( Object . values ( this . _data ) ) ) ; } public get size ( ) : number { return Object . keys ( this . _data ) . length ; } public [ Symbol . iterator ] ( ) { let index = - 1 ; const data = Object . values < Buffer > ( this . _data ) ; return { next : ( ) : { value : Buffer ; done : boolean ; } => { index += 1 ; return { value : data [ index ] , done : ! ( index in data ) , } ; } , } ; } }