refactor
This commit is contained in:
+1
-1
@@ -4,4 +4,4 @@ echo "======================="
|
||||
echo " "
|
||||
echo "Compiling FPC Sources..."
|
||||
echo " "
|
||||
fpc -Aelf -gw -g -gl -n -v0ew -O3 -OpPENTIUM3 -Si -Sc -Sg -Xd -CX -XXs -CfSSE -CfSSE2 -Rintel -Pi386 -Tlinux -FElib/ -Fusrc/* -Fusrc/include/queues -Fusrc/driver/* -Fusrc/driver/net/* -Fusrc/driver/bus/* -Fusrc/driver/bus/usb/* -Fusrc/driver/hid/* src/kernel.pas
|
||||
fpc -Aelf -gw -g -gl -n -v0ew -O3 -OpPENTIUM3 -Si -Sc -Sg -Xd -CX -XXs -CfSSE -CfSSE2 -Rintel -Pi386 -Tlinux -FElib/ -Fusrc/* -Fusrc/include/data_structures/* -Fusrc/driver/* -Fusrc/driver/net/* -Fusrc/driver/bus/* -Fusrc/driver/bus/usb/* -Fusrc/driver/hid/* src/kernel.pas
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -13,11 +13,11 @@
|
||||
// limitations under the License.
|
||||
|
||||
{
|
||||
Queue Types - Shared type definitions for all queue data structures.
|
||||
Data Structure Types - Shared type definitions for all data structures.
|
||||
|
||||
@author(Aaron Hance <ah@aaronhance.me>)
|
||||
}
|
||||
unit q_types;
|
||||
unit dstypes;
|
||||
|
||||
interface
|
||||
|
||||
@@ -17,17 +17,17 @@
|
||||
|
||||
@author(Aaron Hance <ah@aaronhance.me>)
|
||||
}
|
||||
unit q_fifo;
|
||||
unit fifo;
|
||||
|
||||
interface
|
||||
|
||||
uses
|
||||
lmemorymanager,
|
||||
util,
|
||||
q_types;
|
||||
dstypes;
|
||||
|
||||
{ ============================================================================ }
|
||||
{ FIFO Queue — Q_FIFO_* API }
|
||||
{ FIFO Queue — FIFO_* API }
|
||||
{ ============================================================================ }
|
||||
|
||||
{**
|
||||
@@ -35,14 +35,14 @@ uses
|
||||
@param ElementSize Size (in bytes) of each element.
|
||||
@returns Pointer to the new queue.
|
||||
**}
|
||||
function Q_FIFO_New(ElementSize : uint32) : PFIFOQueue;
|
||||
function FIFO_New(ElementSize : uint32) : PFIFOQueue;
|
||||
|
||||
{**
|
||||
@abstract Enqueues an element at the back of the FIFO queue.
|
||||
@param Queue Pointer to the FIFO queue.
|
||||
@param Data Pointer to the element data to copy in.
|
||||
**}
|
||||
procedure Q_FIFO_Enqueue(Queue : PFIFOQueue; Data : void);
|
||||
procedure FIFO_Enqueue(Queue : PFIFOQueue; Data : void);
|
||||
|
||||
{**
|
||||
@abstract Dequeues the front element from the FIFO queue.
|
||||
@@ -50,47 +50,47 @@ uses
|
||||
@param Data Pointer to a buffer that receives the dequeued element.
|
||||
@returns True if an element was dequeued, false if the queue was empty.
|
||||
**}
|
||||
function Q_FIFO_Dequeue(Queue : PFIFOQueue; Data : void) : boolean;
|
||||
function FIFO_Dequeue(Queue : PFIFOQueue; Data : void) : boolean;
|
||||
|
||||
{**
|
||||
@abstract Peeks at the front element without removing it.
|
||||
@param Queue Pointer to the FIFO queue.
|
||||
@returns Pointer to the front element data, or nil if empty.
|
||||
**}
|
||||
function Q_FIFO_Peek(Queue : PFIFOQueue) : void;
|
||||
function FIFO_Peek(Queue : PFIFOQueue) : void;
|
||||
|
||||
{**
|
||||
@abstract Returns the number of elements in the FIFO queue.
|
||||
@param Queue Pointer to the FIFO queue.
|
||||
@returns Element count.
|
||||
**}
|
||||
function Q_FIFO_Size(Queue : PFIFOQueue) : uint32;
|
||||
function FIFO_Size(Queue : PFIFOQueue) : uint32;
|
||||
|
||||
{**
|
||||
@abstract Checks whether the FIFO queue is empty.
|
||||
@param Queue Pointer to the FIFO queue.
|
||||
@returns True if empty.
|
||||
**}
|
||||
function Q_FIFO_IsEmpty(Queue : PFIFOQueue) : boolean;
|
||||
function FIFO_IsEmpty(Queue : PFIFOQueue) : boolean;
|
||||
|
||||
{**
|
||||
@abstract Frees the FIFO queue and all its nodes.
|
||||
@param Queue Pointer to the FIFO queue.
|
||||
**}
|
||||
procedure Q_FIFO_Free(Queue : PFIFOQueue);
|
||||
procedure FIFO_Free(Queue : PFIFOQueue);
|
||||
|
||||
implementation
|
||||
|
||||
function Q_FIFO_New(ElementSize : uint32) : PFIFOQueue;
|
||||
function FIFO_New(ElementSize : uint32) : PFIFOQueue;
|
||||
begin
|
||||
Q_FIFO_New := PFIFOQueue(kalloc(sizeof(TFIFOQueue)));
|
||||
Q_FIFO_New^.Head := nil;
|
||||
Q_FIFO_New^.Tail := nil;
|
||||
Q_FIFO_New^.Count := 0;
|
||||
Q_FIFO_New^.ElementSize := ElementSize;
|
||||
FIFO_New := PFIFOQueue(kalloc(sizeof(TFIFOQueue)));
|
||||
FIFO_New^.Head := nil;
|
||||
FIFO_New^.Tail := nil;
|
||||
FIFO_New^.Count := 0;
|
||||
FIFO_New^.ElementSize := ElementSize;
|
||||
end;
|
||||
|
||||
procedure Q_FIFO_Enqueue(Queue : PFIFOQueue; Data : void);
|
||||
procedure FIFO_Enqueue(Queue : PFIFOQueue; Data : void);
|
||||
var
|
||||
Node : PQueueNode;
|
||||
begin
|
||||
@@ -108,11 +108,11 @@ begin
|
||||
Queue^.Count := Queue^.Count + 1;
|
||||
end;
|
||||
|
||||
function Q_FIFO_Dequeue(Queue : PFIFOQueue; Data : void) : boolean;
|
||||
function FIFO_Dequeue(Queue : PFIFOQueue; Data : void) : boolean;
|
||||
var
|
||||
Node : PQueueNode;
|
||||
begin
|
||||
Q_FIFO_Dequeue := false;
|
||||
FIFO_Dequeue := false;
|
||||
if Queue^.Head = nil then exit;
|
||||
|
||||
Node := Queue^.Head;
|
||||
@@ -125,28 +125,28 @@ begin
|
||||
Queue^.Count := Queue^.Count - 1;
|
||||
kfree(Node^.Data);
|
||||
kfree(void(Node));
|
||||
Q_FIFO_Dequeue := true;
|
||||
FIFO_Dequeue := true;
|
||||
end;
|
||||
|
||||
function Q_FIFO_Peek(Queue : PFIFOQueue) : void;
|
||||
function FIFO_Peek(Queue : PFIFOQueue) : void;
|
||||
begin
|
||||
if Queue^.Head = nil then
|
||||
Q_FIFO_Peek := nil
|
||||
FIFO_Peek := nil
|
||||
else
|
||||
Q_FIFO_Peek := Queue^.Head^.Data;
|
||||
FIFO_Peek := Queue^.Head^.Data;
|
||||
end;
|
||||
|
||||
function Q_FIFO_Size(Queue : PFIFOQueue) : uint32;
|
||||
function FIFO_Size(Queue : PFIFOQueue) : uint32;
|
||||
begin
|
||||
Q_FIFO_Size := Queue^.Count;
|
||||
FIFO_Size := Queue^.Count;
|
||||
end;
|
||||
|
||||
function Q_FIFO_IsEmpty(Queue : PFIFOQueue) : boolean;
|
||||
function FIFO_IsEmpty(Queue : PFIFOQueue) : boolean;
|
||||
begin
|
||||
Q_FIFO_IsEmpty := (Queue^.Count = 0);
|
||||
FIFO_IsEmpty := (Queue^.Count = 0);
|
||||
end;
|
||||
|
||||
procedure Q_FIFO_Free(Queue : PFIFOQueue);
|
||||
procedure FIFO_Free(Queue : PFIFOQueue);
|
||||
var
|
||||
Node, Next : PQueueNode;
|
||||
begin
|
||||
@@ -13,21 +13,21 @@
|
||||
// limitations under the License.
|
||||
|
||||
{
|
||||
Queue LIFO - Last-In First-Out stack, linked-list backed.
|
||||
LIFO Stack - Last-In First-Out stack, linked-list backed.
|
||||
|
||||
@author(Aaron Hance <ah@aaronhance.me>)
|
||||
}
|
||||
unit q_lifo;
|
||||
unit lifo;
|
||||
|
||||
interface
|
||||
|
||||
uses
|
||||
lmemorymanager,
|
||||
util,
|
||||
q_types;
|
||||
dstypes;
|
||||
|
||||
{ ============================================================================ }
|
||||
{ LIFO Stack — Q_LIFO_* API }
|
||||
{ LIFO Stack — lifo_* API }
|
||||
{ ============================================================================ }
|
||||
|
||||
{**
|
||||
@@ -35,14 +35,14 @@ uses
|
||||
@param ElementSize Size (in bytes) of each element.
|
||||
@returns Pointer to the new stack.
|
||||
**}
|
||||
function Q_LIFO_New(ElementSize : uint32) : PLIFOStack;
|
||||
function lifo_New(ElementSize : uint32) : PLIFOStack;
|
||||
|
||||
{**
|
||||
@abstract Pushes an element onto the top of the stack.
|
||||
@param Stack Pointer to the LIFO stack.
|
||||
@param Data Pointer to the element data to copy in.
|
||||
**}
|
||||
procedure Q_LIFO_Push(Stack : PLIFOStack; Data : void);
|
||||
procedure lifo_Push(Stack : PLIFOStack; Data : void);
|
||||
|
||||
{**
|
||||
@abstract Pops the top element from the stack.
|
||||
@@ -50,46 +50,46 @@ uses
|
||||
@param Data Pointer to a buffer that receives the popped element.
|
||||
@returns True if an element was popped, false if the stack was empty.
|
||||
**}
|
||||
function Q_LIFO_Pop(Stack : PLIFOStack; Data : void) : boolean;
|
||||
function lifo_Pop(Stack : PLIFOStack; Data : void) : boolean;
|
||||
|
||||
{**
|
||||
@abstract Peeks at the top element without removing it.
|
||||
@param Stack Pointer to the LIFO stack.
|
||||
@returns Pointer to the top element data, or nil if empty.
|
||||
**}
|
||||
function Q_LIFO_Peek(Stack : PLIFOStack) : void;
|
||||
function lifo_Peek(Stack : PLIFOStack) : void;
|
||||
|
||||
{**
|
||||
@abstract Returns the number of elements on the stack.
|
||||
@param Stack Pointer to the LIFO stack.
|
||||
@returns Element count.
|
||||
**}
|
||||
function Q_LIFO_Size(Stack : PLIFOStack) : uint32;
|
||||
function lifo_Size(Stack : PLIFOStack) : uint32;
|
||||
|
||||
{**
|
||||
@abstract Checks whether the stack is empty.
|
||||
@param Stack Pointer to the LIFO stack.
|
||||
@returns True if empty.
|
||||
**}
|
||||
function Q_LIFO_IsEmpty(Stack : PLIFOStack) : boolean;
|
||||
function lifo_IsEmpty(Stack : PLIFOStack) : boolean;
|
||||
|
||||
{**
|
||||
@abstract Frees the stack and all its nodes.
|
||||
@param Stack Pointer to the LIFO stack.
|
||||
**}
|
||||
procedure Q_LIFO_Free(Stack : PLIFOStack);
|
||||
procedure lifo_Free(Stack : PLIFOStack);
|
||||
|
||||
implementation
|
||||
|
||||
function Q_LIFO_New(ElementSize : uint32) : PLIFOStack;
|
||||
function lifo_New(ElementSize : uint32) : PLIFOStack;
|
||||
begin
|
||||
Q_LIFO_New := PLIFOStack(kalloc(sizeof(TLIFOStack)));
|
||||
Q_LIFO_New^.Top := nil;
|
||||
Q_LIFO_New^.Count := 0;
|
||||
Q_LIFO_New^.ElementSize := ElementSize;
|
||||
lifo_New := PLIFOStack(kalloc(sizeof(TLIFOStack)));
|
||||
lifo_New^.Top := nil;
|
||||
lifo_New^.Count := 0;
|
||||
lifo_New^.ElementSize := ElementSize;
|
||||
end;
|
||||
|
||||
procedure Q_LIFO_Push(Stack : PLIFOStack; Data : void);
|
||||
procedure lifo_Push(Stack : PLIFOStack; Data : void);
|
||||
var
|
||||
Node : PQueueNode;
|
||||
begin
|
||||
@@ -101,11 +101,11 @@ begin
|
||||
Stack^.Count := Stack^.Count + 1;
|
||||
end;
|
||||
|
||||
function Q_LIFO_Pop(Stack : PLIFOStack; Data : void) : boolean;
|
||||
function lifo_Pop(Stack : PLIFOStack; Data : void) : boolean;
|
||||
var
|
||||
Node : PQueueNode;
|
||||
begin
|
||||
Q_LIFO_Pop := false;
|
||||
lifo_Pop := false;
|
||||
if Stack^.Top = nil then exit;
|
||||
|
||||
Node := Stack^.Top;
|
||||
@@ -115,28 +115,28 @@ begin
|
||||
Stack^.Count := Stack^.Count - 1;
|
||||
kfree(Node^.Data);
|
||||
kfree(void(Node));
|
||||
Q_LIFO_Pop := true;
|
||||
lifo_Pop := true;
|
||||
end;
|
||||
|
||||
function Q_LIFO_Peek(Stack : PLIFOStack) : void;
|
||||
function lifo_Peek(Stack : PLIFOStack) : void;
|
||||
begin
|
||||
if Stack^.Top = nil then
|
||||
Q_LIFO_Peek := nil
|
||||
lifo_Peek := nil
|
||||
else
|
||||
Q_LIFO_Peek := Stack^.Top^.Data;
|
||||
lifo_Peek := Stack^.Top^.Data;
|
||||
end;
|
||||
|
||||
function Q_LIFO_Size(Stack : PLIFOStack) : uint32;
|
||||
function lifo_Size(Stack : PLIFOStack) : uint32;
|
||||
begin
|
||||
Q_LIFO_Size := Stack^.Count;
|
||||
lifo_Size := Stack^.Count;
|
||||
end;
|
||||
|
||||
function Q_LIFO_IsEmpty(Stack : PLIFOStack) : boolean;
|
||||
function lifo_IsEmpty(Stack : PLIFOStack) : boolean;
|
||||
begin
|
||||
Q_LIFO_IsEmpty := (Stack^.Count = 0);
|
||||
lifo_IsEmpty := (Stack^.Count = 0);
|
||||
end;
|
||||
|
||||
procedure Q_LIFO_Free(Stack : PLIFOStack);
|
||||
procedure lifo_Free(Stack : PLIFOStack);
|
||||
var
|
||||
Node, Next : PQueueNode;
|
||||
begin
|
||||
@@ -13,20 +13,20 @@
|
||||
// limitations under the License.
|
||||
|
||||
{
|
||||
Queue Max-Heap - Highest priority value extracted first.
|
||||
Max-Heap - Highest priority value extracted first.
|
||||
|
||||
@author(Aaron Hance <ah@aaronhance.me>)
|
||||
}
|
||||
unit q_maxh;
|
||||
unit maxh;
|
||||
|
||||
interface
|
||||
|
||||
uses
|
||||
q_types,
|
||||
q_heap;
|
||||
dstypes,
|
||||
bheap;
|
||||
|
||||
{ ============================================================================ }
|
||||
{ Max-Heap — Q_MAXH_* API }
|
||||
{ Max-Heap — maxh_* API }
|
||||
{ ============================================================================ }
|
||||
|
||||
{**
|
||||
@@ -35,7 +35,7 @@ uses
|
||||
@param InitialCapacity Starting number of slots (will grow as needed).
|
||||
@returns Pointer to the new heap.
|
||||
**}
|
||||
function Q_MAXH_New(ElementSize : uint32; InitialCapacity : uint32) : PBinaryHeap;
|
||||
function maxh_New(ElementSize : uint32; InitialCapacity : uint32) : PBinaryHeap;
|
||||
|
||||
{**
|
||||
@abstract Inserts an element into the max-heap.
|
||||
@@ -43,7 +43,7 @@ uses
|
||||
@param Priority Priority value (higher = higher priority).
|
||||
@param Data Pointer to the element data to copy in.
|
||||
**}
|
||||
procedure Q_MAXH_Insert(Heap : PBinaryHeap; Priority : uint32; Data : void);
|
||||
procedure maxh_Insert(Heap : PBinaryHeap; Priority : uint32; Data : void);
|
||||
|
||||
{**
|
||||
@abstract Extracts the maximum-priority element from the heap.
|
||||
@@ -51,70 +51,70 @@ uses
|
||||
@param Data Pointer to a buffer that receives the extracted element.
|
||||
@returns True if an element was extracted, false if the heap was empty.
|
||||
**}
|
||||
function Q_MAXH_ExtractMax(Heap : PBinaryHeap; Data : void) : boolean;
|
||||
function maxh_ExtractMax(Heap : PBinaryHeap; Data : void) : boolean;
|
||||
|
||||
{**
|
||||
@abstract Peeks at the maximum-priority element without removing it.
|
||||
@param Heap Pointer to the heap.
|
||||
@returns Pointer to the element data, or nil if empty.
|
||||
**}
|
||||
function Q_MAXH_PeekMax(Heap : PBinaryHeap) : void;
|
||||
function maxh_PeekMax(Heap : PBinaryHeap) : void;
|
||||
|
||||
{**
|
||||
@abstract Returns the number of elements in the max-heap.
|
||||
@param Heap Pointer to the heap.
|
||||
@returns Element count.
|
||||
**}
|
||||
function Q_MAXH_Size(Heap : PBinaryHeap) : uint32;
|
||||
function maxh_Size(Heap : PBinaryHeap) : uint32;
|
||||
|
||||
{**
|
||||
@abstract Checks whether the max-heap is empty.
|
||||
@param Heap Pointer to the heap.
|
||||
@returns True if empty.
|
||||
**}
|
||||
function Q_MAXH_IsEmpty(Heap : PBinaryHeap) : boolean;
|
||||
function maxh_IsEmpty(Heap : PBinaryHeap) : boolean;
|
||||
|
||||
{**
|
||||
@abstract Frees the max-heap and all its elements.
|
||||
@param Heap Pointer to the heap.
|
||||
**}
|
||||
procedure Q_MAXH_Free(Heap : PBinaryHeap);
|
||||
procedure maxh_Free(Heap : PBinaryHeap);
|
||||
|
||||
implementation
|
||||
|
||||
function Q_MAXH_New(ElementSize : uint32; InitialCapacity : uint32) : PBinaryHeap;
|
||||
function maxh_New(ElementSize : uint32; InitialCapacity : uint32) : PBinaryHeap;
|
||||
begin
|
||||
Q_MAXH_New := BH_New(ElementSize, InitialCapacity, false);
|
||||
maxh_New := BHeap_New(ElementSize, InitialCapacity, false);
|
||||
end;
|
||||
|
||||
procedure Q_MAXH_Insert(Heap : PBinaryHeap; Priority : uint32; Data : void);
|
||||
procedure maxh_Insert(Heap : PBinaryHeap; Priority : uint32; Data : void);
|
||||
begin
|
||||
BH_Insert(Heap, Priority, Data);
|
||||
BHeap_Insert(Heap, Priority, Data);
|
||||
end;
|
||||
|
||||
function Q_MAXH_ExtractMax(Heap : PBinaryHeap; Data : void) : boolean;
|
||||
function maxh_ExtractMax(Heap : PBinaryHeap; Data : void) : boolean;
|
||||
begin
|
||||
Q_MAXH_ExtractMax := BH_ExtractRoot(Heap, Data);
|
||||
maxh_ExtractMax := BHeap_ExtractRoot(Heap, Data);
|
||||
end;
|
||||
|
||||
function Q_MAXH_PeekMax(Heap : PBinaryHeap) : void;
|
||||
function maxh_PeekMax(Heap : PBinaryHeap) : void;
|
||||
begin
|
||||
Q_MAXH_PeekMax := BH_PeekRoot(Heap);
|
||||
maxh_PeekMax := BHeap_PeekRoot(Heap);
|
||||
end;
|
||||
|
||||
function Q_MAXH_Size(Heap : PBinaryHeap) : uint32;
|
||||
function maxh_Size(Heap : PBinaryHeap) : uint32;
|
||||
begin
|
||||
Q_MAXH_Size := Heap^.Count;
|
||||
maxh_Size := Heap^.Count;
|
||||
end;
|
||||
|
||||
function Q_MAXH_IsEmpty(Heap : PBinaryHeap) : boolean;
|
||||
function maxh_IsEmpty(Heap : PBinaryHeap) : boolean;
|
||||
begin
|
||||
Q_MAXH_IsEmpty := (Heap^.Count = 0);
|
||||
maxh_IsEmpty := (Heap^.Count = 0);
|
||||
end;
|
||||
|
||||
procedure Q_MAXH_Free(Heap : PBinaryHeap);
|
||||
procedure maxh_Free(Heap : PBinaryHeap);
|
||||
begin
|
||||
BH_Free(Heap);
|
||||
BHeap_Free(Heap);
|
||||
end;
|
||||
|
||||
end.
|
||||
@@ -13,20 +13,20 @@
|
||||
// limitations under the License.
|
||||
|
||||
{
|
||||
Queue Min-Heap - Lowest priority value extracted first.
|
||||
Min-Heap - Lowest priority value extracted first.
|
||||
|
||||
@author(Aaron Hance <ah@aaronhance.me>)
|
||||
}
|
||||
unit q_minh;
|
||||
unit minh;
|
||||
|
||||
interface
|
||||
|
||||
uses
|
||||
q_types,
|
||||
q_heap;
|
||||
dstypes,
|
||||
bheap;
|
||||
|
||||
{ ============================================================================ }
|
||||
{ Min-Heap — Q_MINH_* API }
|
||||
{ Min-Heap — minh_* API }
|
||||
{ ============================================================================ }
|
||||
|
||||
{**
|
||||
@@ -35,7 +35,7 @@ uses
|
||||
@param InitialCapacity Starting number of slots (will grow as needed).
|
||||
@returns Pointer to the new heap.
|
||||
**}
|
||||
function Q_MINH_New(ElementSize : uint32; InitialCapacity : uint32) : PBinaryHeap;
|
||||
function minh_New(ElementSize : uint32; InitialCapacity : uint32) : PBinaryHeap;
|
||||
|
||||
{**
|
||||
@abstract Inserts an element into the min-heap.
|
||||
@@ -43,7 +43,7 @@ uses
|
||||
@param Priority Priority value (lower = higher priority).
|
||||
@param Data Pointer to the element data to copy in.
|
||||
**}
|
||||
procedure Q_MINH_Insert(Heap : PBinaryHeap; Priority : uint32; Data : void);
|
||||
procedure minh_Insert(Heap : PBinaryHeap; Priority : uint32; Data : void);
|
||||
|
||||
{**
|
||||
@abstract Extracts the minimum-priority element from the heap.
|
||||
@@ -51,70 +51,70 @@ uses
|
||||
@param Data Pointer to a buffer that receives the extracted element.
|
||||
@returns True if an element was extracted, false if the heap was empty.
|
||||
**}
|
||||
function Q_MINH_ExtractMin(Heap : PBinaryHeap; Data : void) : boolean;
|
||||
function minh_ExtractMin(Heap : PBinaryHeap; Data : void) : boolean;
|
||||
|
||||
{**
|
||||
@abstract Peeks at the minimum-priority element without removing it.
|
||||
@param Heap Pointer to the heap.
|
||||
@returns Pointer to the element data, or nil if empty.
|
||||
**}
|
||||
function Q_MINH_PeekMin(Heap : PBinaryHeap) : void;
|
||||
function minh_PeekMin(Heap : PBinaryHeap) : void;
|
||||
|
||||
{**
|
||||
@abstract Returns the number of elements in the min-heap.
|
||||
@param Heap Pointer to the heap.
|
||||
@returns Element count.
|
||||
**}
|
||||
function Q_MINH_Size(Heap : PBinaryHeap) : uint32;
|
||||
function minh_Size(Heap : PBinaryHeap) : uint32;
|
||||
|
||||
{**
|
||||
@abstract Checks whether the min-heap is empty.
|
||||
@param Heap Pointer to the heap.
|
||||
@returns True if empty.
|
||||
**}
|
||||
function Q_MINH_IsEmpty(Heap : PBinaryHeap) : boolean;
|
||||
function minh_IsEmpty(Heap : PBinaryHeap) : boolean;
|
||||
|
||||
{**
|
||||
@abstract Frees the min-heap and all its elements.
|
||||
@param Heap Pointer to the heap.
|
||||
**}
|
||||
procedure Q_MINH_Free(Heap : PBinaryHeap);
|
||||
procedure minh_Free(Heap : PBinaryHeap);
|
||||
|
||||
implementation
|
||||
|
||||
function Q_MINH_New(ElementSize : uint32; InitialCapacity : uint32) : PBinaryHeap;
|
||||
function minh_New(ElementSize : uint32; InitialCapacity : uint32) : PBinaryHeap;
|
||||
begin
|
||||
Q_MINH_New := BH_New(ElementSize, InitialCapacity, true);
|
||||
minh_New := BHeap_New(ElementSize, InitialCapacity, true);
|
||||
end;
|
||||
|
||||
procedure Q_MINH_Insert(Heap : PBinaryHeap; Priority : uint32; Data : void);
|
||||
procedure minh_Insert(Heap : PBinaryHeap; Priority : uint32; Data : void);
|
||||
begin
|
||||
BH_Insert(Heap, Priority, Data);
|
||||
BHeap_Insert(Heap, Priority, Data);
|
||||
end;
|
||||
|
||||
function Q_MINH_ExtractMin(Heap : PBinaryHeap; Data : void) : boolean;
|
||||
function minh_ExtractMin(Heap : PBinaryHeap; Data : void) : boolean;
|
||||
begin
|
||||
Q_MINH_ExtractMin := BH_ExtractRoot(Heap, Data);
|
||||
minh_ExtractMin := BHeap_ExtractRoot(Heap, Data);
|
||||
end;
|
||||
|
||||
function Q_MINH_PeekMin(Heap : PBinaryHeap) : void;
|
||||
function minh_PeekMin(Heap : PBinaryHeap) : void;
|
||||
begin
|
||||
Q_MINH_PeekMin := BH_PeekRoot(Heap);
|
||||
minh_PeekMin := BHeap_PeekRoot(Heap);
|
||||
end;
|
||||
|
||||
function Q_MINH_Size(Heap : PBinaryHeap) : uint32;
|
||||
function minh_Size(Heap : PBinaryHeap) : uint32;
|
||||
begin
|
||||
Q_MINH_Size := Heap^.Count;
|
||||
minh_Size := Heap^.Count;
|
||||
end;
|
||||
|
||||
function Q_MINH_IsEmpty(Heap : PBinaryHeap) : boolean;
|
||||
function minh_IsEmpty(Heap : PBinaryHeap) : boolean;
|
||||
begin
|
||||
Q_MINH_IsEmpty := (Heap^.Count = 0);
|
||||
minh_IsEmpty := (Heap^.Count = 0);
|
||||
end;
|
||||
|
||||
procedure Q_MINH_Free(Heap : PBinaryHeap);
|
||||
procedure minh_Free(Heap : PBinaryHeap);
|
||||
begin
|
||||
BH_Free(Heap);
|
||||
BHeap_Free(Heap);
|
||||
end;
|
||||
|
||||
end.
|
||||
@@ -18,16 +18,16 @@
|
||||
|
||||
@author(Aaron Hance <ah@aaronhance.me>)
|
||||
}
|
||||
unit q_prio;
|
||||
unit prio;
|
||||
|
||||
interface
|
||||
|
||||
uses
|
||||
q_types,
|
||||
q_heap;
|
||||
bheap,
|
||||
dstypes;
|
||||
|
||||
{ ============================================================================ }
|
||||
{ Priority Queue — Q_PRIO_* API }
|
||||
{ Priority Queue — prio_* API }
|
||||
{ ============================================================================ }
|
||||
|
||||
{**
|
||||
@@ -36,7 +36,7 @@ uses
|
||||
@param InitialCapacity Starting number of slots.
|
||||
@returns Pointer to the new priority queue (a PBinaryHeap).
|
||||
**}
|
||||
function Q_PRIO_New(ElementSize : uint32; InitialCapacity : uint32) : PBinaryHeap;
|
||||
function prio_New(ElementSize : uint32; InitialCapacity : uint32) : PBinaryHeap;
|
||||
|
||||
{**
|
||||
@abstract Enqueues an element with a given priority.
|
||||
@@ -44,7 +44,7 @@ uses
|
||||
@param Priority Priority value (lower = dequeued first).
|
||||
@param Data Pointer to the element data to copy in.
|
||||
**}
|
||||
procedure Q_PRIO_Enqueue(Heap : PBinaryHeap; Priority : uint32; Data : void);
|
||||
procedure prio_Enqueue(Heap : PBinaryHeap; Priority : uint32; Data : void);
|
||||
|
||||
{**
|
||||
@abstract Dequeues the highest-priority (lowest value) element.
|
||||
@@ -52,70 +52,70 @@ uses
|
||||
@param Data Pointer to a buffer that receives the dequeued element.
|
||||
@returns True if an element was dequeued, false if empty.
|
||||
**}
|
||||
function Q_PRIO_Dequeue(Heap : PBinaryHeap; Data : void) : boolean;
|
||||
function prio_Dequeue(Heap : PBinaryHeap; Data : void) : boolean;
|
||||
|
||||
{**
|
||||
@abstract Peeks at the highest-priority element without removing it.
|
||||
@param Heap Pointer to the priority queue.
|
||||
@returns Pointer to the element data, or nil if empty.
|
||||
**}
|
||||
function Q_PRIO_Peek(Heap : PBinaryHeap) : void;
|
||||
function prio_Peek(Heap : PBinaryHeap) : void;
|
||||
|
||||
{**
|
||||
@abstract Returns the number of elements in the priority queue.
|
||||
@param Heap Pointer to the priority queue.
|
||||
@returns Element count.
|
||||
**}
|
||||
function Q_PRIO_Size(Heap : PBinaryHeap) : uint32;
|
||||
function prio_Size(Heap : PBinaryHeap) : uint32;
|
||||
|
||||
{**
|
||||
@abstract Checks whether the priority queue is empty.
|
||||
@param Heap Pointer to the priority queue.
|
||||
@returns True if empty.
|
||||
**}
|
||||
function Q_PRIO_IsEmpty(Heap : PBinaryHeap) : boolean;
|
||||
function prio_IsEmpty(Heap : PBinaryHeap) : boolean;
|
||||
|
||||
{**
|
||||
@abstract Frees the priority queue and all its elements.
|
||||
@param Heap Pointer to the priority queue.
|
||||
**}
|
||||
procedure Q_PRIO_Free(Heap : PBinaryHeap);
|
||||
procedure prio_Free(Heap : PBinaryHeap);
|
||||
|
||||
implementation
|
||||
|
||||
function Q_PRIO_New(ElementSize : uint32; InitialCapacity : uint32) : PBinaryHeap;
|
||||
function prio_New(ElementSize : uint32; InitialCapacity : uint32) : PBinaryHeap;
|
||||
begin
|
||||
Q_PRIO_New := BH_New(ElementSize, InitialCapacity, true);
|
||||
prio_New := BHeap_New(ElementSize, InitialCapacity, true);
|
||||
end;
|
||||
|
||||
procedure Q_PRIO_Enqueue(Heap : PBinaryHeap; Priority : uint32; Data : void);
|
||||
procedure prio_Enqueue(Heap : PBinaryHeap; Priority : uint32; Data : void);
|
||||
begin
|
||||
BH_Insert(Heap, Priority, Data);
|
||||
BHeap_Insert(Heap, Priority, Data);
|
||||
end;
|
||||
|
||||
function Q_PRIO_Dequeue(Heap : PBinaryHeap; Data : void) : boolean;
|
||||
function prio_Dequeue(Heap : PBinaryHeap; Data : void) : boolean;
|
||||
begin
|
||||
Q_PRIO_Dequeue := BH_ExtractRoot(Heap, Data);
|
||||
prio_Dequeue := BHeap_ExtractRoot(Heap, Data);
|
||||
end;
|
||||
|
||||
function Q_PRIO_Peek(Heap : PBinaryHeap) : void;
|
||||
function prio_Peek(Heap : PBinaryHeap) : void;
|
||||
begin
|
||||
Q_PRIO_Peek := BH_PeekRoot(Heap);
|
||||
prio_Peek := BHeap_PeekRoot(Heap);
|
||||
end;
|
||||
|
||||
function Q_PRIO_Size(Heap : PBinaryHeap) : uint32;
|
||||
function prio_Size(Heap : PBinaryHeap) : uint32;
|
||||
begin
|
||||
Q_PRIO_Size := Heap^.Count;
|
||||
prio_Size := Heap^.Count;
|
||||
end;
|
||||
|
||||
function Q_PRIO_IsEmpty(Heap : PBinaryHeap) : boolean;
|
||||
function prio_IsEmpty(Heap : PBinaryHeap) : boolean;
|
||||
begin
|
||||
Q_PRIO_IsEmpty := (Heap^.Count = 0);
|
||||
prio_IsEmpty := (Heap^.Count = 0);
|
||||
end;
|
||||
|
||||
procedure Q_PRIO_Free(Heap : PBinaryHeap);
|
||||
procedure prio_Free(Heap : PBinaryHeap);
|
||||
begin
|
||||
BH_Free(Heap);
|
||||
BHeap_Free(Heap);
|
||||
end;
|
||||
|
||||
end.
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user