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

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