1
1
/**
2
2
* @since 2.0.0
3
3
*/
4
- import { dual , pipe } from "./Function.js"
4
+ import { dual } from "./Function.js"
5
+ import * as HashMap from "./HashMap.js"
5
6
import { hasProperty } from "./Predicate.js"
6
7
import type * as TestAnnotation from "./TestAnnotation.js"
7
8
@@ -23,13 +24,13 @@ export type TestAnnotationMapTypeId = typeof TestAnnotationMapTypeId
23
24
export interface TestAnnotationMap {
24
25
readonly [ TestAnnotationMapTypeId ] : TestAnnotationMapTypeId
25
26
/** @internal */
26
- readonly map : ReadonlyMap < TestAnnotation . TestAnnotation < unknown > , unknown >
27
+ readonly map : HashMap . HashMap < TestAnnotation . TestAnnotation < any > , any >
27
28
}
28
29
29
30
/** @internal */
30
31
class TestAnnotationMapImpl implements TestAnnotationMap {
31
32
readonly [ TestAnnotationMapTypeId ] : TestAnnotationMapTypeId = TestAnnotationMapTypeId
32
- constructor ( readonly map : ReadonlyMap < TestAnnotation . TestAnnotation < unknown > , unknown > ) {
33
+ constructor ( readonly map : HashMap . HashMap < TestAnnotation . TestAnnotation < any > , any > ) {
33
34
}
34
35
}
35
36
@@ -41,12 +42,12 @@ export const isTestAnnotationMap = (u: unknown): u is TestAnnotationMap => hasPr
41
42
/**
42
43
* @since 2.0.0
43
44
*/
44
- export const empty : ( _ : void ) => TestAnnotationMap = ( ) => new TestAnnotationMapImpl ( new Map ( ) )
45
+ export const empty : ( _ : void ) => TestAnnotationMap = ( ) => new TestAnnotationMapImpl ( HashMap . empty ( ) )
45
46
46
47
/**
47
48
* @since 2.0.0
48
49
*/
49
- export const make = ( map : ReadonlyMap < TestAnnotation . TestAnnotation < unknown > , unknown > ) : TestAnnotationMap => {
50
+ export const make = ( map : HashMap . HashMap < TestAnnotation . TestAnnotation < any > , any > ) : TestAnnotationMap => {
50
51
return new TestAnnotationMapImpl ( map )
51
52
}
52
53
@@ -56,11 +57,7 @@ export const make = (map: ReadonlyMap<TestAnnotation.TestAnnotation<unknown>, un
56
57
export const overwrite = dual <
57
58
< A > ( key : TestAnnotation . TestAnnotation < A > , value : A ) => ( self : TestAnnotationMap ) => TestAnnotationMap ,
58
59
< A > ( self : TestAnnotationMap , key : TestAnnotation . TestAnnotation < A > , value : A ) => TestAnnotationMap
59
- > ( 3 , ( self , key , value ) =>
60
- make (
61
- ( self . map as Map < TestAnnotation . TestAnnotation < unknown > , unknown > )
62
- . set ( key as TestAnnotation . TestAnnotation < unknown > , value )
63
- ) )
60
+ > ( 3 , ( self , key , value ) => make ( HashMap . set ( self . map , key , value ) ) )
64
61
65
62
/**
66
63
* @since 2.0.0
@@ -69,11 +66,11 @@ export const update = dual<
69
66
< A > ( key : TestAnnotation . TestAnnotation < A > , f : ( value : A ) => A ) => ( self : TestAnnotationMap ) => TestAnnotationMap ,
70
67
< A > ( self : TestAnnotationMap , key : TestAnnotation . TestAnnotation < A > , f : ( value : A ) => A ) => TestAnnotationMap
71
68
> ( 3 , < A > ( self : TestAnnotationMap , key : TestAnnotation . TestAnnotation < A > , f : ( value : A ) => A ) => {
72
- let value = self . map . get ( key as TestAnnotation . TestAnnotation < unknown > )
73
- if ( value === undefined ) {
74
- value = key . initial
69
+ let value = key . initial
70
+ if ( HashMap . has ( self . map , key . identifier ) ) {
71
+ value = HashMap . unsafeGet ( self . map , key . identifier ) as A
75
72
}
76
- return pipe ( self , overwrite ( key , f ( value as A ) ) )
73
+ return overwrite ( self , key , f ( value ) )
77
74
} )
78
75
79
76
/**
@@ -86,11 +83,10 @@ export const get = dual<
86
83
< A > ( key : TestAnnotation . TestAnnotation < A > ) => ( self : TestAnnotationMap ) => A ,
87
84
< A > ( self : TestAnnotationMap , key : TestAnnotation . TestAnnotation < A > ) => A
88
85
> ( 2 , < A > ( self : TestAnnotationMap , key : TestAnnotation . TestAnnotation < A > ) => {
89
- const value = self . map . get ( key as TestAnnotation . TestAnnotation < unknown > )
90
- if ( value === undefined ) {
91
- return key . initial as A
86
+ if ( HashMap . has ( self . map , key . identifier ) ) {
87
+ return HashMap . unsafeGet ( self . map , key . identifier ) as A
92
88
}
93
- return value as A
89
+ return key . initial
94
90
} )
95
91
96
92
/**
@@ -110,13 +106,13 @@ export const combine = dual<
110
106
( that : TestAnnotationMap ) => ( self : TestAnnotationMap ) => TestAnnotationMap ,
111
107
( self : TestAnnotationMap , that : TestAnnotationMap ) => TestAnnotationMap
112
108
> ( 2 , ( self , that ) => {
113
- const result = new Map < TestAnnotation . TestAnnotation < unknown > , unknown > ( self . map )
109
+ let result = self . map
114
110
for ( const entry of that . map ) {
115
- if ( result . has ( entry [ 0 ] ) ) {
116
- const value = result . get ( entry [ 0 ] ) !
117
- result . set ( entry [ 0 ] , entry [ 0 ] . combine ( value , entry [ 1 ] ) )
111
+ if ( HashMap . has ( result , entry [ 0 ] ) ) {
112
+ const value = HashMap . get ( result , entry [ 0 ] ) !
113
+ result = HashMap . set ( result , entry [ 0 ] , entry [ 0 ] . combine ( value , entry [ 1 ] ) )
118
114
} else {
119
- result . set ( entry [ 0 ] , entry [ 1 ] )
115
+ result = HashMap . set ( result , entry [ 0 ] , entry [ 1 ] )
120
116
}
121
117
}
122
118
return make ( result )
0 commit comments