tesseract  4.00.00dev
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

int sparse_size_
 
GenericVector< inT32compact_map_
 

Detailed Description

Definition at line 42 of file indexmapbidi.h.

Constructor & Destructor Documentation

◆ ~IndexMap()

virtual tesseract::IndexMap::~IndexMap ( )
inlinevirtual

Definition at line 44 of file indexmapbidi.h.

44 {}

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  }
GenericVector< inT32 > compact_map_
Definition: indexmapbidi.h:80
int size() const
Definition: genericvector.h:72

◆ 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 > compact_map_
Definition: indexmapbidi.h:80

◆ CopyFrom() [1/2]

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

Definition at line 33 of file indexmapbidi.cpp.

33  {
34  sparse_size_ = src.sparse_size_;
35  compact_map_ = src.compact_map_;
36 }
GenericVector< inT32 > compact_map_
Definition: indexmapbidi.h:80

◆ CopyFrom() [2/2]

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

Definition at line 37 of file indexmapbidi.cpp.

37  {
38  sparse_size_ = src.SparseSize();
39  compact_map_ = src.compact_map_;
40 }
GenericVector< inT32 > compact_map_
Definition: indexmapbidi.h:80

◆ DeSerialize()

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

Definition at line 52 of file indexmapbidi.cpp.

52  {
53  inT32 sparse_size;
54  if (fread(&sparse_size, sizeof(sparse_size), 1, fp) != 1) return false;
55  if (swap)
56  ReverseN(&sparse_size, sizeof(sparse_size));
57  sparse_size_ = sparse_size;
58  if (!compact_map_.DeSerialize(swap, fp)) return false;
59  return true;
60 }
bool DeSerialize(bool swap, FILE *fp)
int32_t inT32
Definition: host.h:38
GenericVector< inT32 > compact_map_
Definition: indexmapbidi.h:80
void ReverseN(void *ptr, int num_bytes)
Definition: helpers.h:184

◆ Serialize()

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

Definition at line 43 of file indexmapbidi.cpp.

43  {
44  inT32 sparse_size = sparse_size_;
45  if (fwrite(&sparse_size, sizeof(sparse_size), 1, fp) != 1) return false;
46  if (!compact_map_.Serialize(fp)) return false;
47  return true;
48 }
int32_t inT32
Definition: host.h:38
GenericVector< inT32 > compact_map_
Definition: indexmapbidi.h:80
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 27 of file indexmapbidi.cpp.

27  {
28  int result = compact_map_.binary_search(sparse_index);
29  return compact_map_[result] == sparse_index ? result : -1;
30 }
GenericVector< inT32 > compact_map_
Definition: indexmapbidi.h:80
int binary_search(const T &target) const

Member Data Documentation

◆ compact_map_

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

Definition at line 80 of file indexmapbidi.h.

◆ sparse_size_

int tesseract::IndexMap::sparse_size_
protected

Definition at line 77 of file indexmapbidi.h.


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