Something similar to Set<String, Set<String>>
in Java?
Asked
Active
Viewed 3,373 times
5

Motti
- 110,860
- 49
- 189
- 262

akapulko2020
- 1,079
- 2
- 22
- 36
1 Answers
12
A Set is an unordered collection of unique elements. Many Set implementations are based on hash tables (possibly of key-value pairs). VBScript has a Dictionary class -
Dim dicParent : Set dicParent = CreateObject("Scripting.Dictionary")
You can't add the same key twice, so the keys of a VBScript Dictionary represent/model a Set (the Set is ordered (by insertion), however). Nothing keeps you from putting (other) Dictionaries into the values:
>> Dim dicParent : Set dicParent = CreateObject("Scripting.Dictionary")
>> dicParent.Add "Fst", CreateObject("Scripting.Dictionary")
>> dicParent("Fst").Add "Snd", "child of parent"
>> WScript.Echo dicParent("Fst")("Snd")
>>
child of parent
In VBScript (and theory), you can even use objects as keys (not only strings as in other languages):
>> Dim dicParent : Set dicParent = CreateObject("Scripting.Dictionary")
>> Dim dicChild : Set dicChild = CreateObject("Scripting.Dictionary")
>> dicParent(dicChild) = "child of parent"
>> WScript.Echo dicParent(dicChild)
>>
child of parent
Your practical mileage may vary.

Ekkehard.Horner
- 38,498
- 2
- 45
- 96
-
Nice remark about using objects as keys. Allthough, I'll have to think about a practical use for that. Maybe a poor man's linked list, stack or queue. – AutomatedChaos Jan 30 '12 at 16:49
-
Oh, I've used it to implement something like API caching -- to minimize references to the DataTable object, storing object properties (or references) in a dictionary. Works fine, can be useful indeed. – TheBlastOne Mar 22 '12 at 14:22