#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 637 of file statistc.cpp.
640 int32_t prev_greater;
648 if (array[0] < array[1]) {
649 return index >= 1 ? 1 : 0;
652 return index >= 1 ? 0 : 1;
658 else if (index >=
count)
660 equal_count = (int32_t) (rand() %
count);
661 pivot = array[equal_count];
663 array[equal_count] = array[0];
665 prev_greater =
count;
667 for (next_sample = 1; next_sample < prev_greater;) {
668 sample = array[next_sample];
671 array[next_lesser++] =
sample;
674 else if (
sample > pivot) {
677 array[next_sample] = array[prev_greater];
678 array[prev_greater] =
sample;
685 for (next_sample = next_lesser; next_sample < prev_greater;)
686 array[next_sample++] = pivot;
687 if (index < next_lesser)
689 else if (index < prev_greater)
693 array + prev_greater,
694 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 704 of file statistc.cpp.
709 int32_t prev_greater;
716 if (compar (array, (
char *) array + size) < 0) {
717 return index >= 1 ? 1 : 0;
720 return index >= 1 ? 0 : 1;
725 else if (index >=
count)
727 pivot = (int32_t) (rand () %
count);
730 prev_greater =
count;
732 for (next_sample = 1; next_sample < prev_greater;) {
734 compar ((
char *) array + size * next_sample,
735 (
char *) array + size * next_lesser);
737 swap_entries (array, size, next_lesser++, next_sample++);
740 else if (result > 0) {
749 if (index < next_lesser)
751 else if (index < prev_greater)
755 (
char *) array + size * prev_greater,
756 count - prev_greater, size,
757 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 765 of file statistc.cpp.
774 ptr1 =
static_cast<char *
>(array) + index1 * size;
775 ptr2 =
static_cast<char *
>(array) + index2 * size;