1 #if !defined(ON_COMPILING_OPENNURBS_HSORT_FUNCTIONS) 6 #error Do not compile openurbs_hsort_template.c directly. 10 #if !defined(ON_SORT_TEMPLATE_TYPE) 11 #error Define ON_SORT_TEMPLATE_TYPE macro before including opennurbs_qsort_template.c 14 #if !defined(ON_HSORT_FNAME) 15 #error Define ON_HSORT_FNAME macro before including opennurbs_qsort_template.c 18 #if defined(ON_SORT_TEMPLATE_COMPARE) 20 #define ON_HSORT_GT(A,B) ON_SORT_TEMPLATE_COMPARE(A,B) > 0 21 #define ON_HSORT_GT_TMP(A) ON_SORT_TEMPLATE_COMPARE(A,&tmp) > 0 24 #define ON_HSORT_GT(A,B) *A > *B 25 #define ON_HSORT_GT_TMP(A) *A > tmp 28 #if defined(ON_SORT_TEMPLATE_USE_MEMCPY) 29 #define ON_HSORT_TO_TMP(A) memcpy(&tmp,A,sizeof(tmp)) 30 #define ON_HSORT_FROM_TMP(A) memcpy(A,&tmp,sizeof(tmp)) 31 #define ON_HSORT_COPY(dst,src) memcpy(dst,src,sizeof(tmp)) 33 #define ON_HSORT_TO_TMP(A) tmp = *A 34 #define ON_HSORT_FROM_TMP(A) *A = tmp 35 #define ON_HSORT_COPY(dst,src) *dst = *src 38 #if defined(ON_SORT_TEMPLATE_STATIC_FUNCTION) 42 ON_HSORT_FNAME( ON_SORT_TEMPLATE_TYPE* base,
size_t nel )
45 ON_SORT_TEMPLATE_TYPE* e_end;
46 ON_SORT_TEMPLATE_TYPE* e_i;
47 ON_SORT_TEMPLATE_TYPE* e_j;
48 ON_SORT_TEMPLATE_TYPE tmp;
50 if (0 == base || nel < 2)
61 ON_HSORT_TO_TMP((base+k));
65 ON_HSORT_TO_TMP(e_end);
66 ON_HSORT_COPY(e_end,base);
69 ON_HSORT_FROM_TMP(base);
81 if (j < i_end && ON_HSORT_GT((e_j+1),e_j) )
86 if (ON_HSORT_GT_TMP(e_j) )
88 ON_HSORT_COPY(e_i,e_j);
97 ON_HSORT_FROM_TMP(e_i);
102 #undef ON_HSORT_GT_TMP 103 #undef ON_HSORT_TO_TMP 104 #undef ON_HSORT_FROM_TMP 106 #undef ON_HSORT_FROM_TMP