import { keyString } from './buffer_string' ; import cloneDeep = require ( 'lodash.clonedeep' ) ; export class BufferMap < V > { private _data : { [ key ] : V | undefined ; } = { } ; public constructor ( data ? ) { this . _data = data ?? { } ; } public get size ( ) : number { return Object . keys ( this . _data ) . length ; } public get ( key ) { return this . _data [ keyString ( key ) ] ; } public delete ( key ) { delete this . _data [ keyString ( key ) ] ; } public set ( key , value ) { this . _data [ keyString ( key ) ] = value ; } public has ( key ) { return this . _data [ keyString ( key ) ] !== undefined ; } public clone ( ) { return new BufferMap ( cloneDeep ( this . _data ) ) ; } public entries ( ) { return Object . entries ( this . _data ) . map ( ( [ key , value ] ) => [ Buffer . from ( key , 'binary' ) , value , ] ) as [ Buffer , V ] [ ] ; } public values ( ) { return Object . values ( this . _data as { [ key ] : V ; } ) ; } }