summary refs log tree commit diff stats
path: root/lib/pure/collections
diff options
context:
space:
mode:
authorEric N. Vander Weele <ericvw@gmail.com>2023-12-24 09:21:22 -0500
committerGitHub <noreply@github.com>2023-12-24 15:21:22 +0100
commit6fee2240cd327fbe65548eaed9ca21355a1a24b5 (patch)
tree72f4f817be1e70030f370350bc1a3af85ce2e70a /lib/pure/collections
parentc0acf3ce286f92d41e6b280ba9a1b729019bae12 (diff)
downloadNim-6fee2240cd327fbe65548eaed9ca21355a1a24b5.tar.gz
Add `toSinglyLinkedRing` and `toDoublyLinkedRing` to `std/lists` (#22952)
Allow for conversion from `openArray`s, similar to `toSinglyLinkedList`
and `toDoublyLinkedList`.
Diffstat (limited to 'lib/pure/collections')
-rw-r--r--lib/pure/collections/lists.nim22
1 files changed, 22 insertions, 0 deletions
diff --git a/lib/pure/collections/lists.nim b/lib/pure/collections/lists.nim
index b9d5c48eb..9b89fe9f8 100644
--- a/lib/pure/collections/lists.nim
+++ b/lib/pure/collections/lists.nim
@@ -983,6 +983,17 @@ func toSinglyLinkedList*[T](elems: openArray[T]): SinglyLinkedList[T] {.since: (
   for elem in elems.items:
     result.add(elem)
 
+func toSinglyLinkedRing*[T](elems: openArray[T]): SinglyLinkedRing[T] =
+  ## Creates a new `SinglyLinkedRing` from the members of `elems`.
+  runnableExamples:
+    from std/sequtils import toSeq
+    let a = [1, 2, 3, 4, 5].toSinglyLinkedRing
+    assert a.toSeq == [1, 2, 3, 4, 5]
+
+  result = initSinglyLinkedRing[T]()
+  for elem in elems.items:
+    result.add(elem)
+
 func toDoublyLinkedList*[T](elems: openArray[T]): DoublyLinkedList[T] {.since: (1, 5, 1).} =
   ## Creates a new `DoublyLinkedList` from the members of `elems`.
   runnableExamples:
@@ -993,3 +1004,14 @@ func toDoublyLinkedList*[T](elems: openArray[T]): DoublyLinkedList[T] {.since: (
   result = initDoublyLinkedList[T]()
   for elem in elems.items:
     result.add(elem)
+
+func toDoublyLinkedRing*[T](elems: openArray[T]): DoublyLinkedRing[T] =
+  ## Creates a new `DoublyLinkedRing` from the members of `elems`.
+  runnableExamples:
+    from std/sequtils import toSeq
+    let a = [1, 2, 3, 4, 5].toDoublyLinkedRing
+    assert a.toSeq == [1, 2, 3, 4, 5]
+
+  result = initDoublyLinkedRing[T]()
+  for elem in elems.items:
+    result.add(elem)
22 +0200 committer Andreas Rumpf <andreasrumpf@noname> 2009-09-15 23:22:22 +0200 added tools and web dirs' href='/ahoang/Nim/commit/web/index.txt?h=devel&id=66a7e3d37c0303997a6b1a3b7ec263dfb8c07748'>66a7e3d37 ^
3f3dda5a7 ^

66a7e3d37 ^






7000cf51b ^




202d229fd ^

66a7e3d37 ^

66a7e3d37 ^

66a7e3d37 ^


66a7e3d37 ^

42eb21be7 ^
aa14667ca ^

66a7e3d37 ^



053309e60 ^
42eb21be7 ^

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119