tesseract  5.0.0-alpha-619-ge9db
statistc.h File Reference
#include <cstdio>
#include "kdpair.h"
#include "scrollview.h"

Go to the source code of this file.

Classes

class  GenericVector< T >
 
class  STATS
 

Functions

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)
 

Function Documentation

◆ choose_nth_item() [1/2]

int32_t choose_nth_item ( int32_t  index,
float *  array,
int32_t  count 
)

Definition at line 609 of file statistc.cpp.

609  { // colour to draw in
610  if (buckets_ == nullptr) {
611  return;
612  }
613  window->Pen(colour);
614  window->SetCursor(xorigin, yorigin + yscale * buckets_[0]);
615  for (int index = 0; index < rangemax_ - rangemin_; index++) {
616  window->DrawTo(xorigin + xscale * index,
617  yorigin + yscale * buckets_[index]);
618  }
619 }
620 #endif
621 
622 
623 /**********************************************************************
624  * choose_nth_item
625  *
626  * Returns the index of what would b the nth item in the array
627  * if the members were sorted, without actually sorting.
628  **********************************************************************/
629 
630 int32_t choose_nth_item(int32_t index, float *array, int32_t count) {
631  int32_t next_sample; // next one to do
632  int32_t next_lesser; // space for new
633  int32_t prev_greater; // last one saved
634  int32_t equal_count; // no of equal ones
635  float pivot; // proposed median
636  float sample; // current sample
637 
638  if (count <= 1)
639  return 0;
640  if (count == 2) {
641  if (array[0] < array[1]) {
642  return index >= 1 ? 1 : 0;
643  }
644  else {
645  return index >= 1 ? 0 : 1;
646  }
647  }
648  else {
649  if (index < 0)
650  index = 0; // ensure legal
651  else if (index >= count)
652  index = count - 1;
653  equal_count = static_cast<int32_t>(rand() % count);
654  pivot = array[equal_count];
655  // fill gap
656  array[equal_count] = array[0];
657  next_lesser = 0;
658  prev_greater = count;
659  equal_count = 1;
660  for (next_sample = 1; next_sample < prev_greater;) {
661  sample = array[next_sample];
662  if (sample < pivot) {
663  // shuffle
664  array[next_lesser++] = sample;
665  next_sample++;
666  }
667  else if (sample > pivot) {
668  prev_greater--;

◆ 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 675 of file statistc.cpp.

698  {
699  int result; // of compar
700  int32_t next_sample; // next one to do
701  int32_t next_lesser; // space for new
702  int32_t prev_greater; // last one saved
703  int32_t equal_count; // no of equal ones
704  int32_t pivot; // proposed median
705 
706  if (count <= 1)
707  return 0;
708  if (count == 2) {
709  if (compar (array, static_cast<char *>(array) + size) < 0) {
710  return index >= 1 ? 1 : 0;
711  }
712  else {
713  return index >= 1 ? 0 : 1;
714  }
715  }
716  if (index < 0)
717  index = 0; // ensure legal
718  else if (index >= count)
719  index = count - 1;
720  pivot = static_cast<int32_t>(rand () % count);
721  swap_entries (array, size, pivot, 0);
722  next_lesser = 0;
723  prev_greater = count;
724  equal_count = 1;
725  for (next_sample = 1; next_sample < prev_greater;) {
726  result =
727  compar (static_cast<char *>(array) + size * next_sample,
728  static_cast<char *>(array) + size * next_lesser);
729  if (result < 0) {

◆ swap_entries()

void swap_entries ( void *  array,
size_t  size,
int32_t  index1,
int32_t  index2 
)

Definition at line 735 of file statistc.cpp.

737  {
738  equal_count++;
739  next_sample++;
740  }
741  }
742  if (index < next_lesser)
743  return choose_nth_item (index, array, next_lesser, size, compar);
744  else if (index < prev_greater)
745  return next_lesser; // in equal bracket
746  else
747  return choose_nth_item (index - prev_greater,
748  static_cast<char *>(array) + size * prev_greater,
749  count - prev_greater, size,
750  compar) + prev_greater;
751 }
choose_nth_item
int32_t choose_nth_item(int32_t index, float *array, int32_t count)
Definition: statistc.cpp:609
swap_entries
void swap_entries(void *array, size_t size, int32_t index1, int32_t index2)
Definition: statistc.cpp:735
sample
Definition: cluster.h:31
count
int count(LIST var_list)
Definition: oldlist.cpp:79