| 234 | typename compare |
| 235 | > |
| 236 | void qsort_array_main ( |
| 237 | T& array, |
| 238 | const unsigned long left, |
| 239 | const unsigned long right, |
| 240 | unsigned long depth_check, |
| 241 | const compare& comp |
| 242 | ) |
| 243 | /*! |
| 244 | requires |
| 245 | - T implements operator[] |
| 246 | - the items in array must be comparable by comp |
| 247 | - the items in array must be swappable by a global swap() |
| 248 | - left and right are within the bounds of array |
| 249 | i.e. array[left] and array[right] are valid elements |
| 250 | ensures |
| 251 | - for all elements in #array between and including left and right the |
| 252 | ith element is < the i+1 element |
| 253 | - will only recurse about as deep as log(depth_check) calls |
| 254 | - sorts using a quick sort algorithm |
| 255 | !*/ |
| 256 | { |
| 257 | if ( left < right) |
| 258 | { |
| 259 | if (right-left < 30 || depth_check == 0) |
| 260 | { |
| 261 | hsort_array(array,left,right,comp); |
| 262 | } |
| 263 | else |
| 264 | { |
| 265 | // The idea here is to only let quick sort go about log(N) |
| 266 | // calls deep before it kicks into something else. |
| 267 | depth_check >>= 1; |
| 268 | depth_check += (depth_check>>4); |
| 269 | |
| 270 | unsigned long partition_element = |
| 271 | qsort_partition(array,array[right],left,right,comp); |
| 272 | |
| 273 | if (partition_element > 0) |
| 274 | qsort_array_main(array,left,partition_element-1,depth_check,comp); |
| 275 | qsort_array_main(array,partition_element+1,right,depth_check,comp); |
| 276 | } |
| 277 | } |
| 278 | } |
| 279 | |
| 280 | // ---------------------------------------------------------------------------------------- |
| 281 |
no test coverage detected