Mega Code Archive

 
Categories / Delphi / Examples
 

Numeric Queue

Title: Numeric Queue Question: Queue is a first-in-first-out type of an ordered List. this is an Extended version of Queue.it's take Integer,Cardinal and int64 types. Answer: unit QueueEx; {--------------------------------------------- | Done by Harout Bulbulian | | Email: haroutbulbulian2000@yahoo.com | ----------------------------------------------} interface uses SysUtils, Classes, Contnrs; type //TIntegerQueue //it's converts the pointers to integers TIntegerQueue = class(TQueue) public function Push(AItem: Integer): Integer; function Pop: Integer; function Peek: Integer; end; //TCardinalQueue //it's converts the pointers to cardinal TCardinalQueue = class(TQueue) public function Push(AItem: Cardinal): Cardinal; function Pop: Cardinal; function Peek: Cardinal; end; //TInt64Queue //it's fills tow Pointer place for one int64 type TInt64Queue = class(TIntegerQueue) protected procedure PushItem(Aitem: Int64); function PopItem: Int64; function PeekItem: Int64; public function Count: integer; function AtLiest(ACount: Integer): Boolean; function Push(AItem: Int64): Int64; function Pop: Int64; function Peek: Cardinal; end; implementation { TIntegerQueue } function TIntegerQueue.Peek: Integer; begin Peek := Integer( inherited Peek) end; function TIntegerQueue.Pop: Integer; begin Pop := Integer( inherited Pop) end; function TIntegerQueue.Push(AItem: Integer): Integer; begin Push := Integer( inherited Push(Pointer(AItem))) end; { TCardinalQueue } function TCardinalQueue.Peek: Cardinal; begin Peek := Cardinal( inherited Peek) end; function TCardinalQueue.Pop: Cardinal; begin Pop := Cardinal( inherited Pop) end; function TCardinalQueue.Push(AItem: Cardinal): Cardinal; begin Push := Cardinal( inherited Push(Pointer(AItem))) end; { TInt64Queue } function TInt64Queue.PeekItem: Int64; var I: Int64; begin I := Int64(List.Items[List.Count-1]); //peek high order of int64 PeekItem := Int64(List.Items[List.Count-2])or I //peek low order of int64 and combine it with the high one end; function TInt64Queue.Peek: Int64; begin Peek := PeekItem end; function TInt64Queue.Pop: Int64; begin Pop := PopItem end; function TInt64Queue.PopItem: Int64; var I: Int64; begin I := Int64(Inherited Pop);//pop high order of int64 PopItem := (Int64(inherited Pop) shr 32)or I //pop low order of int64 and combine it with the high one end; function TInt64Queue.Push(AItem: Int64): Int64; begin PushItem(Aitem); Push := AItem end; procedure TInt64Queue.PushItem(Aitem: Int64); begin inherited Push(Aitem);//push high order of int64 inherited Push(Aitem shr 32) //push low order of int64 end; function TInt64Queue.AtLiest(ACount: Integer): Boolean; begin AtLiest := ACount = Count end; function TInt64Queue.Count: integer; begin Count := List.Count*2 end; end. {-----------------------------------------------------------} if you have an comments or correction, please write them.