MCPcopy Create free account
hub / github.com/chronoxor/CppBenchmark / MergeSortInternal

Method MergeSortInternal

examples/sort.cpp:277–305  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

275
276private:
277 static void MergeSortInternal(int* dst, int* src, size_t index, size_t size, size_t chunk)
278 {
279 size_t index1 = 0;
280 size_t index2 = 0;
281
282 while ((index1 < chunk) || (index2 < chunk))
283 {
284 // Check bounds of left chunk
285 if ((index + index1 >= size))
286 index1 = chunk;
287 // Check bounds of right chunk
288 if (index + chunk + index2 >= size)
289 index2 = chunk;
290
291 // Check if we use right or left chunk for merge
292 if ((index2 < chunk) && ((index1 == chunk) || (src[chunk + index2] < src[index1])))
293 {
294 // Use right chunk
295 *dst++ = src[chunk + index2];
296 ++index2;
297 }
298 else if (index1 < chunk)
299 {
300 // Use left chunk
301 *dst++ = src[index1];
302 ++index1;
303 }
304 }
305 }
306};
307
308class QuickSort : public CppBenchmark::Benchmark, public SortFixture

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected