ConstIntegerSet< I > Class Template Reference

#include <const-integer-set.h>

Collaboration diagram for ConstIntegerSet< I >:

Public Types

typedef std::vector< I >::const_iterator iterator
 

Public Member Functions

 ConstIntegerSet ()
 
void Init (const std::vector< I > &input)
 
void Init (const std::set< I > &input)
 
 ConstIntegerSet (const std::vector< I > &input)
 
 ConstIntegerSet (const std::set< I > &input)
 
 ConstIntegerSet (const ConstIntegerSet< I > &other)
 
int count (I i) const
 
iterator begin () const
 
iterator end () const
 
size_t size () const
 
bool empty () const
 
void Write (std::ostream &os, bool binary) const
 
void Read (std::istream &is, bool binary)
 

Private Member Functions

void InitInternal ()
 

Private Attributes

lowest_member_
 
highest_member_
 
bool contiguous_
 
bool quick_
 
std::vector< boolquick_set_
 
std::vector< I > slow_set_
 

Detailed Description

template<class I>
class kaldi::ConstIntegerSet< I >

Definition at line 43 of file const-integer-set.h.

Member Typedef Documentation

◆ iterator

typedef std::vector<I>::const_iterator iterator

Definition at line 73 of file const-integer-set.h.

Constructor & Destructor Documentation

◆ ConstIntegerSet() [1/4]

◆ ConstIntegerSet() [2/4]

ConstIntegerSet ( const std::vector< I > &  input)
inlineexplicit

Definition at line 58 of file const-integer-set.h.

58  : slow_set_(input) {
60  InitInternal();
61  }
void SortAndUniq(std::vector< T > *vec)
Sorts and uniq&#39;s (removes duplicates) from a vector.
Definition: stl-utils.h:39
std::vector< I > slow_set_

◆ ConstIntegerSet() [3/4]

ConstIntegerSet ( const std::set< I > &  input)
inlineexplicit

Definition at line 62 of file const-integer-set.h.

62  {
63  CopySetToVector(input, &slow_set_);
64  InitInternal();
65  }
void CopySetToVector(const std::set< T > &s, std::vector< T > *v)
Copies the elements of a set to a vector.
Definition: stl-utils.h:86
std::vector< I > slow_set_

◆ ConstIntegerSet() [4/4]

ConstIntegerSet ( const ConstIntegerSet< I > &  other)
inlineexplicit

Definition at line 66 of file const-integer-set.h.

66  :
67  slow_set_(other.slow_set_) {
68  InitInternal();
69  }
std::vector< I > slow_set_

Member Function Documentation

◆ begin()

iterator begin ( ) const
inline

Definition at line 74 of file const-integer-set.h.

Referenced by TreeRenderer::MakeEdgeLabel(), SplitEventMap::MapValues(), and kaldi::TestSetOfNumbers().

74 { return slow_set_.begin(); }
std::vector< I > slow_set_

◆ count()

int count ( i) const

Definition at line 62 of file const-integer-set-inl.h.

Referenced by ConstIntegerSet< EventValueType >::ConstIntegerSet(), OnlineFasterDecoder::EndOfUtterance(), InverseLeftBiphoneContextFst::Final(), InverseLeftBiphoneContextFst::GetArc(), InverseContextFst::InverseContextFst(), InverseContextFst::IsDisambigSymbol(), InverseContextFst::IsPhoneSymbol(), fst::MakePrecedingInputSymbolsSameClass(), fst::PenalizeArcsWithSomeInputSymbols(), fst::RemoveArcsWithSomeInputSymbols(), TreeRenderer::RenderSplit(), kaldi::TestSetOfNumbers(), kaldi::WeightSilencePost(), and kaldi::WeightSilencePostDistributed().

62  {
63  if (i < lowest_member_ || i > highest_member_) {
64  return 0;
65  } else {
66  if (contiguous_) return true;
67  if (quick_) {
68  return (quick_set_[i-lowest_member_] ? 1 : 0);
69  } else {
70  bool ans = std::binary_search(slow_set_.begin(), slow_set_.end(), i);
71  return (ans ? 1 : 0);
72  }
73  }
74 }
std::vector< I > slow_set_
std::vector< bool > quick_set_

◆ empty()

bool empty ( ) const
inline

◆ end()

iterator end ( ) const
inline

Definition at line 75 of file const-integer-set.h.

Referenced by TreeRenderer::MakeEdgeLabel(), and kaldi::TestSetOfNumbers().

75 { return slow_set_.end(); }
std::vector< I > slow_set_

◆ Init() [1/2]

void Init ( const std::vector< I > &  input)
inline

Definition at line 47 of file const-integer-set.h.

Referenced by kaldi::TestSetOfNumbers().

47  {
48  slow_set_ = input;
50  InitInternal();
51  }
void SortAndUniq(std::vector< T > *vec)
Sorts and uniq&#39;s (removes duplicates) from a vector.
Definition: stl-utils.h:39
std::vector< I > slow_set_

◆ Init() [2/2]

void Init ( const std::set< I > &  input)
inline

Definition at line 53 of file const-integer-set.h.

53  {
54  CopySetToVector(input, &slow_set_);
55  InitInternal();
56  }
void CopySetToVector(const std::set< T > &s, std::vector< T > *v)
Copies the elements of a set to a vector.
Definition: stl-utils.h:86
std::vector< I > slow_set_

◆ InitInternal()

void InitInternal ( )
private

Definition at line 30 of file const-integer-set-inl.h.

Referenced by ConstIntegerSet< EventValueType >::ConstIntegerSet(), and ConstIntegerSet< EventValueType >::Init().

30  {
32  quick_set_.clear(); // just in case we previously had data.
33  if (slow_set_.size() == 0) {
34  lowest_member_=(I) 1;
35  highest_member_=(I) 0;
36  contiguous_ = false;
37  quick_ = false;
38  } else {
39  lowest_member_ = slow_set_.front();
40  highest_member_ = slow_set_.back();
41  size_t range = highest_member_ + 1 - lowest_member_;
42  if (range == slow_set_.size()) {
43  contiguous_ = true;
44  quick_= false;
45  } else {
46  contiguous_ = false;
47  // If it would be more compact to store as bool
48  if (range < slow_set_.size() * 8 * sizeof(I)) {
49  // (assuming 1 bit per element)...
50  quick_set_.resize(range, false);
51  for (size_t i = 0;i < slow_set_.size();i++)
52  quick_set_[slow_set_[i] - lowest_member_] = true;
53  quick_ = true;
54  } else {
55  quick_ = false;
56  }
57  }
58  }
59 }
#define KALDI_ASSERT_IS_INTEGER_TYPE(I)
Definition: kaldi-utils.h:133
std::vector< I > slow_set_
std::vector< bool > quick_set_

◆ Read()

void Read ( std::istream &  is,
bool  binary 
)

Definition at line 82 of file const-integer-set-inl.h.

Referenced by ConstIntegerSet< EventValueType >::empty(), SplitEventMap::Read(), TreeRenderer::RenderSplit(), and kaldi::TestSetOfNumbers().

82  {
83  ReadIntegerVector(is, binary, &slow_set_);
84  InitInternal();
85 }
std::vector< I > slow_set_
void ReadIntegerVector(std::istream &is, bool binary, std::vector< T > *v)
Function for reading STL vector of integer types.
Definition: io-funcs-inl.h:232

◆ size()

size_t size ( ) const
inline

Definition at line 76 of file const-integer-set.h.

Referenced by kaldi::TestSetOfNumbers().

76 { return slow_set_.size(); }
std::vector< I > slow_set_

◆ Write()

void Write ( std::ostream &  os,
bool  binary 
) const

Definition at line 77 of file const-integer-set-inl.h.

Referenced by ConstIntegerSet< EventValueType >::empty(), and kaldi::TestSetOfNumbers().

77  {
78  WriteIntegerVector(os, binary, slow_set_);
79 }
std::vector< I > slow_set_
void WriteIntegerVector(std::ostream &os, bool binary, const std::vector< T > &v)
Function for writing STL vectors of integer types.
Definition: io-funcs-inl.h:198

Member Data Documentation

◆ contiguous_

bool contiguous_
private

Definition at line 85 of file const-integer-set.h.

◆ highest_member_

I highest_member_
private

Definition at line 84 of file const-integer-set.h.

◆ lowest_member_

I lowest_member_
private

Definition at line 83 of file const-integer-set.h.

◆ quick_

bool quick_
private

Definition at line 86 of file const-integer-set.h.

◆ quick_set_

std::vector<bool> quick_set_
private

Definition at line 87 of file const-integer-set.h.

◆ slow_set_


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