fix lists docs regression (#16981)
This commit is contained in:
parent
aac8f67573
commit
41d32c3ea3
1 changed files with 14 additions and 21 deletions
|
|
@ -13,15 +13,11 @@
|
||||||
## * `singly linked rings <#SinglyLinkedRing>`_ (circular lists)
|
## * `singly linked rings <#SinglyLinkedRing>`_ (circular lists)
|
||||||
## * `doubly linked rings <#DoublyLinkedRing>`_ (circular lists)
|
## * `doubly linked rings <#DoublyLinkedRing>`_ (circular lists)
|
||||||
##
|
##
|
||||||
##
|
## # Basic Usage
|
||||||
## Basic Usage
|
|
||||||
## ===========
|
|
||||||
##
|
|
||||||
## Because it makes no sense to do otherwise, the `next` and `prev` pointers
|
## Because it makes no sense to do otherwise, the `next` and `prev` pointers
|
||||||
## are not hidden from you and can be manipulated directly for efficiency.
|
## are not hidden from you and can be manipulated directly for efficiency.
|
||||||
##
|
|
||||||
## Lists
|
## ## Lists
|
||||||
## -----
|
|
||||||
runnableExamples:
|
runnableExamples:
|
||||||
var
|
var
|
||||||
l = initDoublyLinkedList[int]()
|
l = initDoublyLinkedList[int]()
|
||||||
|
|
@ -40,8 +36,7 @@ runnableExamples:
|
||||||
assert c.prev == nil
|
assert c.prev == nil
|
||||||
assert b.next == nil
|
assert b.next == nil
|
||||||
|
|
||||||
## Rings
|
## ## Rings
|
||||||
## -----
|
|
||||||
runnableExamples:
|
runnableExamples:
|
||||||
var
|
var
|
||||||
l = initSinglyLinkedRing[int]()
|
l = initSinglyLinkedRing[int]()
|
||||||
|
|
@ -59,9 +54,7 @@ runnableExamples:
|
||||||
assert b.next == c
|
assert b.next == c
|
||||||
assert c.next.next.next == c
|
assert c.next.next.next == c
|
||||||
|
|
||||||
## See also
|
## # See also
|
||||||
## ========
|
|
||||||
##
|
|
||||||
## * `deques module <deques.html>`_ for double-ended queues
|
## * `deques module <deques.html>`_ for double-ended queues
|
||||||
## * `sharedlist module <sharedlist.html>`_ for shared singly-linked lists
|
## * `sharedlist module <sharedlist.html>`_ for shared singly-linked lists
|
||||||
|
|
||||||
|
|
@ -231,7 +224,7 @@ iterator items*[T](L: SomeLinkedRing[T]): T =
|
||||||
from std/sugar import collect
|
from std/sugar import collect
|
||||||
from std/sequtils import toSeq
|
from std/sequtils import toSeq
|
||||||
let a = collect(initSinglyLinkedRing):
|
let a = collect(initSinglyLinkedRing):
|
||||||
for i in 1..3: 10*i
|
for i in 1 .. 3: 10 * i
|
||||||
doAssert toSeq(items(a)) == toSeq(a)
|
doAssert toSeq(items(a)) == toSeq(a)
|
||||||
doAssert toSeq(a) == @[10, 20, 30]
|
doAssert toSeq(a) == @[10, 20, 30]
|
||||||
itemsRingImpl()
|
itemsRingImpl()
|
||||||
|
|
@ -245,10 +238,10 @@ iterator mitems*[T](L: var SomeLinkedList[T]): var T =
|
||||||
runnableExamples:
|
runnableExamples:
|
||||||
var a = initSinglyLinkedList[int]()
|
var a = initSinglyLinkedList[int]()
|
||||||
for i in 1 .. 5:
|
for i in 1 .. 5:
|
||||||
a.add(10*i)
|
a.add(10 * i)
|
||||||
assert $a == "[10, 20, 30, 40, 50]"
|
assert $a == "[10, 20, 30, 40, 50]"
|
||||||
for x in mitems(a):
|
for x in mitems(a):
|
||||||
x = 5*x - 1
|
x = 5 * x - 1
|
||||||
assert $a == "[49, 99, 149, 199, 249]"
|
assert $a == "[49, 99, 149, 199, 249]"
|
||||||
itemsListImpl()
|
itemsListImpl()
|
||||||
|
|
||||||
|
|
@ -261,10 +254,10 @@ iterator mitems*[T](L: var SomeLinkedRing[T]): var T =
|
||||||
runnableExamples:
|
runnableExamples:
|
||||||
var a = initSinglyLinkedRing[int]()
|
var a = initSinglyLinkedRing[int]()
|
||||||
for i in 1 .. 5:
|
for i in 1 .. 5:
|
||||||
a.add(10*i)
|
a.add(10 * i)
|
||||||
assert $a == "[10, 20, 30, 40, 50]"
|
assert $a == "[10, 20, 30, 40, 50]"
|
||||||
for x in mitems(a):
|
for x in mitems(a):
|
||||||
x = 5*x - 1
|
x = 5 * x - 1
|
||||||
assert $a == "[49, 99, 149, 199, 249]"
|
assert $a == "[49, 99, 149, 199, 249]"
|
||||||
itemsRingImpl()
|
itemsRingImpl()
|
||||||
|
|
||||||
|
|
@ -278,13 +271,13 @@ iterator nodes*[T](L: SomeLinkedList[T]): SomeLinkedNode[T] =
|
||||||
runnableExamples:
|
runnableExamples:
|
||||||
var a = initDoublyLinkedList[int]()
|
var a = initDoublyLinkedList[int]()
|
||||||
for i in 1 .. 5:
|
for i in 1 .. 5:
|
||||||
a.add(10*i)
|
a.add(10 * i)
|
||||||
assert $a == "[10, 20, 30, 40, 50]"
|
assert $a == "[10, 20, 30, 40, 50]"
|
||||||
for x in nodes(a):
|
for x in nodes(a):
|
||||||
if x.value == 30:
|
if x.value == 30:
|
||||||
a.remove(x)
|
a.remove(x)
|
||||||
else:
|
else:
|
||||||
x.value = 5*x.value - 1
|
x.value = 5 * x.value - 1
|
||||||
assert $a == "[49, 99, 199, 249]"
|
assert $a == "[49, 99, 199, 249]"
|
||||||
|
|
||||||
var it = L.head
|
var it = L.head
|
||||||
|
|
@ -303,13 +296,13 @@ iterator nodes*[T](L: SomeLinkedRing[T]): SomeLinkedNode[T] =
|
||||||
runnableExamples:
|
runnableExamples:
|
||||||
var a = initDoublyLinkedRing[int]()
|
var a = initDoublyLinkedRing[int]()
|
||||||
for i in 1 .. 5:
|
for i in 1 .. 5:
|
||||||
a.add(10*i)
|
a.add(10 * i)
|
||||||
assert $a == "[10, 20, 30, 40, 50]"
|
assert $a == "[10, 20, 30, 40, 50]"
|
||||||
for x in nodes(a):
|
for x in nodes(a):
|
||||||
if x.value == 30:
|
if x.value == 30:
|
||||||
a.remove(x)
|
a.remove(x)
|
||||||
else:
|
else:
|
||||||
x.value = 5*x.value - 1
|
x.value = 5 * x.value - 1
|
||||||
assert $a == "[49, 99, 199, 249]"
|
assert $a == "[49, 99, 199, 249]"
|
||||||
|
|
||||||
var it = L.head
|
var it = L.head
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue