Provides a base linked list class from which to derive all other types of linked lists (doubly linked lists, stacks, and queues).
All structures will have the advantage of being persistent, easily extendable, and assignment compatible. However, the TGCustomLinkedList is slower than a TList because it creates objects for every node.
Note
|
This class uses TPersistents instead of records for the nodes because of expandability, readability, and power. The performance hit is small (<3%).
|
Namespace: GLists
Delphi
|
type
TGCustomLinkedList = class( TPersistent )
end;
|
|
Name
|
Description
|
|
Count
|
Returns the number of nodes in the linked list.
|
|
Empty
|
Returns true if the linked list is empty.
|
|
EndOfList
|
Returns true when the last accessed node has been returned.
|
|
Head
|
Specifies the first node in the linked list.
|
|
Item[Integer]
|
Returns the Item property for the node at the specified position in the list.
|
|
LastAccessedIndex
|
Caches the index of the last node accessed. This helps speeds up subsequent calls to Item or Node properties.
|
|
LastAccessedNode
|
Caches the last node accessed. This helps speeds up subsequent calls to Item or Node properties.
|
|
Next
|
Moves the internal Node to the next node in the linked list
|
|
Node[Integer]
|
Returns the the node at the specified position in the list.
|
|
OnChange
|
Occurs when a node is added or removed from the linked list.
Write an OnChange event to respond to changes in the linked list.
|
|
Tail
|
Specifies the last node in the linked list.
|
|
UpdateCount
|
Represents property UpdateCount.
|
Top
|
|
Name
|
Description
|
|
Add(TObject)
|
Creates a new node in the linked list and sets its Item property to the input object.
Add returns the node created.
|
|
AddLinkedList(TGCustomLinkedList)
|
Appends the input linked list to the end of the current linked list.
|
|
AddNode(TSQNode)
|
Adds the input node to the end of the linked list.
|
|
Assign(TPersistent)
|
Represents method Assign(TPersistent).
|
|
BeginUpdate
|
Defers OnChange events until EndUpdate is called.
BeginUpdate and EndUpdate work in tandem to defer change events to speed processing. Use BeginUpdate to defer change events until an equal number of EndUpdate calls occurs.
|
|
Change
|
Represents method Change.
|
|
Clear
|
Empties the linked list
Note
|
Items associated with nodes are not freed.
|
|
|
Delete(TSQNode)
|
Deletes the specified node from the linked list.
|
|
EndUpdate
|
Reenables OnChange events after BeginUpdate has been called.
BeginUpdate and EndUpdate work in tandem to defer change events to speed processing. Use BeginUpdate to defer change events until an equal number of EndUpdate calls occurs.
|
|
Find(TSQNode)
|
Find returns the Node before ANode i.e., whose Next field points to
ANode. If Find returns the Node itself then Node is the Head node
|
|
FindItem(TObject)
|
FindItem returns the node whose Item property equals the input object.
If the item cannot be found, the method returns nil.
|
|
GetEnumerator
|
Returns an enumerator for iterating over the linked list.
|
|
GetNode(Integer)
|
Represents method GetNode(Integer).
|
|
IndexOfItem(TObject)
|
Returns the position of the node (0 = head) whose Item property equals the input object.
If the item cannot be found, the method returns -1.
|
|
Insert(TSQNode,TSQNode)
|
Inserts the input ANode into the linked list. The node is inserted before the BeforeNode (i.e., ANode.Next := BeforeNode).
|
|
NewNode
|
Creates a new node. The new node is not added to the linked list.
|
|
Reset
|
Resets the iteration node to the head of the list.
|
|
SetNode(Integer,TSQNode)
|
Represents method SetNode(Integer,TSQNode).
|
Top
|
To iterate through a list is easy:
Delphi
|
var
aNode: TSQNode;
begin
aNode := List.Head;
while aNode <> nil do
begin
aNode.Item := MyObject;
aNode := aNode.Next;
end;
end;
|
The list also provides accessor properties to do this for you. The following example also iterates through the list:
Delphi
List.Reset; // go to head of list
while not List.EndOfList do
begin
List.Item := MyObject;
List.Next;
end;
The TGCustomLinkedList also supports the for-in construct of Delphi:
Note
|
for aNode in List do
aNode.Item := MyObject
|