Changeset 309 for trunk/Include/Classes/System/Collections
- Timestamp:
- Aug 27, 2007, 12:12:32 AM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Include/Classes/System/Collections/ArrayList.ab
r291 r309 10 10 capacity As Long 11 11 12 Sub Init( sizeAs Long )12 Sub Init( capacity As Long ) 13 13 If size < 0 Then 14 14 ' Error … … 16 16 End If 17 17 18 This.size = size18 This.size = 0 19 19 This.capacity = size 20 20 21 pObject = GC_malloc( SizeOf(*Object) * size + 1)21 pObject = GC_malloc( SizeOf(*Object) * size ) 22 22 If pObject = 0 Then 23 23 ' OutOfMemoryException … … 26 26 End Sub 27 27 28 Sub Realloc( size As Long )29 If size > capacity Then30 ' miss!31 Debug32 End If33 34 pObject = realloc( pObject, SizeOf(*Object) * size + 1)35 If p Object= 0 Then28 Sub Realloc( newSize As Long ) 29 ' If newSize > capacity Then 30 ' ' miss! 31 ' Debug 32 ' End If 33 34 Dim p = realloc( pObject, SizeOf(*Object) * newSize ) 35 If p = 0 Then 36 36 ' OutOfMemoryException 37 37 Debug 38 End If 39 capacity = size 38 Else 39 pObject = p 40 End If 41 capacity = newSize 40 42 End Sub 41 43 42 44 Sub SetLeastCapacity( capacity As Long ) 43 45 If This.capacity < capacity Then 44 This.capacity = capacity45 46 Realloc(capacity) 46 47 End If … … 112 113 ' Constractors 113 114 Sub ArrayList() 114 Init( 0)115 Init( 16 ) 115 116 End Sub 116 117 /* … … 133 134 SetLeastCapacity( size + 1 ) 134 135 pObject[size] = object 136 Add = size 135 137 size++ 136 Return size - 1137 138 End Function 138 139 … … 187 188 Dim arrayList = New ArrayList( size ) 188 189 memcpy( arrayList.pObject, This.pObject, SizeOf(*Object) * size ) 190 arrayList.size = This.size 189 191 Return arrayList 190 192 End Function … … 260 262 If i > 0 Then 261 263 RemoveAt(i) 262 size--263 264 End If 264 265 End Sub … … 266 267 Override Sub RemoveAt(i As Long) 267 268 RemoveRange(i, 1) 268 size--269 269 End Sub 270 270 … … 336 336 Dim i As Long 337 337 For i = 0 To ELM(c) 338 Repeat ->Add(x)338 Repeat.Add(x) 339 339 Next 340 340 End Function
Note:
See TracChangeset
for help on using the changeset viewer.