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

Method sort

deps/tesseract/ccutil/elst2.cpp:108–139  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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