mirror of
https://github.com/moses-smt/mosesdecoder.git
synced 2024-09-11 19:27:11 +03:00
use array instead of vector
This commit is contained in:
parent
0a69a5e1f6
commit
b131527f7a
@ -59,7 +59,7 @@ Hypotheses &MiniStack::GetSortedAndPruneHypos(const Manager &mgr) const
|
||||
if (m_sortedHypos == NULL) {
|
||||
// create sortedHypos first
|
||||
MemPool &pool = mgr.GetPool();
|
||||
m_sortedHypos = new (pool.Allocate< Vector<const Hypothesis*> >()) Vector<const Hypothesis*>(pool, m_coll.size());
|
||||
m_sortedHypos = new (pool.Allocate< Array<const Hypothesis*> >()) Array<const Hypothesis*>(pool, m_coll.size());
|
||||
|
||||
size_t ind = 0;
|
||||
BOOST_FOREACH(const Hypothesis *hypo, m_coll) {
|
||||
|
@ -22,7 +22,7 @@ class Manager;
|
||||
|
||||
namespace NSCubePruningMiniStack
|
||||
{
|
||||
typedef Vector<const Hypothesis*> Hypotheses;
|
||||
typedef Array<const Hypothesis*> Hypotheses;
|
||||
|
||||
class MiniStack
|
||||
{
|
||||
|
@ -13,8 +13,8 @@ using namespace std;
|
||||
namespace Moses2
|
||||
{
|
||||
|
||||
TargetPhrases::TargetPhrases(MemPool &pool, size_t reserve)
|
||||
:m_coll(pool, reserve)
|
||||
TargetPhrases::TargetPhrases(MemPool &pool, size_t size)
|
||||
:m_coll(pool, size)
|
||||
,m_currInd(0)
|
||||
{
|
||||
}
|
||||
|
@ -15,7 +15,7 @@ namespace Moses2
|
||||
|
||||
class TargetPhrases {
|
||||
friend std::ostream& operator<<(std::ostream &, const TargetPhrases &);
|
||||
typedef Vector<const TargetPhrase*> Coll;
|
||||
typedef Array<const TargetPhrase*> Coll;
|
||||
public:
|
||||
typedef Coll::iterator iterator;
|
||||
typedef Coll::const_iterator const_iterator;
|
||||
@ -27,7 +27,7 @@ public:
|
||||
return m_coll.end();
|
||||
}
|
||||
|
||||
TargetPhrases(MemPool &pool, size_t reserve);
|
||||
TargetPhrases(MemPool &pool, size_t size);
|
||||
//TargetPhrases(MemPool &pool, const System &system, const TargetPhrases ©);
|
||||
virtual ~TargetPhrases();
|
||||
|
||||
|
@ -7,6 +7,7 @@
|
||||
|
||||
#pragma once
|
||||
#include <cassert>
|
||||
#include <boost/functional/hash.hpp>
|
||||
#include "MemPool.h"
|
||||
|
||||
namespace Moses2
|
||||
@ -26,5 +27,80 @@ public:
|
||||
protected:
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
template <typename T>
|
||||
class Array
|
||||
{
|
||||
public:
|
||||
typedef T* iterator;
|
||||
typedef const T* const_iterator;
|
||||
//! iterators
|
||||
const_iterator begin() const {
|
||||
return m_arr;
|
||||
}
|
||||
const_iterator end() const {
|
||||
return m_arr + m_size;
|
||||
}
|
||||
|
||||
iterator begin() {
|
||||
return m_arr;
|
||||
}
|
||||
iterator end() {
|
||||
return m_arr + m_size;
|
||||
}
|
||||
|
||||
Array(MemPool &pool, size_t size = 0, const T &val = T())
|
||||
{
|
||||
m_size = size;
|
||||
m_maxSize = size;
|
||||
m_arr = pool.Allocate<T>(size);
|
||||
for (size_t i = 0; i < size; ++i) {
|
||||
m_arr[i] = val;
|
||||
}
|
||||
}
|
||||
|
||||
size_t size() const
|
||||
{ return m_size; }
|
||||
|
||||
const T& operator[](size_t ind) const {
|
||||
return m_arr[ind];
|
||||
}
|
||||
|
||||
T& operator[](size_t ind) {
|
||||
return m_arr[ind];
|
||||
}
|
||||
|
||||
size_t hash() const
|
||||
{
|
||||
size_t seed = 0;
|
||||
for (size_t i = 0; i < m_size; ++i) {
|
||||
boost::hash_combine(seed, m_arr[i]);
|
||||
}
|
||||
return seed;
|
||||
}
|
||||
|
||||
int Compare(const Array &compare) const
|
||||
{
|
||||
|
||||
int cmp = memcmp(m_arr, compare.m_arr, sizeof(T) * m_size);
|
||||
return cmp;
|
||||
}
|
||||
|
||||
bool operator==(const Array &compare) const
|
||||
{
|
||||
int cmp = Compare(compare);
|
||||
return cmp == 0;
|
||||
}
|
||||
|
||||
void resize(size_t newSize)
|
||||
{
|
||||
assert( m_size < m_maxSize);
|
||||
m_size = newSize;
|
||||
}
|
||||
protected:
|
||||
size_t m_size, m_maxSize;
|
||||
T *m_arr;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
@ -46,7 +46,7 @@ void Bitmap::Init(const std::vector<bool>& initializer)
|
||||
m_numWordsCovered = std::count(m_bitmap.begin(), m_bitmap.end(), true);
|
||||
|
||||
// Find the first gap, and cache it.
|
||||
Vector<char>::const_iterator first_gap = std::find(
|
||||
Array<char>::const_iterator first_gap = std::find(
|
||||
m_bitmap.begin(), m_bitmap.end(), false);
|
||||
m_firstGap = (
|
||||
(first_gap == m_bitmap.end()) ?
|
||||
@ -66,7 +66,7 @@ void Bitmap::Init(const Bitmap ©, const Range &range)
|
||||
// for unordered_set in stack
|
||||
size_t Bitmap::hash() const
|
||||
{
|
||||
size_t ret = boost::hash_value(m_bitmap);
|
||||
size_t ret = m_bitmap.hash();
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
@ -52,7 +52,7 @@ class Bitmap
|
||||
{
|
||||
friend std::ostream& operator<<(std::ostream& out, const Bitmap& bitmap);
|
||||
private:
|
||||
Vector<char> m_bitmap; //! Ticks of words in sentence that have been done.
|
||||
Array<char> m_bitmap; //! Ticks of words in sentence that have been done.
|
||||
size_t m_firstGap; //! Cached position of first gap, or NOT_FOUND.
|
||||
size_t m_numWordsCovered;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user