-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCollection.ahk
101 lines (81 loc) · 1.95 KB
/
Collection.ahk
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#Requires AutoHotKey 2.1-alpha.4
; —————————— Collection functions ——————————
class helperColletions {
static lookup(arr_where, str_what) {
for i, obj in arr_where
if obj[1] = str_what
return obj[2]
return ""
}
}
class OrderedMap extends Map { ; autohotkey.com/boards/viewtopic.php?f=82&t=94114&p=418207
__New(KVPairs*) {
super.__New(KVPairs*)
KeyArray := []
keyCount := KVPairs.Length // 2
KeyArray.Length := keyCount
Loop keyCount
KeyArray[A_Index] := KVPairs[(A_Index << 1) - 1]
this.KeyArray := KeyArray
}
__Item[key] {
set {
if !this.Has(key)
this.KeyArray.Push(key)
return super[key] := value
}
}
Clear() {
super.Clear()
this.KeyArray := []
}
Clone() {
Other := super.Clone()
Other.KeyArray := this.KeyArray.Clone()
return Other
}
Delete(key) {
try {
RemovedValue := super.Delete(key)
CaseSense := this.CaseSense
for i, Element in this.KeyArray {
areSame := (Element is String)
? !StrCompare(Element, key, CaseSense)
: (Element = key)
if areSame {
this.KeyArray.RemoveAt(i)
break
}
}
return RemovedValue
}
catch Error as Err
throw Error(Err.Message, -1, Err.Extra)
}
Set(KVPairs*) {
if (KVPairs.Length & 1)
throw ValueError('Invalid number of parameters.', -1)
KeyArray := this.KeyArray
keyCount := KVPairs.Length // 2
KeyArray.Capacity += keyCount
Loop keyCount {
key := KVPairs[(A_Index << 1) - 1]
if !this.Has(key)
KeyArray.Push(key)
}
super.Set(KVPairs*)
return this
}
__Enum(*) {
keyEnum := this.KeyArray.__Enum(1)
keyValEnum(&key := unset, &val := unset) {
if keyEnum(&key) {
val := this[key]
return true
} else {
return false
}
}
return keyValEnum
}
}