@@ -21,18 +21,18 @@ type IndexID struct {
2121
2222func NewIndex [T any ]() * Index [T ] {
2323 return & Index [T ]{
24- Exact : map [ xtype.Signature ][ ]IndexEntry [T ]{} ,
24+ Exact : xtype .NewSignatureMap [[ ]IndexEntry [T ]]() ,
2525 }
2626}
2727
2828type Index [T any ] struct {
29- Exact map [ xtype.Signature ][ ]IndexEntry [T ]
29+ Exact * xtype.SignatureMap [[ ]IndexEntry [T ] ]
3030 Update []* T
3131}
3232
3333func (l * Index [T ]) GetAll () []* T {
3434 items := []* T {}
35- for _ , exacts := range l .Exact {
35+ for _ , exacts := range l .Exact . Values () {
3636 for _ , exact := range exacts {
3737 items = append (items , exact .Item )
3838 }
@@ -42,14 +42,17 @@ func (l *Index[T]) GetAll() []*T {
4242
4343func (l * Index [T ]) RegisterOverrideOverlapping (t * T , def * Definition ) {
4444 newEntry := IndexEntry [T ]{Def : def , Item : t }
45- for i , entry := range l .Exact [def .Signature ] {
45+ entries , _ := l .Exact .At (def .Signature )
46+ for i , entry := range entries {
4647 if satisfiesContext (entry .Def .Context , def .Context ) || satisfiesContext (def .Context , entry .Def .Context ) {
47- l.Exact [def.Signature ][i ] = newEntry
48+ entries [i ] = newEntry
49+ l .Exact .Set (def .Signature , entries )
4850 return
4951 }
5052 }
5153
52- l .Exact [def .Signature ] = append (l .Exact [def .Signature ], newEntry )
54+ entries = append (entries , newEntry )
55+ l .Exact .Set (def .Signature , entries )
5356}
5457
5558func (l * Index [T ]) RegisterUpdate (t * T , def * Definition ) (IndexID , error ) {
@@ -58,7 +61,8 @@ func (l *Index[T]) RegisterUpdate(t *T, def *Definition) (IndexID, error) {
5861}
5962
6063func (l * Index [T ]) Register (t * T , def * Definition ) (IndexID , error ) {
61- for _ , entry := range l .Exact [def .Signature ] {
64+ entries , _ := l .Exact .At (def .Signature )
65+ for _ , entry := range entries {
6266 if err := checkOverlap (entry .Def , def ); err != nil {
6367 return IndexID {}, err
6468 }
@@ -68,8 +72,10 @@ func (l *Index[T]) Register(t *T, def *Definition) (IndexID, error) {
6872 }
6973
7074 newEntry := IndexEntry [T ]{Def : def , Item : t }
71- l .Exact [def .Signature ] = append (l .Exact [def .Signature ], newEntry )
72- return IndexID {sig : def .Signature , idx : len (l .Exact [def .Signature ]) - 1 }, nil
75+ entries = append (entries , newEntry )
76+ l .Exact .Set (def .Signature , entries )
77+
78+ return IndexID {sig : def .Signature , idx : len (entries ) - 1 }, nil
7379}
7480
7581func checkOverlap (left , right * Definition ) error {
@@ -83,16 +89,17 @@ func (l *Index[T]) ByID(id IndexID) *T {
8389 if id .update {
8490 return l .Update [id .idx ]
8591 }
86- return l.Exact [id.sig ][id.idx ].Item
92+ value , _ := l .Exact .At (id .sig )
93+ return value [id .idx ].Item
8794}
8895
8996func (l * Index [T ]) Has (sig xtype.Signature ) bool {
90- _ , ok := l .Exact [ sig ]
97+ _ , ok := l .Exact . At ( sig )
9198 return ok
9299}
93100
94101func (l * Index [T ]) Get (sig xtype.Signature , m map [string ]* xtype.Type ) (* T , error ) {
95- hits , ok := l .Exact [ sig ]
102+ hits , ok := l .Exact . At ( sig )
96103 if ! ok {
97104 return nil , nil
98105 }
0 commit comments