tesseract  4.0.0-1-g2a2b
tesseract::IndexMap Class Reference

#include <indexmapbidi.h>

Inheritance diagram for tesseract::IndexMap:
tesseract::IndexMapBiDi

Public Member Functions

virtual ~IndexMap ()
 
virtual int SparseToCompact (int sparse_index) const
 
int CompactToSparse (int compact_index) const
 
virtual int SparseSize () const
 
int CompactSize () const
 
void CopyFrom (const IndexMap &src)
 
void CopyFrom (const IndexMapBiDi &src)
 
bool Serialize (FILE *fp) const
 
bool DeSerialize (bool swap, FILE *fp)
 

Protected Attributes

int32_t sparse_size_
 
GenericVector< int32_t > compact_map_
 

Detailed Description

Definition at line 42 of file indexmapbidi.h.

Constructor & Destructor Documentation

◆ ~IndexMap()

tesseract::IndexMap::~IndexMap ( )
virtualdefault

Member Function Documentation

◆ CompactSize()

int tesseract::IndexMap::CompactSize ( ) const
inline

Definition at line 61 of file indexmapbidi.h.

61  {
62  return compact_map_.size();
63  }
int size() const
Definition: genericvector.h:71
GenericVector< int32_t > compact_map_
Definition: indexmapbidi.h:80

◆ CompactToSparse()

int tesseract::IndexMap::CompactToSparse ( int  compact_index) const
inline

Definition at line 53 of file indexmapbidi.h.

53  {
54  return compact_map_[compact_index];
55  }
GenericVector< int32_t > compact_map_
Definition: indexmapbidi.h:80

◆ CopyFrom() [1/2]

void tesseract::IndexMap::CopyFrom ( const IndexMap src)

Definition at line 38 of file indexmapbidi.cpp.

38  {
39  sparse_size_ = src.sparse_size_;
40  compact_map_ = src.compact_map_;
41 }
GenericVector< int32_t > compact_map_
Definition: indexmapbidi.h:80

◆ CopyFrom() [2/2]

void tesseract::IndexMap::CopyFrom ( const IndexMapBiDi src)

Definition at line 42 of file indexmapbidi.cpp.

42  {
43  sparse_size_ = src.SparseSize();
44  compact_map_ = src.compact_map_;
45 }
GenericVector< int32_t > compact_map_
Definition: indexmapbidi.h:80

◆ DeSerialize()

bool tesseract::IndexMap::DeSerialize ( bool  swap,
FILE *  fp 
)

Definition at line 54 of file indexmapbidi.cpp.

54  {
55  uint32_t sparse_size;
56  if (!tesseract::DeSerialize(fp, &sparse_size)) return false;
57  if (swap)
58  ReverseN(&sparse_size, sizeof(sparse_size));
59  // Arbitrarily limit the number of elements to protect against bad data.
60  if (sparse_size > UINT16_MAX) return false;
61  sparse_size_ = sparse_size;
62  return compact_map_.DeSerialize(swap, fp);
63 }
GenericVector< int32_t > compact_map_
Definition: indexmapbidi.h:80
bool DeSerialize(bool swap, FILE *fp)
void ReverseN(void *ptr, int num_bytes)
Definition: helpers.h:178
bool DeSerialize(FILE *fp, char *data, size_t n)
Definition: serialis.cpp:27

◆ Serialize()

bool tesseract::IndexMap::Serialize ( FILE *  fp) const

Definition at line 48 of file indexmapbidi.cpp.

48  {
50 }
GenericVector< int32_t > compact_map_
Definition: indexmapbidi.h:80
bool Serialize(FILE *fp, const char *data, size_t n)
Definition: serialis.cpp:59
bool Serialize(FILE *fp) const

◆ SparseSize()

virtual int tesseract::IndexMap::SparseSize ( ) const
inlinevirtual

Reimplemented in tesseract::IndexMapBiDi.

Definition at line 57 of file indexmapbidi.h.

57  {
58  return sparse_size_;
59  }

◆ SparseToCompact()

int tesseract::IndexMap::SparseToCompact ( int  sparse_index) const
virtual

Reimplemented in tesseract::IndexMapBiDi.

Definition at line 32 of file indexmapbidi.cpp.

32  {
33  int result = compact_map_.binary_search(sparse_index);
34  return compact_map_[result] == sparse_index ? result : -1;
35 }
GenericVector< int32_t > compact_map_
Definition: indexmapbidi.h:80
int binary_search(const T &target) const

Member Data Documentation

◆ compact_map_

GenericVector<int32_t> tesseract::IndexMap::compact_map_
protected

Definition at line 80 of file indexmapbidi.h.

◆ sparse_size_

int32_t tesseract::IndexMap::sparse_size_
protected

Definition at line 77 of file indexmapbidi.h.


The documentation for this class was generated from the following files: