MCPcopy Create free account
hub / github.com/catboost/catboost / fts_sort

Function fts_sort

util/folder/fts.cpp:1188–1224  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1186}
1187
1188static FTSENT*
1189fts_sort(FTS* sp, FTSENT* head, int nitems)
1190{
1191 FTSENT **ap, *p;
1192
1193 /*
1194 * Construct an array of pointers to the structures and call qsort(3).
1195 * Reassemble the array in the order returned by qsort. If unable to
1196 * sort for memory reasons, return the directory entries in their
1197 * current order. Allocate enough space for the current needs plus
1198 * 40 so don't realloc one entry at a time.
1199 */
1200 if (nitems > sp->fts_nitems) {
1201 struct _ftsent** a;
1202
1203 sp->fts_nitems = nitems + 40;
1204 if ((a = (struct _ftsent**)realloc(sp->fts_array,
1205 sp->fts_nitems * sizeof(FTSENT*))) == nullptr) {
1206 if (sp->fts_array) {
1207 free(sp->fts_array);
1208 }
1209 sp->fts_array = nullptr;
1210 sp->fts_nitems = 0;
1211 return (head);
1212 }
1213 sp->fts_array = a;
1214 }
1215 for (ap = sp->fts_array, p = head; p; p = p->fts_link) {
1216 *ap++ = p;
1217 }
1218 qsort((void*)sp->fts_array, (size_t)nitems, sizeof(FTSENT*), (int (*)(const void*, const void*))sp->fts_compar);
1219 for (head = *(ap = sp->fts_array); --nitems; ++ap) {
1220 ap[0]->fts_link = ap[1];
1221 }
1222 ap[0]->fts_link = nullptr;
1223 return (head);
1224}
1225
1226static FTSENT*
1227fts_alloc(FTS* sp, const char* name, int namelen)

Callers 2

yfts_openFunction · 0.85
fts.cppFile · 0.85

Calls 2

reallocFunction · 0.50
freeFunction · 0.50

Tested by

no test coverage detected