Map with "more pairs"?

tchart

Well-Known Member
Licensed User
Longtime User
Hi

I have a project which uses a 2 Maps.

Map 1 has a key (numerical id) and a value which is a URL. Map 2 has a key (the URL from map 1) and then a custom type/structure. I have some custom functions which can get and remove items from both maps at the same time.

The reason I use 2 maps is so that I can quickly look up values based on the numerical id or the URL.

Now I'm thinking I should put this in a class but wanted to check if;

1) Has someone already done something like this as a class?
2) Is there a better way to do this?

Thanks
 

tchart

Well-Known Member
Licensed User
Longtime User
A work in progress but heres the class so far (I've called it MapX2 in my project);

'Class module
Sub Class_Globals
Dim Map1 As Map
Dim Map2 As Map
End Sub

'Initializes the object. You can add parameters to this method if needed.
Public Sub Initialize
Map1.Initialize
Map2.Initialize
End Sub

Public Sub ContainsKey1(key As Object) As Boolean
Return Map1.ContainsKey(key)
End Sub

Public Sub ContainsKey2(key As Object) As Boolean
Return Map2.ContainsKey(key)
End Sub

Public Sub Put(Key As Object, Value1 As Object, Value2 As Object) As Object
Map2.Put(Value1 , Value2)
Return Map1.Put(Key ,Value1)
End Sub

Public Sub Remove (Key As Object) As Object
Dim Key2 As Object
Key2 = Map1.Get(Key)
Map2.Remove(Key2)
Return Map1.Remove(Key)
End Sub

Public Sub Get1(Key As Object) As Object
Return Map1.Get(Key)
End Sub

Public Sub Get2(Key As Object) As Object
Dim Key2 As Object
Key2 = Map1.Get(Key)
Return Map2.Get(Key2)
End Sub

Public Sub Size() As Int
Return Map1.Size
End Sub
 
Upvote 0
Top