mirror of
https://github.com/moses-smt/mosesdecoder.git
synced 2024-09-11 19:27:11 +03:00
use own Vector class
This commit is contained in:
parent
0b097405ae
commit
7612306675
@ -9,9 +9,10 @@
|
||||
#include <boost/unordered_set.hpp>
|
||||
#include <vector>
|
||||
#include <queue>
|
||||
#include "../../legacy/Range.h"
|
||||
#include "../Hypothesis.h"
|
||||
#include "../../TypeDef.h"
|
||||
#include "../../legacy/Range.h"
|
||||
#include "../../Vector.h"
|
||||
|
||||
class Manager;
|
||||
class InputPath;
|
||||
@ -52,7 +53,7 @@ class CubeEdge
|
||||
friend std::ostream& operator<<(std::ostream &, const CubeEdge &);
|
||||
|
||||
public:
|
||||
typedef std::vector<const Hypothesis*> Hypotheses;
|
||||
typedef Vector<const Hypothesis*> Hypotheses;
|
||||
typedef std::priority_queue<QueueItem*,
|
||||
std::vector<QueueItem*>,
|
||||
QueueItemOrderer> Queue;
|
||||
|
@ -18,13 +18,21 @@ namespace NSCubePruning
|
||||
{
|
||||
CubeEdge::Hypotheses &HypothesisSet::GetSortedHypos(const Manager &mgr) const
|
||||
{
|
||||
if (m_coll.size() && m_sortedHypos.size() == 0) {
|
||||
if (m_sortedHypos == NULL) {
|
||||
// create sortedHypos first
|
||||
m_sortedHypos.insert(m_sortedHypos.end(), m_coll.begin(), m_coll.end());
|
||||
MemPool &pool = mgr.GetPool();
|
||||
m_sortedHypos = new (pool.Allocate< Vector<const Hypothesis*> >()) Vector<const Hypothesis*>(pool, m_coll.size());
|
||||
|
||||
size_t ind = 0;
|
||||
BOOST_FOREACH(const Hypothesis *hypo, m_coll) {
|
||||
(*m_sortedHypos)[ind] = hypo;
|
||||
++ind;
|
||||
}
|
||||
|
||||
SortAndPruneHypos(mgr);
|
||||
}
|
||||
|
||||
return m_sortedHypos;
|
||||
return *m_sortedHypos;
|
||||
}
|
||||
|
||||
void HypothesisSet::SortAndPruneHypos(const Manager &mgr) const
|
||||
@ -40,21 +48,21 @@ void HypothesisSet::SortAndPruneHypos(const Manager &mgr) const
|
||||
}
|
||||
cerr << endl;
|
||||
*/
|
||||
std::vector<const Hypothesis*>::iterator iterMiddle;
|
||||
iterMiddle = (stackSize == 0 || m_sortedHypos.size() < stackSize)
|
||||
? m_sortedHypos.end()
|
||||
: m_sortedHypos.begin() + stackSize;
|
||||
Vector<const Hypothesis*>::iterator iterMiddle;
|
||||
iterMiddle = (stackSize == 0 || m_sortedHypos->size() < stackSize)
|
||||
? m_sortedHypos->end()
|
||||
: m_sortedHypos->begin() + stackSize;
|
||||
|
||||
std::partial_sort(m_sortedHypos.begin(), iterMiddle, m_sortedHypos.end(),
|
||||
std::partial_sort(m_sortedHypos->begin(), iterMiddle, m_sortedHypos->end(),
|
||||
HypothesisFutureScoreOrderer());
|
||||
|
||||
// prune
|
||||
if (stackSize && m_sortedHypos.size() > stackSize) {
|
||||
for (size_t i = stackSize; i < m_sortedHypos.size(); ++i) {
|
||||
Hypothesis *hypo = const_cast<Hypothesis*>(m_sortedHypos[i]);
|
||||
if (stackSize && m_sortedHypos->size() > stackSize) {
|
||||
for (size_t i = stackSize; i < m_sortedHypos->size(); ++i) {
|
||||
Hypothesis *hypo = const_cast<Hypothesis*>((*m_sortedHypos)[i]);
|
||||
recycler.Add(hypo);
|
||||
}
|
||||
m_sortedHypos.resize(stackSize);
|
||||
m_sortedHypos->resize(stackSize);
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -11,6 +11,7 @@
|
||||
#include "Misc.h"
|
||||
#include "../../Recycler.h"
|
||||
#include "../../TypeDef.h"
|
||||
#include "../../Vector.h"
|
||||
#include "../../legacy/Util2.h"
|
||||
|
||||
class Manager;
|
||||
@ -25,6 +26,9 @@ public:
|
||||
UnorderedComparer<Hypothesis>, UnorderedComparer<Hypothesis>
|
||||
> _HCType;
|
||||
|
||||
HypothesisSet()
|
||||
{}
|
||||
|
||||
_HCType &GetColl()
|
||||
{ return m_coll; }
|
||||
|
||||
@ -35,7 +39,7 @@ public:
|
||||
|
||||
protected:
|
||||
_HCType m_coll;
|
||||
mutable CubeEdge::Hypotheses m_sortedHypos;
|
||||
mutable CubeEdge::Hypotheses *m_sortedHypos;
|
||||
|
||||
void SortAndPruneHypos(const Manager &mgr) const;
|
||||
|
||||
|
@ -6,13 +6,28 @@
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include <cassert>
|
||||
#include "MemPool.h"
|
||||
|
||||
template <typename T>
|
||||
class Vector {
|
||||
public:
|
||||
typedef T* iterator;
|
||||
typedef const T* const_iterator;
|
||||
|
||||
T *begin()
|
||||
{ return m_arr; }
|
||||
const T *begin() const
|
||||
{ return m_arr; }
|
||||
|
||||
T *end()
|
||||
{ return m_arr + m_size; }
|
||||
const T *end() const
|
||||
{ return m_arr + m_size; }
|
||||
|
||||
Vector(MemPool &pool, size_t size)
|
||||
:m_size(size)
|
||||
,m_maxSize(size)
|
||||
{
|
||||
m_arr = pool.Allocate<T>(size);
|
||||
}
|
||||
@ -22,8 +37,22 @@ public:
|
||||
|
||||
}
|
||||
|
||||
T& operator[](size_t ind)
|
||||
{ return m_arr[ind]; }
|
||||
const T& operator[](size_t ind) const
|
||||
{ return m_arr[ind]; }
|
||||
|
||||
size_t size() const
|
||||
{ return m_size; }
|
||||
|
||||
void resize(size_t newSize)
|
||||
{
|
||||
assert(newSize <= m_maxSize);
|
||||
m_size = newSize;
|
||||
}
|
||||
|
||||
protected:
|
||||
size_t m_size;
|
||||
size_t m_size, m_maxSize;
|
||||
T *m_arr;
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user