export class Multiset < T > { private map : Map < T , number > = new Map ( ) ; constructor ( items = [ ] ) { items . forEach ( ( item ) => this . add ( item ) ) ; } add ( key , count = 1 ) { const val = ( this . get ( key ) || 0 ) + count ; this . map . set ( key , val ) ; return val ; } subtract ( key , count = 1 ) { const val = this . get ( key ) ; if ( val === undefined ) return ; this . map . set ( key , val - count ) ; } remove ( key ) { this . map . delete ( key ) ; } get ( key ) { return this . map . get ( key ) ; } entries ( ) { return Array . from ( this . map ) ; } toString ( ) { return this . map . toString ( ) ; } }