#include "statistc.h"
#include <cstring>
#include <cmath>
#include <cstdlib>
#include "errcode.h"
#include "helpers.h"
#include "scrollview.h"
#include "tprintf.h"
Go to the source code of this file.
|
int32_t | choose_nth_item (int32_t index, float *array, int32_t count) |
|
int32_t | choose_nth_item (int32_t index, void *array, int32_t count, size_t size, int(*compar)(const void *, const void *)) |
|
void | swap_entries (void *array, size_t size, int32_t index1, int32_t index2) |
|
◆ choose_nth_item() [1/2]
int32_t choose_nth_item |
( |
int32_t |
index, |
|
|
float * |
array, |
|
|
int32_t |
count |
|
) |
| |
Definition at line 630 of file statistc.cpp.
633 int32_t prev_greater;
641 if (array[0] < array[1]) {
642 return index >= 1 ? 1 : 0;
645 return index >= 1 ? 0 : 1;
651 else if (index >=
count)
653 equal_count =
static_cast<int32_t
>(rand() %
count);
654 pivot = array[equal_count];
656 array[equal_count] = array[0];
658 prev_greater =
count;
660 for (next_sample = 1; next_sample < prev_greater;) {
661 sample = array[next_sample];
664 array[next_lesser++] =
sample;
667 else if (
sample > pivot) {
670 array[next_sample] = array[prev_greater];
671 array[prev_greater] =
sample;
678 for (next_sample = next_lesser; next_sample < prev_greater;)
679 array[next_sample++] = pivot;
680 if (index < next_lesser)
682 else if (index < prev_greater)
686 array + prev_greater,
687 count - prev_greater) + prev_greater;
int32_t choose_nth_item(int32_t index, float *array, int32_t count)
◆ choose_nth_item() [2/2]
int32_t choose_nth_item |
( |
int32_t |
index, |
|
|
void * |
array, |
|
|
int32_t |
count, |
|
|
size_t |
size, |
|
|
int(*)(const void *, const void *) |
compar |
|
) |
| |
Definition at line 697 of file statistc.cpp.
702 int32_t prev_greater;
709 if (compar (array, static_cast<char *>(array) + size) < 0) {
710 return index >= 1 ? 1 : 0;
713 return index >= 1 ? 0 : 1;
718 else if (index >=
count)
720 pivot =
static_cast<int32_t
>(rand () %
count);
723 prev_greater =
count;
725 for (next_sample = 1; next_sample < prev_greater;) {
727 compar (static_cast<char *>(array) + size * next_sample,
728 static_cast<char *>(array) + size * next_lesser);
730 swap_entries (array, size, next_lesser++, next_sample++);
733 else if (result > 0) {
742 if (index < next_lesser)
744 else if (index < prev_greater)
748 static_cast<char *>(array) + size * prev_greater,
749 count - prev_greater, size,
750 compar) + prev_greater;
void swap_entries(void *array, size_t size, int32_t index1, int32_t index2)
int32_t choose_nth_item(int32_t index, float *array, int32_t count)
◆ swap_entries()
void swap_entries |
( |
void * |
array, |
|
|
size_t |
size, |
|
|
int32_t |
index1, |
|
|
int32_t |
index2 |
|
) |
| |
Definition at line 758 of file statistc.cpp.
767 ptr1 =
static_cast<char *
>(array) + index1 * size;
768 ptr2 =
static_cast<char *
>(array) + index2 * size;