||5 years ago|
|LinkedList1.pl||5 years ago|
|LinkedList2.pl||5 years ago|
|LinkedList3.pl||5 years ago|
|Node.pl||5 years ago|
|README.md||5 years ago|
Perl Data Structures
Linked List in Perl (ha ha)
Implementing a linked list in Perl is a pretty low level operation, and because Perl doesn't deal much at all with objects in the same sense of C++, Java, or Python, you can't really deal with pointers to objects in memory. And besides, Perl has many data structures built in, particularly queues and arrays, which are flexible enough to obviate a need for LinkedLists.
Bioinformatics might need speedy data structures if they're parsing DNA data with Perl, but... there are probably bigger issues to worry about there, around reproducability.
Linked List Approaches in Perl: 3 Abominations
There are 3 ways to implement linked lists in Perl, all defeating the real purpose of a linked list, which is to implement a more efficient data structure by storing data in a sequences of references to memory. Sure, a linked list might be handy for a particular operation or a particular algorithm, but generally the purpose of a linked list is to provide a more efficient data structure.
Each of the three approaches to a linked list in Perl utilize arrays, which are contiguous blocks of memory and defeat the performance purpose of linked lists.
One method is to use reference "pointers". This stores a queue, or array, or data (in this case, Strings), each associated with a second value, which is "Null". It then stores another array called links, which contain the values of each element's links. In other words, we're just mappping elements of an array in a particular order. At that point, why not just store the items in an array, in the order we wanted in the first place? It might save some time if we're reshuffling the array, ensures we don't have to destroy/create data in memory if we're changing links/relationships in table.
Another method is to utilize a hash map. This is a key-value store, but the values also contain the name of the next key that they point to, with the last item in the list havign a value ending in :Nulls
The third is also an abomination. It stores each node in a linked list as a two-element array, but then each node is stored in an array. The first item of each node-array is the data, and the second item of each node-array is an integer indicating the index of the next node.
This implements the three abominations mentioned above..
This is a confusing but potentially interesting "node class" type of script for Perl.