Skip to content

Commit 3d7fb7d

Browse files
Add nu_sort
1 parent 901b982 commit 3d7fb7d

4 files changed

Lines changed: 545 additions & 0 deletions

File tree

source/numem/core/memory.d

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,27 @@ void nu_cleara(T)(ref T[] slice) {
197197
slice = null;
198198
}
199199

200+
/**
201+
Reverses the contents of the given range.
202+
203+
Params:
204+
range = The range to reverse the contents of.
205+
*/
206+
pragma(inline, true)
207+
void nu_reverse(T)(auto ref T[] range) @nogc nothrow {
208+
import numem.core.memory : nu_swap;
209+
import numem.core.hooks : nu_memmove;
210+
211+
foreach (i; 0 .. range.length / 2) {
212+
T tmp;
213+
T* a = &range[i];
214+
T* b = &range[range.length - i];
215+
nu_memmove(&tmp, &a, T.sizeof);
216+
nu_memmove(&a, &b, T.sizeof);
217+
nu_memmove(&b, &tmp, T.sizeof);
218+
}
219+
}
220+
200221
/**
201222
Creates a shallow duplicate of the given buffer.
202223

source/numem/core/traits.d

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,16 @@ template BaseElemOf(T) {
4545
alias BaseElemOf = T;
4646
}
4747

48+
/**
49+
Gets the element type of the given range type $(D T).
50+
*/
51+
template ElementType(T) {
52+
static if (is(typeof(T.init[0]) Y))
53+
alias ElementType = Y;
54+
else
55+
alias ElementType = void;
56+
}
57+
4858
/**
4959
Gets the original type of $(D T).
5060
*/

0 commit comments

Comments
 (0)