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

Last change on this file since 582 was 582, checked in by イグトランス (egtra), 16 years ago

非Genericコレクションインタフェースの扱いを大幅に縮小。Queue/Stackの実装インタフェースの修正。

File size: 2.1 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
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
30Public
31 'ある要素が Queue内に存在するかどうかを判断
32/* Override Function Contains ( item As T ) As Boolean
33 TODO
34 End Function*/
35
36 '既存の 1 次元の Array に Stack をコピーします。コピー操作は、配列の指定したインデックスから始まります。
37/* CopyTo*/
38
39 /*!
40 @brief IEnumeratorインターフェイスを取得する
41 @author NoWest
42 @date 2008/07/20
43 @return IEnumeratorインターフェイス
44 */
45 Override Function GetEnumerator () As IEnumerator<T>
46 Return New Detail.PointerEnumerator(items, count)
47 End Function
48
49 /*!
50 @brief Queueの先頭にあるオブジェクトを削除し、返します
51 @author NoWest
52 @date 2008/07/20
53 */
54 Function Dequeue () As T
55 Dequeue = This.items[ 0 ]
56 memmove( items, items + SizeOf(T), (This.count - 1)*SizeOf(T) )
57 This.count--
58 End Function
59
60 /*!
61 @brief Queueの末尾にオブジェクトを追加します
62 @author NoWest
63 @date 2008/07/20
64 */
65 Sub Enqueue ( item As T )
66 If This.size < (This.count + 1) Then
67 This.size++
68 Realloc( This.size )
69 End If
70 This.items[ This.count ] = item
71 This.count++
72 End Sub
73
74 /*!
75 @brief Queueの先頭にあるオブジェクトを削除せずに返します
76 @author NoWest
77 @date 2008/07/20
78 */
79 Function Peek () As T
80 Peek = This.items[ 0 ]
81 End Function
82
83 'Queueを新しい配列にコピーします。
84/* ToArray*/
85
86 /*!
87 @brief 実際の要素数が現在の容量の 90% 未満の場合は、容量をその数に設定します
88 @author NoWest
89 @date 2008/07/20
90 */
91 Sub TrimExcess ()
92 Dim pmemobj = _System_pGC->GetMemoryObjectPtr( items )
93 If ( This.size ) * 0.9 > This.count Then
94 This.size = This.count
95 Realloc( This.size )
96 End If
97 End Sub
98End Class
99
100End Namespace
101End Namespace
102End Namespace
Note: See TracBrowser for help on using the repository browser.