tesseract v5.3.3.20231005
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_
 
std::vector< int32_t > compact_map_
 

Detailed Description

Definition at line 44 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 63 of file indexmapbidi.h.

63 {
64 return compact_map_.size();
65 }
std::vector< int32_t > compact_map_
Definition: indexmapbidi.h:82

◆ CompactToSparse()

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

Definition at line 55 of file indexmapbidi.h.

55 {
56 return compact_map_[compact_index];
57 }

◆ CopyFrom() [1/2]

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

Definition at line 43 of file indexmapbidi.cpp.

43 {
44 sparse_size_ = src.sparse_size_;
45 compact_map_ = src.compact_map_;
46}

◆ CopyFrom() [2/2]

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

Definition at line 47 of file indexmapbidi.cpp.

47 {
48 sparse_size_ = src.SparseSize();
49 compact_map_ = src.compact_map_;
50}

◆ DeSerialize()

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

Definition at line 59 of file indexmapbidi.cpp.

59 {
60 uint32_t sparse_size;
61 if (!tesseract::DeSerialize(fp, &sparse_size)) {
62 return false;
63 }
64 if (swap) {
65 ReverseN(&sparse_size, sizeof(sparse_size));
66 }
67 // Arbitrarily limit the number of elements to protect against bad data.
68 if (sparse_size > UINT16_MAX) {
69 return false;
70 }
71 sparse_size_ = sparse_size;
72 return tesseract::DeSerialize(swap, fp, compact_map_);
73}
void ReverseN(void *ptr, int num_bytes)
Definition: helpers.h:184
bool DeSerialize(bool swap, FILE *fp, std::vector< T > &data)
Definition: helpers.h:205

◆ Serialize()

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

Definition at line 53 of file indexmapbidi.cpp.

53 {
55}
bool Serialize(FILE *fp, const std::vector< T > &data)
Definition: helpers.h:236

◆ SparseSize()

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

Reimplemented in tesseract::IndexMapBiDi.

Definition at line 59 of file indexmapbidi.h.

59 {
60 return sparse_size_;
61 }

◆ SparseToCompact()

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

Reimplemented in tesseract::IndexMapBiDi.

Definition at line 33 of file indexmapbidi.cpp.

33 {
34 auto pos = std::upper_bound(compact_map_.begin(), compact_map_.end(), sparse_index);
35 if (pos > compact_map_.begin()) {
36 --pos;
37 }
38 auto result = pos - compact_map_.begin();
39 return compact_map_[result] == sparse_index ? result : -1;
40}

Member Data Documentation

◆ compact_map_

std::vector<int32_t> tesseract::IndexMap::compact_map_
protected

Definition at line 82 of file indexmapbidi.h.

◆ sparse_size_

int32_t tesseract::IndexMap::sparse_size_
protected

Definition at line 79 of file indexmapbidi.h.


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