All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
SplitEventMap Class Reference

#include <event-map.h>

Inheritance diagram for SplitEventMap:
Collaboration diagram for SplitEventMap:

Public Member Functions

virtual bool Map (const EventType &event, EventAnswerType *ans) const
 
virtual void MultiMap (const EventType &event, std::vector< EventAnswerType > *ans) const
 
virtual void GetChildren (std::vector< EventMap * > *out) const
 
virtual EventMapCopy (const std::vector< EventMap * > &new_leaves) const
 
virtual void Write (std::ostream &os, bool binary)
 Write to stream. More...
 
virtual EventMapPrune () const
 
virtual EventMapMapValues (const unordered_set< EventKeyType > &keys_to_map, const unordered_map< EventValueType, EventValueType > &value_map) const
 
virtual ~SplitEventMap ()
 
 SplitEventMap (EventKeyType key, const std::vector< EventValueType > &yes_set, EventMap *yes, EventMap *no)
 This constructor takes ownership of the "yes" and "no" arguments. More...
 
- Public Member Functions inherited from EventMap
EventMapCopy () const
 
virtual EventAnswerType MaxResult () const
 
virtual ~EventMap ()
 

Static Public Member Functions

static SplitEventMapRead (std::istream &is, bool binary)
 
- Static Public Member Functions inherited from EventMap
static void Check (const EventType &event)
 
static bool Lookup (const EventType &event, EventKeyType key, EventValueType *ans)
 
static void Write (std::ostream &os, bool binary, EventMap *emap)
 a Write function that takes care of NULL pointers. More...
 
static EventMapRead (std::istream &is, bool binary)
 a Read function that reads an arbitrary EventMap; also works for NULL pointers. More...
 

Private Member Functions

 SplitEventMap (EventKeyType key, const ConstIntegerSet< EventValueType > &yes_set, EventMap *yes, EventMap *no)
 This constructor used in the Copy() function. More...
 
void Destroy ()
 
SplitEventMapoperator= (const SplitEventMap &other)
 

Private Attributes

EventKeyType key_
 
ConstIntegerSet< EventValueTypeyes_set_
 
EventMapyes_
 
EventMapno_
 

Detailed Description

Definition at line 269 of file event-map.h.

Constructor & Destructor Documentation

virtual ~SplitEventMap ( )
inlinevirtual

Definition at line 316 of file event-map.h.

References SplitEventMap::Destroy().

316 { Destroy(); }
SplitEventMap ( EventKeyType  key,
const std::vector< EventValueType > &  yes_set,
EventMap yes,
EventMap no 
)
inline

This constructor takes ownership of the "yes" and "no" arguments.

Definition at line 319 of file event-map.h.

References kaldi::IsSorted(), KALDI_ASSERT, KALDI_PARANOID_ASSERT, SplitEventMap::no_, and SplitEventMap::yes_.

Referenced by SplitEventMap::Copy(), SplitEventMap::MapValues(), SplitEventMap::Prune(), and SplitEventMap::Read().

320  : key_(key), yes_set_(yes_set), yes_(yes), no_(no) {
322  KALDI_ASSERT(yes_ != NULL && no_ != NULL);
323  }
EventKeyType key_
Definition: event-map.h:335
#define KALDI_PARANOID_ASSERT(cond)
Definition: kaldi-error.h:182
ConstIntegerSet< EventValueType > yes_set_
Definition: event-map.h:337
bool IsSorted(const std::vector< T > &vec)
Returns true if the vector is sorted.
Definition: stl-utils.h:47
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:169
SplitEventMap ( EventKeyType  key,
const ConstIntegerSet< EventValueType > &  yes_set,
EventMap yes,
EventMap no 
)
inlineprivate

This constructor used in the Copy() function.

Definition at line 328 of file event-map.h.

References KALDI_ASSERT, SplitEventMap::no_, and SplitEventMap::yes_.

329  : key_(key), yes_set_(yes_set), yes_(yes), no_(no) {
330  KALDI_ASSERT(yes_ != NULL && no_ != NULL);
331  }
EventKeyType key_
Definition: event-map.h:335
ConstIntegerSet< EventValueType > yes_set_
Definition: event-map.h:337
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:169

Member Function Documentation

virtual EventMap* Copy ( const std::vector< EventMap * > &  new_leaves) const
inlinevirtual

Implements EventMap.

Definition at line 303 of file event-map.h.

References EventMap::Copy(), SplitEventMap::key_, SplitEventMap::no_, SplitEventMap::SplitEventMap(), SplitEventMap::yes_, and SplitEventMap::yes_set_.

303  {
304  return new SplitEventMap(key_, yes_set_, yes_->Copy(new_leaves), no_->Copy(new_leaves));
305  }
EventKeyType key_
Definition: event-map.h:335
SplitEventMap(EventKeyType key, const std::vector< EventValueType > &yes_set, EventMap *yes, EventMap *no)
This constructor takes ownership of the "yes" and "no" arguments.
Definition: event-map.h:319
virtual EventMap * Copy(const std::vector< EventMap * > &new_leaves) const =0
ConstIntegerSet< EventValueType > yes_set_
Definition: event-map.h:337
void Destroy ( )
inlineprivate

Definition at line 332 of file event-map.h.

References SplitEventMap::no_, and SplitEventMap::yes_.

Referenced by SplitEventMap::~SplitEventMap().

332  {
333  delete yes_; delete no_;
334  }
virtual void GetChildren ( std::vector< EventMap * > *  out) const
inlinevirtual

Implements EventMap.

Definition at line 297 of file event-map.h.

References SplitEventMap::no_, and SplitEventMap::yes_.

297  {
298  out->clear();
299  out->push_back(yes_);
300  out->push_back(no_);
301  }
virtual bool Map ( const EventType event,
EventAnswerType ans 
) const
inlinevirtual

Implements EventMap.

Definition at line 272 of file event-map.h.

References ConstIntegerSet< I >::count(), SplitEventMap::key_, EventMap::Lookup(), EventMap::Map(), SplitEventMap::no_, SplitEventMap::yes_, and SplitEventMap::yes_set_.

272  {
273  EventValueType value;
274  if (Lookup(event, key_, &value)) {
275  // if (std::binary_search(yes_set_.begin(), yes_set_.end(), value)) {
276  if (yes_set_.count(value)) {
277  return yes_->Map(event, ans);
278  }
279  return no_->Map(event, ans);
280  }
281  return false;
282  }
EventKeyType key_
Definition: event-map.h:335
virtual bool Map(const EventType &event, EventAnswerType *ans) const =0
ConstIntegerSet< EventValueType > yes_set_
Definition: event-map.h:337
static bool Lookup(const EventType &event, EventKeyType key, EventValueType *ans)
Definition: event-map.cc:290
int32 EventValueType
Given current code, things of type EventValueType should generally be nonnegative and in a reasonably...
Definition: event-map.h:51
EventMap * MapValues ( const unordered_set< EventKeyType > &  keys_to_map,
const unordered_map< EventValueType, EventValueType > &  value_map 
) const
virtual

Implements EventMap.

Definition at line 165 of file event-map.cc.

References ConstIntegerSet< I >::begin(), ConstIntegerSet< I >::end(), KALDI_ERR, SplitEventMap::key_, EventMap::MapValues(), SplitEventMap::no_, kaldi::SortAndUniq(), SplitEventMap::SplitEventMap(), SplitEventMap::yes_, and SplitEventMap::yes_set_.

167  {
168  EventMap *yes = yes_->MapValues(keys_to_map, value_map),
169  *no = no_->MapValues(keys_to_map, value_map);
170 
171  if (keys_to_map.count(key_) == 0) {
172  return new SplitEventMap(key_, yes_set_, yes, no);
173  } else {
174  std::vector<EventValueType> yes_set;
176  iter != yes_set_.end();
177  ++iter) {
178  EventValueType value = *iter;
179  unordered_map<EventValueType, EventValueType>::const_iterator
180  map_iter = value_map.find(value);
181  if (map_iter == value_map.end())
182  KALDI_ERR << "Value " << value << ", for key "
183  << key_ << ", cannot be mapped.";
184  EventValueType mapped_value = map_iter->second;
185  yes_set.push_back(mapped_value);
186  }
187  SortAndUniq(&yes_set);
188  return new SplitEventMap(key_, yes_set, yes, no);
189  }
190 }
EventKeyType key_
Definition: event-map.h:335
iterator begin() const
void SortAndUniq(std::vector< T > *vec)
Sorts and uniq's (removes duplicates) from a vector.
Definition: stl-utils.h:39
iterator end() const
SplitEventMap(EventKeyType key, const std::vector< EventValueType > &yes_set, EventMap *yes, EventMap *no)
This constructor takes ownership of the "yes" and "no" arguments.
Definition: event-map.h:319
#define KALDI_ERR
Definition: kaldi-error.h:127
virtual EventMap * MapValues(const unordered_set< EventKeyType > &keys_to_map, const unordered_map< EventValueType, EventValueType > &value_map) const =0
ConstIntegerSet< EventValueType > yes_set_
Definition: event-map.h:337
std::vector< EventValueType >::const_iterator iterator
int32 EventValueType
Given current code, things of type EventValueType should generally be nonnegative and in a reasonably...
Definition: event-map.h:51
virtual void MultiMap ( const EventType event,
std::vector< EventAnswerType > *  ans 
) const
inlinevirtual

Implements EventMap.

Definition at line 284 of file event-map.h.

References ConstIntegerSet< I >::begin(), ConstIntegerSet< I >::end(), SplitEventMap::key_, EventMap::Lookup(), EventMap::MultiMap(), SplitEventMap::no_, SplitEventMap::yes_, and SplitEventMap::yes_set_.

284  {
285  EventValueType tmp;
286  if (Lookup(event, key_, &tmp)) {
287  if (std::binary_search(yes_set_.begin(), yes_set_.end(), tmp))
288  yes_->MultiMap(event, ans);
289  else
290  no_->MultiMap(event, ans);
291  } else { // both yes and no contribute.
292  yes_->MultiMap(event, ans);
293  no_->MultiMap(event, ans);
294  }
295  }
EventKeyType key_
Definition: event-map.h:335
iterator begin() const
iterator end() const
ConstIntegerSet< EventValueType > yes_set_
Definition: event-map.h:337
static bool Lookup(const EventType &event, EventKeyType key, EventValueType *ans)
Definition: event-map.cc:290
int32 EventValueType
Given current code, things of type EventValueType should generally be nonnegative and in a reasonably...
Definition: event-map.h:51
virtual void MultiMap(const EventType &event, std::vector< EventAnswerType > *ans) const =0
SplitEventMap& operator= ( const SplitEventMap other)
private
EventMap * Prune ( ) const
virtual

Implements EventMap.

Definition at line 156 of file event-map.cc.

References SplitEventMap::key_, SplitEventMap::no_, EventMap::Prune(), SplitEventMap::SplitEventMap(), SplitEventMap::yes_, and SplitEventMap::yes_set_.

156  {
157  EventMap *yes = yes_->Prune(),
158  *no = no_->Prune();
159  if (yes == NULL && no == NULL) return NULL;
160  else if (yes == NULL) return no;
161  else if (no == NULL) return yes;
162  else return new SplitEventMap(key_, yes_set_, yes, no);
163 }
EventKeyType key_
Definition: event-map.h:335
SplitEventMap(EventKeyType key, const std::vector< EventValueType > &yes_set, EventMap *yes, EventMap *no)
This constructor takes ownership of the "yes" and "no" arguments.
Definition: event-map.h:319
ConstIntegerSet< EventValueType > yes_set_
Definition: event-map.h:337
virtual EventMap * Prune() const =0
SplitEventMap * Read ( std::istream &  is,
bool  binary 
)
static

Definition at line 209 of file event-map.cc.

References kaldi::ExpectToken(), KALDI_ERR, ConstIntegerSet< I >::Read(), EventMap::Read(), kaldi::ReadBasicType(), and SplitEventMap::SplitEventMap().

Referenced by EventMap::Read().

209  {
210  ExpectToken(is, binary, "SE");
211  EventKeyType key;
212  ReadBasicType(is, binary, &key);
213  // std::vector<EventValueType> yes_set;
214  // ReadIntegerVector(is, binary, &yes_set);
215  ConstIntegerSet<EventValueType> yes_set;
216  yes_set.Read(is, binary);
217  ExpectToken(is, binary, "{");
218  EventMap *yes = EventMap::Read(is, binary);
219  EventMap *no = EventMap::Read(is, binary);
220  ExpectToken(is, binary, "}");
221  // yes and no should be non-NULL because NULL values are not valid for SplitEventMap;
222  // the constructor checks this. Therefore this is an unlikely error.
223  if (yes == NULL || no == NULL) KALDI_ERR << "SplitEventMap::Read, NULL pointers.";
224  return new SplitEventMap(key, yes_set, yes, no);
225 }
void ReadBasicType(std::istream &is, bool binary, T *t)
ReadBasicType is the name of the read function for bool, integer types, and floating-point types...
Definition: io-funcs-inl.h:55
static EventMap * Read(std::istream &is, bool binary)
a Read function that reads an arbitrary EventMap; also works for NULL pointers.
Definition: event-map.cc:36
SplitEventMap(EventKeyType key, const std::vector< EventValueType > &yes_set, EventMap *yes, EventMap *no)
This constructor takes ownership of the "yes" and "no" arguments.
Definition: event-map.h:319
void ExpectToken(std::istream &is, bool binary, const char *token)
ExpectToken tries to read in the given token, and throws an exception on failure. ...
Definition: io-funcs.cc:188
int32 EventKeyType
Things of type EventKeyType can take any value.
Definition: event-map.h:45
#define KALDI_ERR
Definition: kaldi-error.h:127
void Write ( std::ostream &  os,
bool  binary 
)
virtual

Write to stream.

Implements EventMap.

Definition at line 192 of file event-map.cc.

References KALDI_ASSERT, KALDI_ERR, SplitEventMap::key_, SplitEventMap::no_, ConstIntegerSet< I >::Write(), EventMap::Write(), kaldi::WriteBasicType(), kaldi::WriteToken(), SplitEventMap::yes_, and SplitEventMap::yes_set_.

192  {
193  WriteToken(os, binary, "SE");
194  WriteBasicType(os, binary, key_);
195  // WriteIntegerVector(os, binary, yes_set_);
196  yes_set_.Write(os, binary);
197  KALDI_ASSERT(yes_ != NULL && no_ != NULL);
198  WriteToken(os, binary, "{");
199  yes_->Write(os, binary);
200  no_->Write(os, binary);
201  WriteToken(os, binary, "}");
202  if (!binary) os << '\n';
203  if (os.fail()) {
204  KALDI_ERR << "SplitEventMap::Write(), could not write to stream.";
205  }
206 }
EventKeyType key_
Definition: event-map.h:335
void Write(std::ostream &os, bool binary) const
#define KALDI_ERR
Definition: kaldi-error.h:127
ConstIntegerSet< EventValueType > yes_set_
Definition: event-map.h:337
void WriteToken(std::ostream &os, bool binary, const char *token)
The WriteToken functions are for writing nonempty sequences of non-space characters.
Definition: io-funcs.cc:134
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:169
void WriteBasicType(std::ostream &os, bool binary, T t)
WriteBasicType is the name of the write function for bool, integer types, and floating-point types...
Definition: io-funcs-inl.h:34
virtual void Write(std::ostream &os, bool binary)=0
Write to stream.

Member Data Documentation


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