Skip to content

Commit

Permalink
delete typedefs for UINT32 and UINT64. MSVC now has uint32_t and uint…
Browse files Browse the repository at this point in the history
…64_t /Ken
  • Loading branch information
hieuhoang committed Mar 25, 2015
1 parent cdc5e0f commit 1064aaa
Show file tree
Hide file tree
Showing 17 changed files with 148 additions and 155 deletions.
14 changes: 7 additions & 7 deletions OnDiskPt/OnDiskWrapper.cpp
Expand Up @@ -51,7 +51,7 @@ void OnDiskWrapper::BeginLoad(const std::string &filePath)
if (!m_vocab.Load(*this))
UTIL_THROW(util::FileOpenException, "Couldn't load vocab");

UINT64 rootFilePos = GetMisc("RootNodeOffset");
uint64_t rootFilePos = GetMisc("RootNodeOffset");
m_rootSourceNode = new PhraseNode(rootFilePos, *this);
}

Expand Down Expand Up @@ -102,7 +102,7 @@ bool OnDiskWrapper::LoadMisc()


const string &key = tokens[0];
m_miscInfo[key] = Moses::Scan<UINT64>(tokens[1]);
m_miscInfo[key] = Moses::Scan<uint64_t>(tokens[1]);
}

return true;
Expand Down Expand Up @@ -199,17 +199,17 @@ void OnDiskWrapper::SaveMisc()

size_t OnDiskWrapper::GetSourceWordSize() const
{
return sizeof(UINT64) + sizeof(char);
return sizeof(uint64_t) + sizeof(char);
}

size_t OnDiskWrapper::GetTargetWordSize() const
{
return sizeof(UINT64) + sizeof(char);
return sizeof(uint64_t) + sizeof(char);
}

UINT64 OnDiskWrapper::GetMisc(const std::string &key) const
uint64_t OnDiskWrapper::GetMisc(const std::string &key) const
{
std::map<std::string, UINT64>::const_iterator iter;
std::map<std::string, uint64_t>::const_iterator iter;
iter = m_miscInfo.find(key);
UTIL_THROW_IF2(iter == m_miscInfo.end()
, "Couldn't find value for key " << key
Expand Down Expand Up @@ -243,7 +243,7 @@ Word *OnDiskWrapper::ConvertFromMoses(const std::vector<Moses::FactorType> &fact
} // for (size_t factorType

bool found;
UINT64 vocabId = m_vocab.GetVocabId(strme.str(), found);
uint64_t vocabId = m_vocab.GetVocabId(strme.str(), found);
if (!found) {
// factor not in phrase table -> phrse definately not in. exit
delete newWord;
Expand Down
4 changes: 2 additions & 2 deletions OnDiskPt/OnDiskWrapper.h
Expand Up @@ -43,7 +43,7 @@ class OnDiskWrapper
size_t m_defaultNodeSize;
PhraseNode *m_rootSourceNode;

std::map<std::string, UINT64> m_miscInfo;
std::map<std::string, uint64_t> m_miscInfo;

void SaveMisc();
bool OpenForLoad(const std::string &filePath);
Expand Down Expand Up @@ -105,7 +105,7 @@ class OnDiskWrapper
return *m_rootSourceNode;
}

UINT64 GetMisc(const std::string &key) const;
uint64_t GetMisc(const std::string &key) const;

Word *ConvertFromMoses(const std::vector<Moses::FactorType> &factorsVec
, const Moses::Word &origWord) const;
Expand Down
42 changes: 21 additions & 21 deletions OnDiskPt/PhraseNode.cpp
Expand Up @@ -31,8 +31,8 @@ namespace OnDiskPt

size_t PhraseNode::GetNodeSize(size_t numChildren, size_t wordSize, size_t countSize)
{
size_t ret = sizeof(UINT64) * 2 // num children, value
+ (wordSize + sizeof(UINT64)) * numChildren // word + ptr to next source node
size_t ret = sizeof(uint64_t) * 2 // num children, value
+ (wordSize + sizeof(uint64_t)) * numChildren // word + ptr to next source node
+ sizeof(float) * countSize; // count info
return ret;
}
Expand All @@ -45,7 +45,7 @@ PhraseNode::PhraseNode()
{
}

PhraseNode::PhraseNode(UINT64 filePos, OnDiskWrapper &onDiskWrapper)
PhraseNode::PhraseNode(uint64_t filePos, OnDiskWrapper &onDiskWrapper)
:m_counts(onDiskWrapper.GetNumCounts())
{
// load saved node
Expand All @@ -55,26 +55,26 @@ PhraseNode::PhraseNode(UINT64 filePos, OnDiskWrapper &onDiskWrapper)

std::fstream &file = onDiskWrapper.GetFileSource();
file.seekg(filePos);
assert(filePos == (UINT64)file.tellg());
assert(filePos == (uint64_t)file.tellg());

file.read((char*) &m_numChildrenLoad, sizeof(UINT64));
file.read((char*) &m_numChildrenLoad, sizeof(uint64_t));

size_t memAlloc = GetNodeSize(m_numChildrenLoad, onDiskWrapper.GetSourceWordSize(), countSize);
m_memLoad = (char*) malloc(memAlloc);

// go to start of node again
file.seekg(filePos);
assert(filePos == (UINT64)file.tellg());
assert(filePos == (uint64_t)file.tellg());

// read everything into memory
file.read(m_memLoad, memAlloc);
assert(filePos + memAlloc == (UINT64)file.tellg());
assert(filePos + memAlloc == (uint64_t)file.tellg());

// get value
m_value = ((UINT64*)m_memLoad)[1];
m_value = ((uint64_t*)m_memLoad)[1];

// get counts
float *memFloat = (float*) (m_memLoad + sizeof(UINT64) * 2);
float *memFloat = (float*) (m_memLoad + sizeof(uint64_t) * 2);

assert(countSize == 1);
m_counts[0] = memFloat[0];
Expand Down Expand Up @@ -108,10 +108,10 @@ void PhraseNode::Save(OnDiskWrapper &onDiskWrapper, size_t pos, size_t tableLimi
//memset(mem, 0xfe, memAlloc);

size_t memUsed = 0;
UINT64 *memArray = (UINT64*) mem;
uint64_t *memArray = (uint64_t*) mem;
memArray[0] = GetSize(); // num of children
memArray[1] = m_value; // file pos of corresponding target phrases
memUsed += 2 * sizeof(UINT64);
memUsed += 2 * sizeof(uint64_t);

// count info
float *memFloat = (float*) (mem + memUsed);
Expand All @@ -133,9 +133,9 @@ void PhraseNode::Save(OnDiskWrapper &onDiskWrapper, size_t pos, size_t tableLimi
size_t wordMemUsed = childWord.WriteToMemory(currMem);
memUsed += wordMemUsed;

UINT64 *memArray = (UINT64*) (mem + memUsed);
uint64_t *memArray = (uint64_t*) (mem + memUsed);
memArray[0] = childNode.GetFilePos();
memUsed += sizeof(UINT64);
memUsed += sizeof(uint64_t);

}

Expand All @@ -148,7 +148,7 @@ void PhraseNode::Save(OnDiskWrapper &onDiskWrapper, size_t pos, size_t tableLimi
file.seekp(0, ios::end);
file.write(mem, memUsed);

UINT64 endPos = file.tellp();
uint64_t endPos = file.tellp();
assert(m_filePos + memUsed == endPos);

free(mem);
Expand Down Expand Up @@ -206,7 +206,7 @@ const PhraseNode *PhraseNode::GetChild(const Word &wordSought, OnDiskWrapper &on
x = (l + r) / 2;

Word wordFound;
UINT64 childFilePos;
uint64_t childFilePos;
GetChild(wordFound, childFilePos, x, onDiskWrapper);

if (wordSought == wordFound) {
Expand All @@ -222,30 +222,30 @@ const PhraseNode *PhraseNode::GetChild(const Word &wordSought, OnDiskWrapper &on
return ret;
}

void PhraseNode::GetChild(Word &wordFound, UINT64 &childFilePos, size_t ind, OnDiskWrapper &onDiskWrapper) const
void PhraseNode::GetChild(Word &wordFound, uint64_t &childFilePos, size_t ind, OnDiskWrapper &onDiskWrapper) const
{

size_t wordSize = onDiskWrapper.GetSourceWordSize();
size_t childSize = wordSize + sizeof(UINT64);
size_t childSize = wordSize + sizeof(uint64_t);

char *currMem = m_memLoad
+ sizeof(UINT64) * 2 // size & file pos of target phrase coll
+ sizeof(uint64_t) * 2 // size & file pos of target phrase coll
+ sizeof(float) * onDiskWrapper.GetNumCounts() // count info
+ childSize * ind;

size_t memRead = ReadChild(wordFound, childFilePos, currMem);
assert(memRead == childSize);
}

size_t PhraseNode::ReadChild(Word &wordFound, UINT64 &childFilePos, const char *mem) const
size_t PhraseNode::ReadChild(Word &wordFound, uint64_t &childFilePos, const char *mem) const
{
size_t memRead = wordFound.ReadFromMemory(mem);

const char *currMem = mem + memRead;
UINT64 *memArray = (UINT64*) (currMem);
uint64_t *memArray = (uint64_t*) (currMem);
childFilePos = memArray[0];

memRead += sizeof(UINT64);
memRead += sizeof(uint64_t);
return memRead;
}

Expand Down
18 changes: 9 additions & 9 deletions OnDiskPt/PhraseNode.h
Expand Up @@ -36,7 +36,7 @@ class PhraseNode
{
friend std::ostream& operator<<(std::ostream&, const PhraseNode&);
protected:
UINT64 m_filePos, m_value;
uint64_t m_filePos, m_value;

typedef std::map<Word, PhraseNode> ChildColl;
ChildColl m_children;
Expand All @@ -48,35 +48,35 @@ class PhraseNode
TargetPhraseCollection m_targetPhraseColl;

char *m_memLoad, *m_memLoadLast;
UINT64 m_numChildrenLoad;
uint64_t m_numChildrenLoad;

void AddTargetPhrase(size_t pos, const SourcePhrase &sourcePhrase
, TargetPhrase *targetPhrase, OnDiskWrapper &onDiskWrapper
, size_t tableLimit, const std::vector<float> &counts, OnDiskPt::PhrasePtr spShort);
size_t ReadChild(Word &wordFound, UINT64 &childFilePos, const char *mem) const;
void GetChild(Word &wordFound, UINT64 &childFilePos, size_t ind, OnDiskWrapper &onDiskWrapper) const;
size_t ReadChild(Word &wordFound, uint64_t &childFilePos, const char *mem) const;
void GetChild(Word &wordFound, uint64_t &childFilePos, size_t ind, OnDiskWrapper &onDiskWrapper) const;

public:
static size_t GetNodeSize(size_t numChildren, size_t wordSize, size_t countSize);

PhraseNode(); // unsaved node
PhraseNode(UINT64 filePos, OnDiskWrapper &onDiskWrapper); // load saved node
PhraseNode(uint64_t filePos, OnDiskWrapper &onDiskWrapper); // load saved node
~PhraseNode();

void Add(const Word &word, UINT64 nextFilePos, size_t wordSize);
void Add(const Word &word, uint64_t nextFilePos, size_t wordSize);
void Save(OnDiskWrapper &onDiskWrapper, size_t pos, size_t tableLimit);

void AddTargetPhrase(const SourcePhrase &sourcePhrase, TargetPhrase *targetPhrase
, OnDiskWrapper &onDiskWrapper, size_t tableLimit
, const std::vector<float> &counts, OnDiskPt::PhrasePtr spShort);

UINT64 GetFilePos() const {
uint64_t GetFilePos() const {
return m_filePos;
}
UINT64 GetValue() const {
uint64_t GetValue() const {
return m_value;
}
void SetValue(UINT64 value) {
void SetValue(uint64_t value) {
m_value = value;
}
size_t GetSize() const {
Expand Down

0 comments on commit 1064aaa

Please sign in to comment.