[558] | 1 |
|
---|
| 2 | Namespace System
|
---|
| 3 | Namespace Collections
|
---|
| 4 | Namespace Generic
|
---|
| 5 |
|
---|
| 6 | Class Queue<T>
|
---|
[582] | 7 | Implements IEnumerable<T>
|
---|
[558] | 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 | Public
|
---|
| 18 | Sub Queue ()
|
---|
| 19 | This.items = GC_malloc( 1 )
|
---|
| 20 | End Sub
|
---|
| 21 |
|
---|
| 22 | Sub Queue ( capacity As Long )
|
---|
[560] | 23 | This.items = GC_malloc( 1 )
|
---|
[558] | 24 | If capacity > 0 Then
|
---|
| 25 | This.size = capacity
|
---|
| 26 | Realloc(capacity)
|
---|
| 27 | End If
|
---|
| 28 | End Sub
|
---|
| 29 |
|
---|
| 30 | Public
|
---|
| 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>
|
---|
[607] | 46 | Return New Detail.PointerEnumerator<T>(items, count)
|
---|
[558] | 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
|
---|
| 98 | End Class
|
---|
| 99 |
|
---|
| 100 | End Namespace
|
---|
| 101 | End Namespace
|
---|
| 102 | End Namespace
|
---|