cutil/tessarray.cpp File Reference

#include "tessarray.h"
#include "callcpp.h"
#include "freelist.h"
#include <stdio.h>
#include <string.h>
#include <ctype.h>

Go to the source code of this file.

Functions


Function Documentation

ARRAY array_insert ( ARRAY  array,
int  index,
void *  value 
)

Insert a data element into a particular spot in the array.

Move all the elements in the array (past that spot) down one to make room for the new element.

Definition at line 42 of file tessarray.cpp.

References array_count, array_push(), array_value, and NULL.

Referenced by improve_one_blob(), and insert_seam().

00042                                                         { 
00043   int x;
00044 
00045   array = array_push (array, NULL);
00046   for (x = array_count (array) - 1; x > index; x--)
00047     array_value (array, x) = array_value (array, x - 1);
00048   array_value (array, index) = value;
00049   return (array);
00050 }

ARRAY array_new ( int  num  ) 

Create a new array with a certain number of elements.

If the number of elements requested is 0 then the default number will be used.

Definition at line 58 of file tessarray.cpp.

References array_count, array_limit, array_value, cprintf(), DEFAULT_SIZE, and memalloc().

Referenced by new_seam_list().

00058                          { 
00059   ARRAY temp;
00060   int x;
00061 
00062   if (num == 0)
00063     num = DEFAULT_SIZE;
00064   temp = (ARRAY) memalloc ((num - 2) * sizeof (char *) +
00065     sizeof (struct array_record));
00066   if (!temp) {
00067     cprintf ("error: Out of memory in array_new\n");
00068     exit (1);                    //?err_exit ();
00069   }
00070   array_count (temp) = 0;
00071   array_limit (temp) = num;
00072   for (x = 0; x < num; x++)
00073     array_value (temp, x) = (char *) 0;
00074   return (temp);
00075 }

ARRAY array_push ( ARRAY  array,
void *  value 
)

Add a new element onto the top of the array.

If there is no more room, room is made by "realloc"ing the array. This means that the new array location may change. All previous references to its old location may no longer be valid.

Definition at line 85 of file tessarray.cpp.

References array_count, array_limit, array_top, cprintf(), and memrealloc().

Referenced by add_seam(), array_insert(), choose_best_seam(), chop_word_main(), evaluate_chunks(), permute_subword(), and rebuild_current_state().

00085                                            { 
00086   if (array_count (array) == array_limit (array)) {
00087     array = (ARRAY) memrealloc (array, (array_limit (array) * 2 - 2) *
00088       sizeof (char *) +
00089       sizeof (struct array_record),
00090       (array_limit (array) -
00091       2) * sizeof (char *) +
00092       sizeof (struct array_record));
00093     if (!array) {
00094       cprintf ("error: Out of memory in array_push\n");
00095       exit (1);                  //?err_exit ();
00096     }
00097     array_limit (array) *= 2;
00098   }
00099   array_count (array)++;
00100   array_top (array) = value;
00101   return (array);
00102 }


Generated on Wed Feb 28 19:49:22 2007 for Tesseract by  doxygen 1.5.1