Changeset 558
- Timestamp:
- Jul 20, 2008, 10:31:12 PM (16 years ago)
- Location:
- trunk/ab5.0/ablib/src/Classes
- Files:
-
- 1 added
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/ab5.0/ablib/src/Classes/System/Collections/Generic/List.ab
r557 r558 9 9 items As *T 10 10 size As Long 11 count As Long 11 12 12 13 currentIndexForEnumerator As Long … … 32 33 Sub List( capacity As Long ) 33 34 This.List() 34 This.Realloc( capacity ) 35 If capacity > 0 Then 36 This.size = capacity 37 Realloc(capacity) 38 End If 35 39 End Sub 36 40 … … 41 45 @param インデックス 42 46 */ 43 Sub List( array As *T, count As Long ) 44 This.List( count ) 45 memmove( This.items, array, count * SizeOf(T) ) 46 This.size = count 47 End Sub 47 Sub List( array As *T, length As Long ) 48 This.List( length ) 49 memmove( This.items, array, length * SizeOf(T) ) 50 This.count = length 51 End Sub 52 48 53 Sub ~List() 49 54 End Sub … … 83 88 */ 84 89 Override Function Count() As Long 85 Return size90 Return This.count 86 91 End Function 87 92 … … 106 111 */ 107 112 Override Sub Add( item As T ) 108 Realloc( size + 1 ) 109 110 items[size] = item 111 size++ 113 If This.size < (This.count + 1) Then 114 This.size++ 115 Realloc( This.size ) 116 End If 117 This.items[ This.count ] = item 118 This.count++ 112 119 End Sub 113 120 … … 120 127 */ 121 128 Override Sub Clear() 122 size= 0129 This.count = 0 123 130 End Sub 124 131 … … 135 142 Override Function IndexOf( item As T ) As Long 136 143 Dim i As Long 137 For i = 0 To ELM( size)144 For i = 0 To ELM( This.count ) 138 145 If items[i].Equals(item) Then 139 146 Return i … … 149 156 */ 150 157 Override Sub Insert( index As Long, item As T ) 151 Realloc( size + 1 ) 152 memmove( items + (index+1)*SizeOf(T), items + index*SizeOf(T), (size-index)*SizeOf(T) ) 158 If This.size < (This.count + 1) Then 159 This.size++ 160 Realloc( This.size ) 161 End If 162 memmove( items + (index+1)*SizeOf(T), items + index*SizeOf(T), (This.count - index)*SizeOf(T) ) 153 163 items[index] = item 154 size++164 This.count++ 155 165 End Sub 156 166 … … 175 185 @author Daisuke Yamamoto 176 186 @date 2007/10/03 177 @return 値が削除されたときはTrue、されなかったときはFlaseが返る178 187 */ 179 188 Override Sub RemoveAt( index As Long ) 180 memmove( items + index*SizeOf(T), items + (index+1)*SizeOf(T), (size-(index+1))*SizeOf(T) ) 181 Realloc( size - 1 ) 182 size-- 189 memmove( items + index*SizeOf(T), items + (index+1)*SizeOf(T), (This.count - (index+1))*SizeOf(T) ) 190 This.count-- 183 191 End Sub 184 192 … … 192 200 Dim string As String 193 201 Dim i As Long 194 For i = 0 To This.Count-2202 For i = 0 To ELM( This.count ) 195 203 string += This[i].ToString() + Ex"\r\n" 196 204 Next 197 205 Return string + This[i].ToString() 198 206 End Function 207 208 /*! 209 @brief 実際の要素数が現在の容量の 90% 未満の場合は、容量をその数に設定します 210 @author NoWest 211 @date 2008/07/20 212 */ 213 Sub TrimExcess () 214 Dim pmemobj = _System_pGC->GetMemoryObjectPtr( items ) 215 If ( This.size ) * 0.9 > This.count Then 216 This.size = This.count 217 Realloc( This.size ) 218 End If 219 End Sub 199 220 200 221 /*! -
trunk/ab5.0/ablib/src/Classes/System/Collections/Generic/Stack.ab
r557 r558 72 72 */ 73 73 Function Peek () As T 74 Peek = This.items[ This.count -1]74 Peek = This.items[ 0 ] 75 75 End Function 76 76 … … 81 81 */ 82 82 Function Pop () As T 83 Pop = This.items[ This.count -1 ] 83 Pop = This.items[ 0 ] 84 memmove( items, items + SizeOf(T), (This.count - 1)*SizeOf(T) ) 84 85 This.count-- 85 86 End Function … … 91 92 */ 92 93 Sub Push ( item As T ) 93 This.count++ 94 If This.size < This.count Then 94 If This.size < (This.count + 1) Then 95 95 This.size++ 96 96 Realloc( This.size ) 97 97 End If 98 This.items[ This.count -1 ] = item 98 memmove( items + SizeOf(T), items, This.count * SizeOf(T) ) 99 items[ 0 ] = item 100 This.count++ 99 101 End Sub 100 102 -
trunk/ab5.0/ablib/src/Classes/index.ab
r557 r558 30 30 #require "./System/Collections/Generic/Dictionary.ab" 31 31 #require "./System/Collections/Generic/List.ab" 32 #require "./System/Collections/Generic/Queue.ab" 32 33 #require "./System/Collections/Generic/Stack.ab" 33 34 #require "./System/Collections/Generic/KeyNotFoundException.ab"
Note:
See TracChangeset
for help on using the changeset viewer.