@@ -989,43 +989,43 @@ namespace ts {
989989 return result ;
990990 }
991991
992- /**
993- * Adds the value to an array of values associated with the key, and returns the array.
994- * Creates the array if it does not already exist.
995- */
996- export function multiMapAdd < V > ( map : Map < V [ ] > , key : string , value : V ) : V [ ] {
997- let values = map . get ( key ) ;
998- if ( values ) {
999- values . push ( value ) ;
1000- }
1001- else {
1002- map . set ( key , values = [ value ] ) ;
1003- }
1004- return values ;
992+ export interface MultiMap < T > extends Map < T [ ] > {
993+ /**
994+ * Adds the value to an array of values associated with the key, and returns the array.
995+ * Creates the array if it does not already exist.
996+ */
997+ add ( key : string , value : T ) : T [ ] ;
998+ /**
999+ * Removes a value from an array of values associated with the key.
1000+ * Does not preserve the order of those values.
1001+ * Does nothing if `key` is not in `map`, or `value` is not in `map[key]`.
1002+ */
1003+ remove ( key : string , value : T ) : void ;
10051004 }
10061005
1007- export function multiMapSparseArrayAdd < V > ( map : SparseArray < V [ ] > , key : number , value : V ) : V [ ] {
1008- let values = map [ key ] ;
1006+ export function createMultiMap < T > ( ) : MultiMap < T > {
1007+ const map = createMap < T [ ] > ( ) as MultiMap < T > ;
1008+ map . add = multiMapAdd ;
1009+ map . remove = multiMapRemove ;
1010+ return map ;
1011+ }
1012+ function multiMapAdd < T > ( this : MultiMap < T > , key : string , value : T ) {
1013+ let values = this . get ( key ) ;
10091014 if ( values ) {
10101015 values . push ( value ) ;
10111016 }
10121017 else {
1013- map [ key ] = values = [ value ] ;
1018+ this . set ( key , values = [ value ] ) ;
10141019 }
10151020 return values ;
1016- }
10171021
1018- /**
1019- * Removes a value from an array of values associated with the key.
1020- * Does not preserve the order of those values.
1021- * Does nothing if `key` is not in `map`, or `value` is not in `map[key]`.
1022- */
1023- export function multiMapRemove < V > ( map : Map < V [ ] > , key : string , value : V ) : void {
1024- const values = map . get ( key ) ;
1022+ }
1023+ function multiMapRemove < T > ( this : MultiMap < T > , key : string , value : T ) {
1024+ const values = this . get ( key ) ;
10251025 if ( values ) {
10261026 unorderedRemoveItem ( values , value ) ;
10271027 if ( ! values . length ) {
1028- map . delete ( key ) ;
1028+ this . delete ( key ) ;
10291029 }
10301030 }
10311031 }
0 commit comments