Namespace System Namespace Collections Namespace Generic Class Queue Implements IEnumerable items As *T size As Long count As Long Sub Realloc ( allocateSize As Long ) This.items = realloc( This.items, allocateSize * SizeOf(T) ) End Sub Sub initialize() This.items = GC_malloc(1) End Sub Public Sub Queue () This.initialize() End Sub Sub Queue ( capacity As Long ) This.initialize() If capacity > 0 Then This.size = capacity Realloc(capacity) End If End Sub Sub Queue ( enumerator As IEnumerator ) This.initialize() While enumerator.MoveNext() This.Enqueue(enumerator.Current()) Wend End Sub Public 'ある要素が Queue内に存在するかどうかを判断 /* Override Function Contains ( item As T ) As Boolean TODO End Function*/ '既存の 1 次元の Array に Stack をコピーします。コピー操作は、配列の指定したインデックスから始まります。 /* CopyTo*/ /*! @brief IEnumeratorインターフェイスを取得する @author NoWest @date 2008/07/20 @return IEnumeratorインターフェイス */ Override Function GetEnumerator () As IEnumerator Return New Detail.PointerEnumerator(items, count) End Function /*! @brief Queueの先頭にあるオブジェクトを削除し、返します @author NoWest @date 2008/07/20 */ Function Dequeue () As T Dequeue = This.items[ 0 ] memmove( items, items + SizeOf(T), (This.count - 1)*SizeOf(T) ) This.count-- End Function /*! @brief Queueの末尾にオブジェクトを追加します @author NoWest @date 2008/07/20 */ Sub Enqueue ( item As T ) If This.size < (This.count + 1) Then This.size++ Realloc( This.size ) End If This.items[ This.count ] = item This.count++ End Sub /*! @brief Queueの先頭にあるオブジェクトを削除せずに返します @author NoWest @date 2008/07/20 */ Function Peek () As T Peek = This.items[ 0 ] End Function 'Queueを新しい配列にコピーします。 /* ToArray*/ /*! @brief 実際の要素数が現在の容量の 90% 未満の場合は、容量をその数に設定します @author NoWest @date 2008/07/20 */ Sub TrimExcess () Dim pmemobj = _System_pGC->GetMemoryObjectPtr( items ) If ( This.size ) * 0.9 > This.count Then This.size = This.count Realloc( This.size ) End If End Sub End Class End Namespace End Namespace End Namespace