Implementation of singly and doubly linked lists. Because it makes no sense to do so, the 'next' and 'prev' pointers are not hidden from you and can be manipulated directly for efficiency.
DoublyLinkedNodeObj[T] = object next*, prev*: ref DoublyLinkedNodeObj[T] value*: T
DoublyLinkedNode[T] = ref DoublyLinkedNodeObj[T]
SinglyLinkedNodeObj[T] = object next*: ref SinglyLinkedNodeObj[T] value*: T
SinglyLinkedNode[T] = ref SinglyLinkedNodeObj[T]
SinglyLinkedList[T] = object head*, tail*: SinglyLinkedNode[T]
DoublyLinkedList[T] = object head*, tail*: DoublyLinkedNode[T]
SinglyLinkedRing[T] = object head*, tail*: SinglyLinkedNode[T]
DoublyLinkedRing[T] = object head*: DoublyLinkedNode[T]
SomeLinkedList[T] = SinglyLinkedList[T] | DoublyLinkedList[T]
SomeLinkedRing[T] = SinglyLinkedRing[T] | DoublyLinkedRing[T]
SomeLinkedCollection[T] = SomeLinkedList[T] | SomeLinkedRing[T]
SomeLinkedNode[T] = SinglyLinkedNode[T] | DoublyLinkedNode[T]
proc initSinglyLinkedList[T](): SinglyLinkedList[T]
proc initDoublyLinkedList[T](): DoublyLinkedList[T]
proc initSinglyLinkedRing[T](): SinglyLinkedRing[T]
proc initDoublyLinkedRing[T](): DoublyLinkedRing[T]
proc newDoublyLinkedNode[T](value: T): DoublyLinkedNode[T]
proc newSinglyLinkedNode[T](value: T): SinglyLinkedNode[T]
proc `$`[T](L: SomeLinkedCollection[T]): string
proc find[T](L: SomeLinkedCollection[T]; value: T): SomeLinkedNode[T]
proc contains[T](L: SomeLinkedCollection[T]; value: T): bool {...}{.inline.}
proc prepend[T](L: var SinglyLinkedList[T]; n: SinglyLinkedNode[T]) {...}{.inline.}
proc prepend[T](L: var SinglyLinkedList[T]; value: T) {...}{.inline.}
proc append[T](L: var DoublyLinkedList[T]; n: DoublyLinkedNode[T])
proc append[T](L: var DoublyLinkedList[T]; value: T)
proc prepend[T](L: var DoublyLinkedList[T]; n: DoublyLinkedNode[T])
proc prepend[T](L: var DoublyLinkedList[T]; value: T)
proc remove[T](L: var DoublyLinkedList[T]; n: DoublyLinkedNode[T])
proc append[T](L: var SinglyLinkedRing[T]; n: SinglyLinkedNode[T])
proc append[T](L: var SinglyLinkedRing[T]; value: T)
proc prepend[T](L: var SinglyLinkedRing[T]; n: SinglyLinkedNode[T])
proc prepend[T](L: var SinglyLinkedRing[T]; value: T)
proc append[T](L: var DoublyLinkedRing[T]; n: DoublyLinkedNode[T])
proc append[T](L: var DoublyLinkedRing[T]; value: T)
proc prepend[T](L: var DoublyLinkedRing[T]; n: DoublyLinkedNode[T])
proc prepend[T](L: var DoublyLinkedRing[T]; value: T)
proc remove[T](L: var DoublyLinkedRing[T]; n: DoublyLinkedNode[T])
iterator items[T](L: SomeLinkedList[T]): T
iterator items[T](L: SomeLinkedRing[T]): T
iterator mitems[T](L: var SomeLinkedList[T]): var T
iterator mitems[T](L: var SomeLinkedRing[T]): var T
iterator nodes[T](L: SomeLinkedList[T]): SomeLinkedNode[T]
iterator nodes[T](L: SomeLinkedRing[T]): SomeLinkedNode[T]
© 2006–2018 Andreas Rumpf
Licensed under the MIT License.
https://nim-lang.org/docs/lists.html