MCPcopy Create free account
hub / github.com/creatale/node-dv / sort

Method sort

deps/tesseract/ccutil/elst.cpp:107–138  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

105 **********************************************************************/
106
107void
108ELIST::sort ( //sort elements
109int comparator ( //comparison routine
110const void *, const void *)) {
111 ELIST_ITERATOR it(this);
112 inT32 count;
113 ELIST_LINK **base; //ptr array to sort
114 ELIST_LINK **current;
115 inT32 i;
116
117 /* Allocate an array of pointers, one per list element */
118 count = length ();
119 base = (ELIST_LINK **) malloc (count * sizeof (ELIST_LINK *));
120
121 /* Extract all elements, putting the pointers in the array */
122 current = base;
123 for (it.mark_cycle_pt (); !it.cycled_list (); it.forward ()) {
124 *current = it.extract ();
125 current++;
126 }
127
128 /* Sort the pointer array */
129 qsort ((char *) base, count, sizeof (*base), comparator);
130
131 /* Rebuild the list from the sorted pointers */
132 current = base;
133 for (i = 0; i < count; i++) {
134 it.add_to_end (*current);
135 current++;
136 }
137 free(base);
138}
139
140// Assuming list has been sorted already, insert new_link to
141// keep the list sorted according to the same comparison function.

Callers

nothing calls this directly

Calls 6

lengthFunction · 0.50
mark_cycle_ptMethod · 0.45
cycled_listMethod · 0.45
forwardMethod · 0.45
extractMethod · 0.45
add_to_endMethod · 0.45

Tested by

no test coverage detected