Removes unused datastructures (#34292)

This commit is contained in:
Jordan Brown
2018-01-12 10:57:32 -05:00
committed by ShizCalev
parent 28436f36b5
commit fbae6d597d
6 changed files with 40 additions and 373 deletions

View File

@@ -1,191 +0,0 @@
//Ok so it's technically a double linked list, bite me.
/datum/linked_list
var/datum/linked_node/head
var/datum/linked_node/tail
var/node_amt = 0
/datum/linked_node
var/value = null
var/datum/linked_list/linked_list = null
var/datum/linked_node/next_node = null
var/datum/linked_node/previous_node = null
/datum/linked_list/proc/IsEmpty()
. = (node_amt <= 0)
//Add a linked_node (or value, creating a linked_node) at position
//the added node BECOMES the position-th element,
//eg: add("Test",5), the 5th node is now "Test", the previous 5th moves up to become the 6th
/datum/linked_list/proc/Add(node, position)
var/datum/linked_node/adding
if(istype(node, /datum/linked_node))
adding = node
else
adding = new()
adding.value = node
if(!adding.linked_list || (adding.linked_list && (adding.linked_list != src)))
node_amt++
adding.linked_list = src
if(position && position < node_amt)
//Replacing head
if(position == 1)
if(head)
head.previous_node = adding
adding.next_node = head
head = adding
//Replacing any middle node
else
var/location = 0
var/datum/linked_node/at
while((location != position) && (location <= node_amt))
if(at)
if(at.next_node)
at = at.next_node
else
break
else
at = head
location++
//Push at up and assume it's place as the position-th element
if(at && at.previous_node)
at.previous_node.next_node = adding
adding.previous_node = at.previous_node
at.previous_node = adding
adding.next_node = at
return
//Replacing tail
if(tail)
tail.next_node = adding
adding.previous_node = tail
if(!tail.previous_node)
head = tail
tail = adding
//Remove a linked_node or the linked_node of a value
//If you specify a value the FIRST ONE is removed
/datum/linked_list/proc/Remove(node)
var/datum/linked_node/removing
if(istype(node, /datum/linked_node))
removing = node
else
//optimise removing head and tail, no point looping for them, especially the tail
if(removing == head)
removing = head
else if(removing == tail)
removing = tail
else
var/location = 1
var/current_value = null
var/datum/linked_node/at = null
while((current_value != node) && (location <= node_amt))
if(at)
if(at.next_node)
at = at.next_node
else
at = head
location++
if(at)
current_value = at.value
if(current_value == node)
removing = at
break
//Adjust pointers of where removing -was- in the chain.
if(removing)
if(removing.previous_node)
if(removing == tail)
tail = removing.previous_node
if(removing.next_node)
if(removing == head)
head = removing.next_node
removing.next_node.previous_node = removing.previous_node
removing.previous_node.next_node = removing.next_node
else
removing.previous_node.next_node = null
else
if(removing.next_node)
if(removing == head)
head = removing.next_node
removing.next_node.previous_node = null
//if this is still true at this point, there's no more nodes to replace them with
if(removing == head)
head = null
if(removing == tail)
tail = null
removing.next_node = null
removing.previous_node = null
if(removing.linked_list == src)
node_amt--
removing.linked_list = null
return removing
return 0
//Removes and deletes a node or value
/datum/linked_list/proc/RemoveDelete(node)
var/datum/linked_node/dead = Remove(node)
if(dead)
qdel(dead)
return 1
return 0
//Empty the linked_list, deleting all nodes
/datum/linked_list/proc/Empty()
var/datum/linked_node/n = head
while(n)
var/next = n.next_node
Remove(n)
qdel(n)
n = next
node_amt = 0
//Some debugging tools
/datum/linked_list/proc/CheckNodeLinks()
var/datum/linked_node/n = head
while(n)
. = "|[n.value]|"
if(n.previous_node)
. = "[n.previous_node.value]<-" + .
if(n.next_node)
. += "->[n.next_node.value]"
n = n.next_node
. += "<BR>"
/datum/linked_list/proc/DrawNodeLinks()
. = "|<-"
var/datum/linked_node/n = head
while(n)
if(n.previous_node)
. += "<-"
. += "[n.value]"
if(n.next_node)
. += "->"
n = n.next_node
. += "->|"
/datum/linked_list/proc/ToList()
. = list()
var/datum/linked_node/n = head
while(n)
. += n
n = n.next_node

View File

@@ -1,83 +0,0 @@
//////////////////////
//PriorityQueue object
//////////////////////
//an ordered list, using the cmp proc to weight the list elements
/PriorityQueue
var/list/L //the actual queue
var/cmp //the weight function used to order the queue
/PriorityQueue/New(compare)
L = new()
cmp = compare
/PriorityQueue/proc/IsEmpty()
return !L.len
//return the index the element should be in the priority queue using dichotomic search
/PriorityQueue/proc/FindElementIndex(atom/A)
var/i = 1
var/j = L.len
var/mid
while(i < j)
mid = round((i+j)/2)
if(call(cmp)(L[mid],A) < 0)
i = mid + 1
else
j = mid
if(i == 1 || i == L.len) //edge cases
return (call(cmp)(L[i],A) > 0) ? i : i+1
else
return i
//add an element in the list,
//immediatly ordering it to its position using dichotomic search
/PriorityQueue/proc/Enqueue(atom/A)
if(!L.len)
L.Add(A)
return
L.Insert(FindElementIndex(A),A)
//removes and returns the first element in the queue
/PriorityQueue/proc/Dequeue()
if(!L.len)
return 0
. = L[1]
Remove(.)
//removes an element
/PriorityQueue/proc/Remove(atom/A)
return L.Remove(A)
//returns a copy of the elements list
/PriorityQueue/proc/List()
. = L.Copy()
//return the position of an element or 0 if not found
/PriorityQueue/proc/Seek(atom/A)
. = L.Find(A)
//return the element at the i_th position
/PriorityQueue/proc/Get(i)
if(i > L.len || i < 1)
return 0
return L[i]
//replace the passed element at it's right position using the cmp proc
/PriorityQueue/proc/ReSort(atom/A)
var/i = Seek(A)
if(i == 0)
return
while(i < L.len && call(cmp)(L[i],L[i+1]) > 0)
L.Swap(i,i+1)
i++
while(i > 1 && call(cmp)(L[i],L[i-1]) <= 0) //last inserted element being first in case of ties (optimization)
L.Swap(i,i-1)
i--

View File

@@ -1,56 +0,0 @@
/datum/stack
var/list/stack = list()
var/max_elements = 0
/datum/stack/New(list/elements,max)
..()
if(elements)
stack = elements.Copy()
if(max)
max_elements = max
/datum/stack/proc/Pop()
if(is_empty())
return null
. = stack[stack.len]
stack.Cut(stack.len,0)
/datum/stack/proc/Push(element)
if(max_elements && (stack.len+1 > max_elements))
return null
stack += element
/datum/stack/proc/Top()
if(is_empty())
return null
. = stack[stack.len]
/datum/stack/proc/is_empty()
. = stack.len ? 0 : 1
//Rotate entire stack left with the leftmost looping around to the right
/datum/stack/proc/RotateLeft()
if(is_empty())
return 0
. = stack[1]
stack.Cut(1,2)
Push(.)
//Rotate entire stack to the right with the rightmost looping around to the left
/datum/stack/proc/RotateRight()
if(is_empty())
return 0
. = stack[stack.len]
stack.Cut(stack.len,0)
stack.Insert(1,.)
/datum/stack/proc/Copy()
var/datum/stack/S=new()
S.stack = stack.Copy()
S.max_elements = max_elements
return S
/datum/stack/proc/Clear()
stack.Cut()

View File

@@ -16,11 +16,7 @@
#include "_maps\basemap.dm"
#include "code\_compile_options.dm"
#include "code\world.dm"
#include "code\__DATASTRUCTURES\globals.dm"
#include "code\__DATASTRUCTURES\heap.dm"
#include "code\__DATASTRUCTURES\linked_lists.dm"
#include "code\__DATASTRUCTURES\priority_queue.dm"
#include "code\__DATASTRUCTURES\stacks.dm"
#include "code\__DEFINES\_globals.dm"
#include "code\__DEFINES\_tick.dm"
#include "code\__DEFINES\access.dm"
#include "code\__DEFINES\admin.dm"
@@ -44,6 +40,7 @@
#include "code\__DEFINES\flags.dm"
#include "code\__DEFINES\food.dm"
#include "code\__DEFINES\forensics.dm"
#include "code\__HELPERS\heap.dm"
#include "code\__DEFINES\hud.dm"
#include "code\__DEFINES\integrated_electronics.dm"
#include "code\__DEFINES\inventory.dm"