21#include "quickSortIndex.h"
24#define OPT_SORT_CASE 0x01
25#define OPT_SORT_GROUP 0x02
26#define OPT_SORT_FIELD 0x04
47static int _compareField(
struct CompareField* cf,
70 for( it = cf->fb.
it; it != cf->fb.
end; ++it )
72 if( ur_is(it, UT_INT) )
80 if( type == UT_BINARY )
82 ca = _binByte( bufA, i + a->
series.
it );
83 i = _binByte( bufB, i + b->
series.
it );
89 if( ! (cf->opt & OPT_SORT_CASE) )
114 for( it = cf->fb.
it; it != cf->fb.
end; )
116 if( ur_is(it, UT_INT) )
124 if( (++it != cf->fb.
end) && ur_is(it, UT_OPTION) )
134#define SORT_BLK_CELL(res, si, index) \
135 pos = index + ((index < 0) ? si.end : si.it); \
136 if( pos < si.it || pos >= si.end ) \
138 res = si.buf->ptr.cell + pos;
140 SORT_BLK_CELL( a, siA, i );
141 SORT_BLK_CELL( b, siB, i );
160 for( it = cf->fb.
it; it != cf->fb.
end; )
162 if( ur_is(it, UT_WORD) )
166 if( (++it != cf->fb.
end) && ur_is(it, UT_OPTION) )
214 if( ur_isBlockType(type) )
217 struct CompareField fld;
227 len = bi.end - bi.it;
230 if( fld.opt & OPT_SORT_GROUP )
232 group = ur_int(CFUNC_OPT_ARG(2));
235 indexLen = len / group;
236 len = indexLen * group;
246 qs.index = ((uint32_t*) (blk->
ptr.
cell + len)) - indexLen;
247 qs.data = (uint8_t*) bi.it;
248 qs.elemSize =
sizeof(
UCell);
250 if( fld.opt & OPT_SORT_FIELD )
255 qs.user = (
void*) &fld;
256 qs.compare = (QuickSortFunc) _compareField;
260 qs.user = (
void*) ut;
261 qs.compare = (QuickSortFunc) ((fld.opt & OPT_SORT_CASE) ?
266 iend = ip + quickSortIndex( &qs, 0, len, group );
268 len = qs.elemSize * group;
271 memCpy( blk->
ptr.
cell + blk->
used, bi.it + *ip, len );
#define CFUNC(name)
Macro to define C functions.
Definition boron.h:57
#define CFUNC_OPTIONS
Macro to get uint16_t option flags from inside a C function.
Definition boron.h:59
UBuffer * ur_makeBlockCell(UThread *, int type, int size, UCell *cell)
Generate a single block and set cell to reference it.
Definition block.c:76
int ur_ctxLookup(const UBuffer *, UAtom atom)
Find word in context by atom.
Definition context.c:579
#define ur_ctxCell(c, n)
Get pointer of UCell in context by index.
Definition urlan.h:668
int ur_strChar(const UBuffer *, UIndex pos)
Return the character at a given position.
Definition string.c:1659
void ur_seriesSlice(const UThread *, USeriesIter *si, const UCell *cell)
Set USeriesIter to series slice.
Definition env.c:1338
#define ur_bufferSer(c)
Convenience macro for ur_bufferSeries().
Definition urlan.h:752
UStatus ur_error(UThread *, int errorType, const char *fmt,...)
Create error! exception.
Definition env.c:964
const UCell * end
End position.
Definition urlan.h:388
const UCell * it
Start position.
Definition urlan.h:387
@ UR_OK
Returned to indicate successful evaluation/operation.
Definition urlan.h:118
const UBuffer * ur_blockIt(const UThread *ut, UBlockIt *bi, const UCell *blkCell)
Set UBlockIt to the start and end of a block slice.
Definition env.c:1388
int ur_compare(UThread *, const UCell *a, const UCell *b)
Definition env.c:1079
int ur_compareCase(UThread *, const UCell *a, const UCell *b)
Case-sensitive ordering comparison.
Definition env.c:1093
#define ur_type(c)
Return UrlanDataType of cell.
Definition urlan.h:695
Iterator for const UCell array.
Definition urlan.h:386
The UBuffer struct holds information about a resource, usually a chunk of memory.
Definition urlan.h:266
UIndex used
This typically holds the number of elements in the buffer.
Definition urlan.h:271
UCell * cell
Array of cells.
Definition urlan.h:275
union UBuffer::@312146223224040072236377336057316010374162171270 ptr
This typically holds a pointer to a chunk of memory.
UIndex it
Iterator index.
Definition urlan.h:229
Iterator for const series of any type.
Definition urlan.h:336
The UThread struct stores the data specific to a thread of execution.
Definition urlan.h:309
A cell holds a single value of a simple type or a reference (often to a UBuffer) for a complex type.
Definition urlan.h:248
UCellSeries series
For binary!, bitset!, string!, file!, block!, paren!, path! types.
Definition urlan.h:255
int ur_charLowercase(int c)
Convert UCS2 character to lowercase.
Definition ucs2_case.c:293
@ UR_ERR_INTERNAL
Fatal internal problem.
Definition urlan.h:129