tesseract  5.0.0-alpha-619-ge9db
tesseract::DawgPositionVector Class Reference

#include <dawg.h>

Inheritance diagram for tesseract::DawgPositionVector:
GenericVector< DawgPosition >

Public Member Functions

void clear ()
 
bool add_unique (const DawgPosition &new_pos, bool debug, const char *debug_msg)
 
- Public Member Functions inherited from GenericVector< DawgPosition >
 GenericVector ()
 
 GenericVector (int size, const DawgPosition &init_val)
 
 GenericVector (const GenericVector &other)
 
GenericVector< DawgPosition > & operator+= (const GenericVector &other)
 
void operator+= (const DawgPosition &t)
 
GenericVector< DawgPosition > & operator= (const GenericVector &other)
 
 ~GenericVector ()
 
void reserve (int size)
 
void double_the_size ()
 
void init_to_size (int size, const DawgPosition &t)
 
void resize_no_init (int size)
 
int size () const
 
size_t unsigned_size () const
 
int size_reserved () const
 
bool empty () const
 
DawgPosition & get (int index) const
 
DawgPosition & back () const
 
DawgPosition & operator[] (int index) const
 
DawgPosition pop_back ()
 
int get_index (const DawgPosition &object) const
 
bool contains (const DawgPosition &object) const
 
DawgPosition contains_index (int index) const
 
int push_back (DawgPosition object)
 
int push_back_new (const DawgPosition &object)
 
int push_front (const DawgPosition &object)
 
void set (const DawgPosition &t, int index)
 
void insert (const DawgPosition &t, int index)
 
void remove (int index)
 
void truncate (int size)
 
void set_clear_callback (std::function< void(DawgPosition)> cb)
 
void set_compare_callback (std::function< bool(const DawgPosition &, const DawgPosition &)> cb)
 
void clear ()
 
void delete_data_pointers ()
 
void move (GenericVector< DawgPosition > *from)
 
bool write (FILE *f, std::function< bool(FILE *, const DawgPosition &)> cb) const
 
bool read (tesseract::TFile *f, std::function< bool(tesseract::TFile *, DawgPosition *)> cb)
 
bool Serialize (FILE *fp) const
 
bool Serialize (tesseract::TFile *fp) const
 
bool DeSerialize (bool swap, FILE *fp)
 
bool DeSerialize (tesseract::TFile *fp)
 
bool SerializeClasses (FILE *fp) const
 
bool SerializeClasses (tesseract::TFile *fp) const
 
bool DeSerializeClasses (bool swap, FILE *fp)
 
bool DeSerializeClasses (tesseract::TFile *fp)
 
void reverse ()
 
void sort ()
 
void sort (int(*comparator)(const void *, const void *))
 
bool bool_binary_search (const DawgPosition &target) const
 
int binary_search (const DawgPosition &target) const
 
void compact_sorted ()
 
int choose_nth_item (int target_index)
 
void swap (int index1, int index2)
 
bool WithinBounds (const DawgPosition &rangemin, const DawgPosition &rangemax) const
 

Additional Inherited Members

- Static Public Member Functions inherited from GenericVector< DawgPosition >
static bool SkipDeSerialize (tesseract::TFile *fp)
 
static bool SkipDeSerializeClasses (tesseract::TFile *fp)
 
static DawgPosition * double_the_size_memcpy (int current_size, DawgPosition *data)
 
- Protected Member Functions inherited from GenericVector< DawgPosition >
int choose_nth_item (int target_index, int start, int end, unsigned int *seed)
 
void init (int size)
 
- Protected Attributes inherited from GenericVector< DawgPosition >
int32_t size_used_
 
int32_t size_reserved_
 
DawgPosition * data_
 
std::function< void(DawgPosition)> clear_cb_
 
std::function< bool(const DawgPosition &, const DawgPosition &)> compare_cb_
 
- Static Protected Attributes inherited from GenericVector< DawgPosition >
static const int kDefaultVectorSize
 

Detailed Description

Definition at line 373 of file dawg.h.

Member Function Documentation

◆ add_unique()

bool tesseract::DawgPositionVector::add_unique ( const DawgPosition new_pos,
bool  debug,
const char *  debug_msg 
)
inline

Adds an entry for the given dawg_index with the given node to the vec. Returns false if the same entry already exists in the vector, true otherwise.

Definition at line 381 of file dawg.h.

384  {
385  for (int i = 0; i < size_used_; ++i) {
386  if (data_[i] == new_pos) return false;
387  }
388  push_back(new_pos);
389  if (debug) {
390  tprintf("%s[%d, " REFFORMAT "] [punc: " REFFORMAT "%s]\n",
391  debug_msg, new_pos.dawg_index, new_pos.dawg_ref,
392  new_pos.punc_ref, new_pos.back_to_punc ? " returned" : "");
393  }
394  return true;

◆ clear()

void tesseract::DawgPositionVector::clear ( )
inline

Overload clear() in order to avoid allocating/deallocating memory when clearing the vector and re-inserting entries into it later.

Definition at line 377 of file dawg.h.

378 { size_used_ = 0; }

The documentation for this class was generated from the following file:
GenericVector< DawgPosition >::data_
DawgPosition * data_
Definition: genericvector.h:332
GenericVector< DawgPosition >::push_back
int push_back(DawgPosition object)
Definition: genericvector.h:799
REFFORMAT
#define REFFORMAT
Definition: dawg.h:87
GenericVector< DawgPosition >::size_used_
int32_t size_used_
Definition: genericvector.h:330
tprintf
DLLSYM void tprintf(const char *format,...)
Definition: tprintf.cpp:34