source: trunk/ab5.0/ablib/src/Classes/System/Collections/Generic/Queue.ab

Last change on this file was 631, checked in by NoWest, 16 years ago

List<T>、Stack<T>、Queue<T>を相互にIEnumerator<T>を使って変換できるようにしました。

List<T>クラスからReadOnlyCollectionの呼び出しがコンパイルできません。
どうしても問題を再現できなかったので、皆さんの所でも問題が発生するか確認のためにupしておきます。
やっぱり問題がおきたら、RevertするかListのAsReadOnlyメソッドをコメントアウトしてください。

File size: 2.3 KB
Line 
1
2Namespace System
3Namespace Collections
4Namespace Generic
5
6Class Queue<T>
7 Implements IEnumerable<T>
8
9 items As *T
10 size As Long
11 count As Long
12
13 Sub Realloc ( allocateSize As Long )
14 This.items = realloc( This.items, allocateSize * SizeOf(T) )
15 End Sub
16
17 Sub initialize()
18 This.items = GC_malloc(1)
19 End Sub
20
21Public
22 Sub Queue ()
23 This.initialize()
24 End Sub
25
26 Sub Queue ( capacity As Long )
27 This.initialize()
28 If capacity > 0 Then
29 This.size = capacity
30 Realloc(capacity)
31 End If
32 End Sub
33
34 Sub Queue ( enumerator As IEnumerator<T> )
35 This.initialize()
36 While enumerator.MoveNext()
37 This.Enqueue(enumerator.Current())
38 Wend
39 End Sub
40
41Public
42 'ある要素が Queue内に存在するかどうかを判断
43/* Override Function Contains ( item As T ) As Boolean
44 TODO
45 End Function*/
46
47 '既存の 1 次元の Array に Stack をコピーします。コピー操作は、配列の指定したインデックスから始まります。
48/* CopyTo*/
49
50 /*!
51 @brief IEnumeratorインターフェイスを取得する
52 @author NoWest
53 @date 2008/07/20
54 @return IEnumeratorインターフェイス
55 */
56 Override Function GetEnumerator () As IEnumerator<T>
57 Return New Detail.PointerEnumerator<T>(items, count)
58 End Function
59
60 /*!
61 @brief Queueの先頭にあるオブジェクトを削除し、返します
62 @author NoWest
63 @date 2008/07/20
64 */
65 Function Dequeue () As T
66 Dequeue = This.items[ 0 ]
67 memmove( items, items + SizeOf(T), (This.count - 1)*SizeOf(T) )
68 This.count--
69 End Function
70
71 /*!
72 @brief Queueの末尾にオブジェクトを追加します
73 @author NoWest
74 @date 2008/07/20
75 */
76 Sub Enqueue ( item As T )
77 If This.size < (This.count + 1) Then
78 This.size++
79 Realloc( This.size )
80 End If
81 This.items[ This.count ] = item
82 This.count++
83 End Sub
84
85 /*!
86 @brief Queueの先頭にあるオブジェクトを削除せずに返します
87 @author NoWest
88 @date 2008/07/20
89 */
90 Function Peek () As T
91 Peek = This.items[ 0 ]
92 End Function
93
94 'Queueを新しい配列にコピーします。
95/* ToArray*/
96
97 /*!
98 @brief 実際の要素数が現在の容量の 90% 未満の場合は、容量をその数に設定します
99 @author NoWest
100 @date 2008/07/20
101 */
102 Sub TrimExcess ()
103 Dim pmemobj = _System_pGC->GetMemoryObjectPtr( items )
104 If ( This.size ) * 0.9 > This.count Then
105 This.size = This.count
106 Realloc( This.size )
107 End If
108 End Sub
109End Class
110
111End Namespace
112End Namespace
113End Namespace
Note: See TracBrowser for help on using the repository browser.