This file documents the Linked List implentation in ztypes.
Linked List in ztypes is a Doubly Linked List, and is broken down into parts.
- Defination of the Linked List Structure itself
- Defination of the Handler of the Linked List
This have numerous benifits and sadly a bit of a overhead.
Linked List and its functions are completly implentated as macros. So they are as type generic as they come.
In order to Create a new Linked List, we first have to create a 'Linked List Structure'. We do that by using the z__Link keyword.
Okay so whats what?
There are Three main parameters that can be given to z__Link, one of which is optional.
-
Tag Name: The name to identify that particular Linked List Structure. Similar to struct names or typedefs.
Tag Names are only there to identify the Linked List and therefore can be used again as indentifies, though they can induce confusion.
-
Main Data Type: The Main Data Type Used For Storing data. Though it's not the only way to-do so.
These two are the mandatory Fields.
- Optional Members: This the Third though not limited to Field.
The Third Field is a Vardic Argument and can be used to insert more members into the Linked List Structure.
Note: As Its Directly Inserting the Members into Linked List Structure. We have use semi-colon
;to seperate the optional members.
In both previous we used integers as the main datatype but truely they can be of any type. Here some examples...
We are not not going to interact with Linked List Structure Directly, even though we can. We will use a Handler for that.
A Handler will let us access our Linked List with ease and safety.
Now, in-order to create a new Handler we use z__LList keyword.
A new linked list is created!
Note: Like
z__Link's Third argument,z__LList's Second argument is for creating optional members inside the Linked List Handler's Structure. In this case matrices.
The Handler by default consist of three members.
Whilst more members can be added to the handlers. Just like z__Link.
Even though we have created a new variable as matrices we still have not initialized it; Allocated memory or inserted a value.
So to do that we use z__LList_new.
This will neatly allocates and initializes the first instance of the Linked List. After which we will never call this function on the same variable again, unless it's contents has been deleted or else we have a memory leak issue.
After Initialization values can be inserted both at the head or at the tail.
Also Remember
Insertion at head can be easily done by z__LList_pushHead.
Similarly we can insert at the tail to.
Similar to insertion, deletion can happen on both head or tail.
Cursor is a main member of the Linked List Handler. It's value is not fixed or allocated but is a pointer to data in a Linked List similar to Head and Tail but unlike them cursor is not bound to be at a fixed/particular place pointing to a particular data, it can be moved freely within the bounds of the Linked List.
So in Essence
With this we have more control over our Linked list as it allows us to manipulate data from anywhere in the list, even insertion and deletion in-between the items.
At default Cursor points to initialized value of the Linked List (or NULL if Linked List is uninitialized).
To iterate over the Linked List we have:
- z__LList_inext(zls, n) : Iterates towards next pointer.
- z__LList_iprev(zls, n) : Iterates towards previous pointer.
Which are pretty self-elxplanatory.
Incomeplete.
Incomeplete.