8000 Convert timsort.c.src to C++ · rjeb/numpy@73a20fd · GitHub
[go: up one dir, main page]

Skip to content

Commit 73a20fd

Browse files
Convert timsort.c.src to C++
1 parent f40b105 commit 73a20fd

File tree

4 files changed

+1027
-571
lines changed

4 files changed

+1027
-571
lines changed

numpy/core/setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -948,7 +948,7 @@ def gl_if_msvc(build_cmd):
948948
join('src', 'common', 'npy_sort.h.src'),
949949
join('src', 'npysort', 'quicksort.c.src'),
950950
join('src', 'npysort', 'mergesort.c.src'),
951-
join('src', 'npysort', 'timsort.c.src'),
951+
join('src', 'npysort', 'timsort.cpp'),
952952
join('src', 'npysort', 'heapsort.c.src'),
953953
join('src', 'npysort', 'radixsort.cpp'),
954954
join('src', 'common', 'npy_partition.h.src'),

numpy/core/src/common/numpy_tag.h

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,40 @@ struct timedelta_tag : date_tag {
220220
}
221221
};
222222

223+
struct string_tag {
224+
using type = npy_char;
225+
static constexpr NPY_TYPES type_value = NPY_STRING;
226+
static int less(type const* a, type const* b, size_t len) {
227+
return STRING_LT(a, b, len);
228+
}
229+
static int less_equal(type const* a, type const* b, size_t len) {
230+
return !less(b, a, len);
231+
}
232+
static void swap(type* a, type* b, size_t len) {
233+
STRING_SWAP(a, b, len);
234+
}
235+
static void copy(type * a, type const* b, size_t len) {
236+
STRING_COPY(a, b, len);
237+
}
238+
};
239+
240+
struct unicode_tag {
241+
using type = npy_ucs4;
242+
static constexpr NPY_TYPES type_value = NPY_UNICODE;
243+
static int less(type const* a, type const* b, size_t len) {
244+
return UNICODE_LT(a, b, len);
245+
}
246+
static int less_equal(type const* a, type const* b, size_t len) {
247+
return !less(b, a, len);
248+
}
249+
static void swap(type* a, type* b, size_t len) {
250+
UNICODE_SWAP(a, b, len);
251+
}
252+
static void copy(type * a, type const* b, size_t len) {
253+
UNICODE_COPY(a, b, len);
254+
}
255+
};
256+
223257
} // namespace npy
224258

225259
#endif

numpy/core/src/npysort/npysort_common.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ CLONGDOUBLE_LT(npy_clongdouble a, npy_clongdouble b)
259259

260260

261261
NPY_INLINE static void
262-
STRING_COPY(char *s1, char *s2, size_t len)
262+
STRING_COPY(char *s1, char const*s2, size_t len)
263263
{
264264
memcpy(s1, s2, len);
265265
}
@@ -295,7 +295,7 @@ STRING_LT(const char *s1, const char *s2, size_t len)
295295

296296

297297
NPY_INLINE static void
298-
UNICODE_COPY(npy_ucs4 *s1, npy_ucs4 *s2, size_t len)
298+
UNICODE_COPY(npy_ucs4 *s1, npy_ucs4 const *s2, size_t len)
299299
{
300300
while(len--) {
301301
*s1++ = *s2++;

0 commit comments

Comments
 (0)
0