@@ -24,7 +24,7 @@ Macros:
2424module mir.ndslice.sorting ;
2525
2626// / Check if ndslice is sorted, or strictly monotonic.
27- version (mir_test) unittest
27+ version (mir_test) @safe pure unittest
2828{
2929 import mir.ndslice.algorithm: all;
3030 import mir.ndslice.slice: sliced;
@@ -48,7 +48,7 @@ version(mir_test) unittest
4848}
4949
5050// / Create index
51- unittest
51+ version (mir_test) unittest
5252{
5353 import mir.ndslice.algorithm: all;
5454 import mir.ndslice.allocation: slice;
@@ -65,7 +65,7 @@ unittest
6565}
6666
6767// / Schwartzian transform
68- unittest
68+ version (mir_test) unittest
6969{
7070 import mir.ndslice.algorithm: all;
7171 import mir.ndslice.allocation: slice;
@@ -128,7 +128,7 @@ template isStrictlyMonotonic(alias less = "a < b")
128128 alias isStrictlyMonotonic = .isStrictlyMonotonic! (naryFun! less);
129129}
130130
131- unittest
131+ @safe pure version(mir_test) unittest
132132{
133133 import mir.ndslice.algorithm: all;
134134 import mir.ndslice.topology: pairwise;
@@ -145,7 +145,7 @@ unittest
145145 assert (c.pairwise! " a <= b" .all);
146146}
147147
148- unittest
148+ @safe pure version(mir_test) unittest
149149{
150150 import mir.ndslice.algorithm: all;
151151 import mir.ndslice.topology: pairwise;
@@ -172,6 +172,12 @@ template sort(alias less = "a < b")
172172 (Slice! (kind, packs, Iterator) slice)
173173 if (packs.length == 1 )
174174 {
175+ if (false ) // break safety
176+ {
177+ import mir.utility : swapStars;
178+ swapStars(slice._iterator, slice._iterator);
179+ auto l = less(* slice._iterator, * slice._iterator);
180+ }
175181 import mir.ndslice.topology: flattened;
176182 if (slice.anyEmpty)
177183 return slice;
@@ -183,7 +189,7 @@ template sort(alias less = "a < b")
183189}
184190
185191// /
186- unittest
192+ @safe pure version(mir_test) unittest
187193{
188194 import mir.ndslice.algorithm: all;
189195 import mir.ndslice.slice;
@@ -192,12 +198,12 @@ unittest
192198
193199 int [10 ] arr = [7 ,1 ,3 ,2 ,9 ,0 ,5 ,4 ,8 ,6 ];
194200
195- auto data = arr[].ptr. sliced(arr.length);
201+ auto data = arr[].sliced(arr.length);
196202 data.sort();
197203 assert (data.pairwise! " a <= b" .all);
198204}
199205
200- void quickSortImpl (alias less, Iterator)(Slice! (Contiguous, [1 ], Iterator) slice)
206+ void quickSortImpl (alias less, Iterator)(Slice! (Contiguous, [1 ], Iterator) slice) @trusted
201207{
202208 import mir.utility : swap, swapStars;
203209
@@ -308,7 +314,7 @@ void quickSortImpl(alias less, Iterator)(Slice!(Contiguous, [1], Iterator) slice
308314 }
309315}
310316
311- void setPivot (alias less, Iterator)(size_t length, ref Iterator l, ref Iterator mid, ref Iterator r)
317+ void setPivot (alias less, Iterator)(size_t length, ref Iterator l, ref Iterator mid, ref Iterator r) @trusted
312318{
313319 if (length < 512 )
314320 {
@@ -323,7 +329,7 @@ void setPivot(alias less, Iterator)(size_t length, ref Iterator l, ref Iterator
323329}
324330
325331void medianOf (alias less, Iterator)
326- (ref Iterator a, ref Iterator b, ref Iterator c)
332+ (ref Iterator a, ref Iterator b, ref Iterator c) @trusted
327333{
328334 import mir.utility : swapStars;
329335 if (less(* c, * a)) // c < a
@@ -355,7 +361,7 @@ void medianOf(alias less, Iterator)
355361}
356362
357363void medianOf (alias less, Iterator)
358- (ref Iterator a, ref Iterator b, ref Iterator c, ref Iterator d, ref Iterator e)
364+ (ref Iterator a, ref Iterator b, ref Iterator c, ref Iterator d, ref Iterator e) @trusted
359365{
360366 import mir.utility : swapStars; // Credit: Teppo Niinimäki
361367 version (unittest ) scope (success)
0 commit comments