-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathbase.util.longmap.bmx
More file actions
306 lines (266 loc) · 7.04 KB
/
base.util.longmap.bmx
File metadata and controls
306 lines (266 loc) · 7.04 KB
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
SuperStrict
Import "base.util.longmap.c"
Extern
Function bmx_map_longmap_clear(root:Byte Ptr Ptr)
Function bmx_map_longmap_isempty:Int(root:Byte Ptr Ptr)
Function bmx_map_longmap_insert(key:Long, value:Object, root:Byte Ptr Ptr)
Function bmx_map_longmap_contains:Int(key:Long, root:Byte Ptr Ptr)
Function bmx_map_longmap_valueforkey:Object(key:Long, root:Byte Ptr Ptr)
Function bmx_map_longmap_remove:Int(key:Long, root:Byte Ptr Ptr)
Function bmx_map_longmap_firstnode:Byte Ptr(root:Byte Ptr)
Function bmx_map_longmap_nextnode:Byte Ptr(node:Byte Ptr)
Function bmx_map_longmap_key:Long(node:Byte Ptr)
Function bmx_map_longmap_value:Object(node:Byte Ptr)
Function bmx_map_longmap_hasnext:Int(node:Byte Ptr, root:Byte Ptr)
Function bmx_map_longmap_copy(dst:Byte Ptr Ptr, _root:Byte Ptr)
End Extern
Rem
bbdoc: A key/value (Int/Object) map.
End Rem
Type TLongMap
Method Delete()
Clear
End Method
Rem
bbdoc: Clears the map.
about: Removes all keys and values.
End Rem
Method Clear()
?ngcmod
If Not IsEmpty() Then
_modCount :+ 1
End If
?
bmx_map_longmap_clear(Varptr _root)
End Method
Rem
bbdoc: Checks if the map is empty.
about: #True if @map is empty, otherwise #False.
End Rem
Method IsEmpty:Int()
Return bmx_map_longmap_isempty(Varptr _root)
End Method
Rem
bbdoc: Inserts a key/value pair into the map.
about: If the map already contains @key, its value is overwritten with @value.
End Rem
Method Insert( key:Long,value:Object )
bmx_map_longmap_insert(key, value, Varptr _root)
?ngcmod
_modCount :+ 1
?
End Method
Rem
bbdoc: Checks if the map contains @key.
returns: #True if the map contains @key.
End Rem
Method Contains:Int( key:Long )
Return bmx_map_longmap_contains(key, Varptr _root)
End Method
Rem
bbdoc: Finds a value given a @key.
returns: The value associated with @key.
about: If the map does not contain @key, a #Null object is returned.
End Rem
Method ValueForKey:Object( key:Long )
Return bmx_map_longmap_valueforkey(key, Varptr _root)
End Method
Rem
bbdoc: Remove a key/value pair from the map.
returns: #True if @key was removed, or #False otherwise.
End Rem
Method Remove:Int( key:Long )
?ngcmod
_modCount :+ 1
?
Return bmx_map_longmap_remove(key, Varptr _root)
End Method
Method _FirstNode:TLongNode()
If Not IsEmpty() Then
Local node:TLongNode= New TLongNode
node._root = _root
Return node
Else
Return Null
End If
End Method
Rem
bbdoc: Gets the map keys.
returns: An enumeration object
about: The object returned by #Keys can be used with #EachIn to iterate through the keys in the map.
End Rem
Method Keys:TLongMapEnumerator()
Local nodeenum:TLongNodeEnumerator
If Not isEmpty() Then
nodeenum=New TLongKeyEnumerator
nodeenum._node=_FirstNode()
Else
nodeenum=New TLongEmptyEnumerator
End If
Local mapenum:TLongMapEnumerator=New TLongMapEnumerator
mapenum._enumerator=nodeenum
nodeenum._map = Self
?ngcmod
nodeenum._expectedModCount = _modCount
?
Return mapenum
End Method
Rem
bbdoc: Get the map values.
returns: An enumeration object.
about: The object returned by #Values can be used with #EachIn to iterate through the values in the map.
End Rem
Method Values:TLongMapEnumerator()
Local nodeenum:TLongNodeEnumerator
If Not isEmpty() Then
nodeenum=New TLongValueEnumerator
nodeenum._node=_FirstNode()
Else
nodeenum=New TLongEmptyEnumerator
End If
Local mapenum:TLongMapEnumerator=New TLongMapEnumerator
mapenum._enumerator=nodeenum
nodeenum._map = Self
?ngcmod
nodeenum._expectedModCount = _modCount
?
Return mapenum
End Method
Rem
bbdoc: Returns a copy the contents of this map.
End Rem
Method Copy:TLongMap()
Local map:TLongMap=New TLongMap
bmx_map_longmap_copy(Varptr map._root, _root)
Return map
End Method
Rem
bbdoc: Returns a node enumeration object.
about: The object returned by #ObjectEnumerator can be used with #EachIn to iterate through the nodes in the map.
End Rem
Method ObjectEnumerator:TLongNodeEnumerator()
Local nodeenum:TLongNodeEnumerator
If Not isEmpty() Then
nodeenum = New TLongNodeEnumerator
nodeenum._node=_FirstNode()
nodeenum._map = Self
Else
nodeenum=New TLongEmptyEnumerator
End If
Return nodeenum
End Method
Rem
bbdoc: Finds a value given a @key using index syntax.
returns: The value associated with @key.
about: If the map does not contain @key, a #Null object is returned.
End Rem
Method Operator[]:Object(key:Long)
Return bmx_map_longmap_valueforkey(key, Varptr _root)
End Method
Rem
bbdoc: Inserts a key/value pair into the map using index syntax.
about: If the map already contains @key, its value is overwritten with @value.
End Rem
Method Operator[]=(key:Long, value:Object)
bmx_map_longmap_insert(key, value, Varptr _root)
End Method
Field _root:Byte Ptr
?ngcmod
Field _modCount:Int
?
End Type
Type TLongNode
Field _root:Byte Ptr
Field _nodePtr:Byte Ptr
Field _nextNode:Byte Ptr
Method key:Long()
Return bmx_map_longmap_key(_nodePtr)
End Method
Method Value:Object()
Return bmx_map_longmap_value(_nodePtr)
End Method
Method HasNext:Int()
Return bmx_map_longmap_hasnext(_nodePtr, _root)
End Method
Method NextNode:TLongNode()
If Not _nodePtr Then
_nodePtr = bmx_map_longmap_firstnode(_root)
Else
'_nodePtr = bmx_map_longmap_nextnode(_nodePtr)
_nodePtr = _nextNode
End If
If HasNext() Then
_nextNode = bmx_map_longmap_nextnode(_nodePtr)
End If
Return Self
End Method
Method Remove()
End Method
End Type
Rem
bbdoc: Long holder for key returned by TLongMap.Keys() enumerator.
about: Because a single instance of #TLongKey is used during enumeration, #value changes on each iteration.
End Rem
Type TLongKey
Rem
bbdoc: Long key value.
End Rem
Field value:Long
End Type
Type TLongNodeEnumerator
Method HasNext:Int()
Local has:Int = _node.HasNext()
If Not has Then
_map = Null
End If
Return has
End Method
Method NextObject:Object()
?ngcmod
Assert _expectedModCount = _map._modCount, "TLongMap Concurrent Modification"
?
Local node:TLongNode=_node
_node=_node.NextNode()
Return node
End Method
'***** PRIVATE *****
Field _node:TLongNode
Field _map:TLongMap
?ngcmod
Field _expectedModCount:Int
?
End Type
Type TLongKeyEnumerator Extends TLongNodeEnumerator
Field _key:TLongKey = New TLongKey
Method NextObject:Object() Override
?ngcmod
Assert _expectedModCount = _map._modCount, "TLongMap Concurrent Modification"
?
Local node:TLongNode=_node
_node=_node.NextNode()
_key.value = node.Key()
Return _key
End Method
End Type
Type TLongValueEnumerator Extends TLongNodeEnumerator
Method NextObject:Object() Override
?ngcmod
Assert _expectedModCount = _map._modCount, "TLongMap Concurrent Modification"
?
Local node:TLongNode=_node
_node=_node.NextNode()
Return node.Value()
End Method
End Type
Type TLongMapEnumerator
Method ObjectEnumerator:TLongNodeEnumerator()
Return _enumerator
End Method
Field _enumerator:TLongNodeEnumerator
End Type
Type TLongEmptyEnumerator Extends TLongNodeEnumerator
Method HasNext:Int() Override
_map = Null
Return False
End Method
End Type