This time I want to share some(possibly dumb) ways to implement doubly circular linked lists, to incite you to think about that data structure in RGSS3.
Using Hash Directly
1. Building the list:
head_node_id, tail_node_id and cur_node_id(the id of the currently pointed node in the list) should always be stored as long as the list exists to make using the list easier.
2. Accessing the current node data:
3. Going to the next i node:
4. Going to the previous i node:
5. Adding a new node as the next node of the current node:
6. Removing the next node of the current node:
7. Adding a new head node:
8. Adding a new tail node:
9. Removing the head node:
10. Removing the tail node:
11. Shifting the head and tail node to their next i node:
12. Shifting the head and tail node to their previous i node:
P.S.: Using dcll.keys to do the above would likely lead to much, much more performant solutions XD
Using Variable Pointers
DoubleX RMVXA Variable Pointers Tutorial
It's incredibly alien, complicated and idiotic, making it an excellent counter example of implementing doubly circular linked lists lol
What are your opinions on doubly circular linked lists? Do you think they're useful in RGSS3 scripts? How would you implement them? Would you implement some other data structures using them?
P.S.S.: Normally, each node in a doubly circular linked list has a data, next and previous pointer(storing the memory address of another variable) pointing to the next and previous node. If that pointer behavior needs to be replicated as well, both the aforementioned ways will fail. Maybe using Fiddle:😛ointer can do the job(I wonder if RGSS3 supports that though).
Using Hash Directly
1. Building the list:
dcll = { head_node_id = [head_node_data, 2nd_node_id, tail_node_id], 2nd_node_id = [2nd_node_data, 3rd_node_id, 1st_node_id], 3rd_node_id = [3rd_node_data, 4th_node_id, 2nd_node_id], ... ith_node_id = [ith_node_data, i-1th_node_id, i+1th_node_id], ... tail_node_id = [tail_node_data, head_node_id, n-1th_node_id]}
2. Accessing the current node data:
dcll[cur_node_id][0]
i.times { cur_node_id = dcll[cur_node_id][1] }
i.times { cur_node_id = dcll[cur_node_id][2] }
next_node_id = dcll[cur_node_id][1]dcll[new_node_id] = [new_node_data, next_node_id, cur_node_id]dcll[cur_node_id][1] = dcll[next_node_id][2] = new_node_id
old_node_id = dcll[cur_node_id][1]next_node_id = dcll[old_node_id][1]dcll.delete(old_node_id)dcll[cur_node_id][1] = next_node_iddcll[next_node_id][2] = cur_node_id
dcll[new_head_node_id] = [new_head_node_data, head_node_id, tail_node_id]dcll[tail_node_id][1] = dcll[head_node_id][2] = new_head_node_idhead_node_id = new_head_node_id
dcll[new_tail_node_id] = [new_tail_node_data, head_node_id, tail_node_id]dcll[tail_node_id][1] = dcll[head_node_id][2] = new_tail_node_idtail_node_id = new_tail_node_id
new_head_node_id = dcll[head_node_id][1]dcll.delete(head_node_id)head_node_id = new_head_node_iddcll[tail_node_id][1] = head_node_iddcll[head_node_id][2] = tail_node_id
new_tail_node_id = dcll[tail_node_id][2]dcll.delete(tail_node_id)tail_node_id = new_tail_node_iddcll[tail_node_id][1] = head_node_iddcll[head_node_id][2] = tail_node_id
i.times { head_node_id = dcll[head_node_id][1] }tail_node_id = dcll[head_node_id][2]
i.times { head_node_id = dcll[head_node_id][2] }tail_node_id = dcll[head_node_id][2]
Using Variable Pointers
DoubleX RMVXA Variable Pointers Tutorial
It's incredibly alien, complicated and idiotic, making it an excellent counter example of implementing doubly circular linked lists lol
What are your opinions on doubly circular linked lists? Do you think they're useful in RGSS3 scripts? How would you implement them? Would you implement some other data structures using them?
P.S.S.: Normally, each node in a doubly circular linked list has a data, next and previous pointer(storing the memory address of another variable) pointing to the next and previous node. If that pointer behavior needs to be replicated as well, both the aforementioned ways will fail. Maybe using Fiddle:😛ointer can do the job(I wonder if RGSS3 supports that though).