All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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< bool > quick_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

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

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

Constructor & Destructor Documentation

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's (removes duplicates) from a vector.
Definition: stl-utils.h:39
std::vector< I > slow_set_
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 ( 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

iterator begin ( ) const
inline
int count ( i) const
bool empty ( ) const
inline

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

77 { return slow_set_.empty(); }
std::vector< I > slow_set_
iterator end ( ) const
inline
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's (removes duplicates) from a vector.
Definition: stl-utils.h:39
std::vector< I > slow_set_
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_
void InitInternal ( )
private

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

References rnnlm::i, and KALDI_ASSERT_IS_INTEGER_TYPE.

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:129
std::vector< I > slow_set_
std::vector< bool > quick_set_
void Read ( std::istream &  is,
bool  binary 
)

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

References kaldi::ReadIntegerVector().

Referenced by 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_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_
void Write ( std::ostream &  os,
bool  binary 
) const

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

References kaldi::WriteIntegerVector().

Referenced by kaldi::TestSetOfNumbers(), and SplitEventMap::Write().

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

bool contiguous_
private

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

I highest_member_
private

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

I lowest_member_
private

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

bool quick_
private

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

std::vector<bool> quick_set_
private

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


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