#include "statistc.h"
#include <string.h>
#include <math.h>
#include <stdlib.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 636 of file statistc.cpp.
639 int32_t prev_greater;
647 if (array[0] < array[1]) {
648 return index >= 1 ? 1 : 0;
651 return index >= 1 ? 0 : 1;
657 else if (index >=
count)
659 equal_count = (int32_t) (rand() %
count);
660 pivot = array[equal_count];
662 array[equal_count] = array[0];
664 prev_greater =
count;
666 for (next_sample = 1; next_sample < prev_greater;) {
667 sample = array[next_sample];
668 if (sample < pivot) {
670 array[next_lesser++] = sample;
673 else if (sample > pivot) {
676 array[next_sample] = array[prev_greater];
677 array[prev_greater] = sample;
684 for (next_sample = next_lesser; next_sample < prev_greater;)
685 array[next_sample++] = pivot;
686 if (index < next_lesser)
688 else if (index < prev_greater)
692 array + prev_greater,
693 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 703 of file statistc.cpp.
708 int32_t prev_greater;
715 if (compar (array, (
char *) array + size) < 0) {
716 return index >= 1 ? 1 : 0;
719 return index >= 1 ? 0 : 1;
724 else if (index >=
count)
726 pivot = (int32_t) (rand () %
count);
729 prev_greater =
count;
731 for (next_sample = 1; next_sample < prev_greater;) {
733 compar ((
char *) array + size * next_sample,
734 (
char *) array + size * next_lesser);
736 swap_entries (array, size, next_lesser++, next_sample++);
739 else if (result > 0) {
748 if (index < next_lesser)
750 else if (index < prev_greater)
754 (
char *) array + size * prev_greater,
755 count - prev_greater, size,
756 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 764 of file statistc.cpp.
773 ptr1 =
static_cast<char *
>(array) + index1 * size;
774 ptr2 =
static_cast<char *
>(array) + index2 * size;
775 for (count = 0; count < size; count++) {