Replace uses of the VC++ non-standard std::hash_map with C++ standard std::unordered_map type in the HTKMLFReader

This commit is contained in:
Amit Agarwal 2015-09-01 22:07:15 -07:00
Родитель 6f0526ea93
Коммит b1ccf91f85
8 изменённых файлов: 14 добавлений и 33 удалений

Просмотреть файл

@ -53,10 +53,6 @@ typedef void* HANDLE;
#define VOID void
#define CONST const
//standard library conversion
//#define min std::min
#define hash_map unordered_map
//macro conversion
#define __forceinline inline
//string and io conversion

Просмотреть файл

@ -14,7 +14,7 @@
#include <string>
#include <regex>
#include <set>
#include <hash_map>
#include <unordered_map>
#include <stdint.h>
#include <limits.h>
#include <wchar.h>
@ -659,7 +659,7 @@ private:
public:
// parse format with original HTK state align MLF format and state list
void parsewithstatelist (const vector<char*> & toks, const hash_map<std::string, size_t> & statelisthash, const double htkTimeToFrame)
void parsewithstatelist (const vector<char*> & toks, const unordered_map<std::string, size_t> & statelisthash, const double htkTimeToFrame)
{
size_t ts, te;
parseframerange (toks, ts, te, htkTimeToFrame);
@ -686,7 +686,7 @@ template<class ENTRY, class WORDSEQUENCE>
class htkmlfreader : public map<wstring,vector<ENTRY>> // [key][i] the data
{
wstring curpath; // for error messages
hash_map<std::string, size_t> statelistmap; // for state <=> index
unordered_map<std::string, size_t> statelistmap; // for state <=> index
map<wstring,WORDSEQUENCE> wordsequences; // [key] word sequences (if we are building word entries as well, for MMI)
void strtok (char * s, const char * delim, vector<char*> & toks)

Просмотреть файл

@ -18,7 +18,7 @@
#include <vector>
#include <string>
#include <set>
#include <hash_map>
#include <unordered_map>
#include <regex>
#pragma warning(disable : 4996)
@ -95,20 +95,6 @@ static size_t tryfind (const MAPTYPE & map, const KEYTYPE & key, VALTYPE deflt)
const msra::asr::htkmlfreader<msra::asr::htkmlfentry,msra::lattices::lattice::htkmlfwordsequence> & labels, // non-empty: build numer lattices
const msra::lm::CMGramLM & unigram, const msra::lm::CSymbolSet & unigramsymbols) // for numer lattices
{
#if 0 // little unit test helper for testing the read function
bool test = true;
if (test)
{
archive a;
a.open (outpath + L".toc");
lattice L;
std::hash_map<string,size_t> symmap;
a.getlattice (L"sw2001_A_1263622500_1374610000", L, symmap);
a.getlattice (L"sw2001_A_1391162500_1409287500", L, symmap);
return;
}
#endif
const bool numermode = !labels.empty(); // if labels are passed then we shall convert the MLFs to lattices, and 'infiles' are regular keys
const std::wstring tocpath = outpath + L".toc";

Просмотреть файл

@ -22,7 +22,6 @@
#include <stdint.h>
#include <vector>
#include <string>
#include <hash_map>
#include <unordered_map>
#include <algorithm> // for find()
#include "simplesenonehmm.h"
@ -1079,7 +1078,7 @@ class archive
mutable size_t currentarchiveindex; // which archive is open
mutable auto_file_ptr f; // cached archive file handle of currentarchiveindex
hash_map<std::wstring,latticeref> toc; // [key] -> (file, offset) --table of content (.toc file)
unordered_map<std::wstring, latticeref> toc; // [key] -> (file, offset) --table of content (.toc file)
public:
// construct = open the archive
//archive() : currentarchiveindex (SIZE_MAX) {}

Просмотреть файл

@ -12,7 +12,7 @@
#include "fileutil.h" // for opening/reading the ARPA file
#include <vector>
#include <string>
#include <hash_map>
#include <unordered_map>
#include <algorithm> // for various sort() calls
#include <math.h>
@ -85,7 +85,7 @@ static inline double invertlogprob (double logP) { return logclip (1.0 - exp (lo
// CSymbolSet -- a simple symbol table
// ===========================================================================
// compare function to allow char* as keys (without, hash_map will correctly
// compare function to allow char* as keys (without, unordered_map will correctly
// compute a hash key from the actual strings, but then compare the pointers
// -- duh!)
struct less_strcmp : public binary_function<const char *, const char *, bool>
@ -94,7 +94,7 @@ struct less_strcmp : public binary_function<const char *, const char *, bool>
{ return strcmp (_Left, _Right) < 0; }
};
class CSymbolSet : public stdext::hash_map<const char *, int, stdext::hash_compare<const char*,less_strcmp>>
class CSymbolSet : public std::unordered_map<const char *, int, std::hash<const char*>, less_strcmp>
{
vector<const char *> symbols; // the symbols
@ -106,14 +106,14 @@ public:
void clear()
{
foreach_index (i, symbols) free ((void*) symbols[i]);
hash_map::clear();
unordered_map::clear();
}
// operator[key] on a 'const' object
// get id for an existing word, returns -1 if not existing
int operator[] (const char * key) const
{
hash_map<const char *,int>::const_iterator iter = find (key);
unordered_map<const char *, int>::const_iterator iter = find(key);
return (iter != end()) ? iter->second : -1;
}
@ -121,7 +121,7 @@ public:
// determine unique id for a word ('key')
int operator[] (const char * key)
{
hash_map<const char *,int>::const_iterator iter = find (key);
unordered_map<const char *, int>::const_iterator iter = find(key);
if (iter != end())
return iter->second;

Просмотреть файл

@ -64,7 +64,7 @@ public: // (TODO: better encapsulation)
transP() : numstates (0) {}
};
std::vector<transP> transPs; // the transition matrices --TODO: finish this
std::hash_map<std::string,size_t> transPmap; // [transPname] -> index into transPs[]
std::unordered_map<std::string, size_t> transPmap; // [transPname] -> index into transPs[]
public:
// get an hmm by index
const hmm & gethmm (size_t i) const { return hmms[i]; }

Просмотреть файл

@ -199,7 +199,7 @@ class minibatchutterancesource : public minibatchsource
}
};
std::vector<utteranceref> randomizedutterancerefs; // [pos] randomized utterance ids
std::hash_map<size_t,size_t> randomizedutteranceposmap; // [globalts] -> pos lookup table
std::unordered_map<size_t, size_t> randomizedutteranceposmap; // [globalts] -> pos lookup table
struct positionchunkwindow // chunk window required in memory when at a certain position, for controlling paging
{
std::vector<chunk>::iterator definingchunk; // the chunk in randomizedchunks[] that defined the utterance position of this utterance

Просмотреть файл

@ -208,7 +208,7 @@ class minibatchutterancesourcemulti : public minibatchsource
}
};
std::vector<utteranceref> randomizedutterancerefs; // [pos] randomized utterance ids
std::hash_map<size_t,size_t> randomizedutteranceposmap; // [globalts] -> pos lookup table
std::unordered_map<size_t, size_t> randomizedutteranceposmap; // [globalts] -> pos lookup table
struct positionchunkwindow // chunk window required in memory when at a certain position, for controlling paging
{
std::vector<chunk>::iterator definingchunk; // the chunk in randomizedchunks[] that defined the utterance position of this utterance