Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/moses-smt/mgiza.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'mgizapp/src/mystl.h')
-rw-r--r--mgizapp/src/mystl.h172
1 files changed, 89 insertions, 83 deletions
diff --git a/mgizapp/src/mystl.h b/mgizapp/src/mystl.h
index ae42159..aa915ef 100644
--- a/mgizapp/src/mystl.h
+++ b/mgizapp/src/mystl.h
@@ -52,15 +52,15 @@ inline double verfProb(int n1,int n2)
if( n1==1 )return prob*n1mult;
else if( n1==2 )return prob*n2mult;
else if( n1==3 )return prob*n3mult;
- else
- return prob;
+ else
+ return prob;
}
inline bool prefix(const string&x,const string&y)
{
if(y.size()>x.size() )
return 0;
- for(unsigned int i=0;i<y.size();++i)
+ for(unsigned int i=0; i<y.size(); ++i)
if( y[i]!=x[i] )
return 0;
return 1;
@@ -115,21 +115,23 @@ float rel_lev(const T&s1,const T&s2)
return min(1.0,lev(s1,s2)/(double)s1.size());
}*/
-template<class V> int Hash(const pair<V,V>&a)
-{ return Hash(a.first)+13001*Hash(a.second); }
+template<class V> int Hash(const pair<V,V>&a)
+{
+ return Hash(a.first)+13001*Hash(a.second);
+}
template<class T1,class T2>
ostream& operator<<(ostream &out,const pair<T1,T2> &ir)
-{
+{
out << "(" << ir.first << "," << ir.second << ")";
return out;
-}
+}
inline int Hash(const string& s)
{
int sum=0;
string::const_iterator i=s.begin(),end=s.end();
- for(;i!=end;i++)sum=5*sum+(*i);
+ for(; i!=end; i++)sum=5*sum+(*i);
return sum;
}
template<class A,class B,class C>
@@ -139,13 +141,15 @@ public:
A a;
B b;
C c;
- tri(){};
+ tri() {};
tri(const A&_a,const B&_b,const C&_c)
: a(_a),b(_b),c(_c) {}
};
template<class A,class B,class C>
bool operator==(const tri<A,B,C>&x,const tri<A,B,C>&y)
-{ return x.a==y.a&&x.b==y.b&&x.c==y.c;}
+{
+ return x.a==y.a&&x.b==y.b&&x.c==y.c;
+}
template<class A,class B,class C>
bool operator<(const tri<A,B,C>&x,const tri<A,B,C>&y)
@@ -166,29 +170,36 @@ template<class T ,class _Pr = less<T> >
class my_hash
{
public:
- int operator()(const T&t)const {return Hash(t);}
+ int operator()(const T&t)const {
+ return Hash(t);
+ }
#ifdef WIN32
- enum
- { // parameters for hash table
- bucket_size = 1 // 0 < bucket_size
- };
- my_hash()
- : comp()
- { // construct with default comparator
- }
-
- my_hash(_Pr _Pred)
- : comp(_Pred)
- { // construct with _Pred comparator
- }
-protected:
- _Pr comp;
+ enum {
+ // parameters for hash table
+ bucket_size = 1 // 0 < bucket_size
+ };
+ my_hash()
+ : comp() {
+ // construct with default comparator
+ }
+
+ my_hash(_Pr _Pred)
+ : comp(_Pred) {
+ // construct with _Pred comparator
+ }
+protected:
+ _Pr comp;
public:
- int operator()(const T&t , const T&t1)const {return comp(t,t1);}
+ int operator()(const T&t , const T&t1)const {
+ return comp(t,t1);
+ }
#endif
};
-inline int Hash(int value) { return value; }
+inline int Hash(int value)
+{
+ return value;
+}
#define MY_HASH_BASE hash_map<A,B,my_hash<A> >
template<class A,class B>
@@ -200,29 +211,28 @@ public:
leda_h_array() : MY_HASH_BASE() {}
leda_h_array(const B&_init)
: MY_HASH_BASE(),init(_init) {}
- bool defined(const A&a) const
- { return find(a)!=this->end(); }
- const B&operator[](const A&a)const
- {
- typename MY_HASH_BASE::const_iterator pos=find(a);
- if( pos==this->end() )
- return init;
- else
- return pos->second;
- }
- B&operator[](const A&a)
- {
- typename MY_HASH_BASE::iterator pos=find(a);
- if( pos==this->end() )
- {
- insert(MY_HASH_BASE::value_type(a,init));
- pos=find(a);
- iassert(pos!=this->end());
- }
+ bool defined(const A&a) const {
+ return find(a)!=this->end();
+ }
+ const B&operator[](const A&a)const {
+ typename MY_HASH_BASE::const_iterator pos=find(a);
+ if( pos==this->end() )
+ return init;
+ else
return pos->second;
+ }
+ B&operator[](const A&a) {
+ typename MY_HASH_BASE::iterator pos=find(a);
+ if( pos==this->end() ) {
+ insert(MY_HASH_BASE::value_type(a,init));
+ pos=find(a);
+ iassert(pos!=this->end());
}
- const B&initValue()const
- {return init;}
+ return pos->second;
+ }
+ const B&initValue()const {
+ return init;
+ }
};
#define forall_defined_h(a,b,c,d) for(typename leda_h_array<a,b>::const_iterator __jj__=(d).begin();__jj__!=(d).end()&&((c=__jj__->first),1); ++__jj__)
@@ -232,13 +242,12 @@ ostream & operator<<(ostream&out,const leda_h_array<T,U>&w)
T t;
bool makeNl=0;
out << "h_array{";
- forall_defined_h(T,U,t,w)
- {
- if( makeNl )
- out << "\n ";
- out << "EL:" << t << " INH:" << w[t] << ".";
- makeNl=1;
- }
+ forall_defined_h(T,U,t,w) {
+ if( makeNl )
+ out << "\n ";
+ out << "EL:" << t << " INH:" << w[t] << ".";
+ makeNl=1;
+ }
return out << "}\n";
}
@@ -253,21 +262,20 @@ bool operator==(const leda_h_array<A,B>&p1,const leda_h_array<A,B>&p2)
{
A v;
forall_defined_h(A,B,v,p1)
- if( !( p1[v]==p2[v]) ) return 0;
+ if( !( p1[v]==p2[v]) ) return 0;
forall_defined_h(A,B,v,p2)
- if( !( p1[v]==p2[v]) ) return 0;
- return 1;
+ if( !( p1[v]==p2[v]) ) return 0;
+ return 1;
}
template<class T>
int count_elements(T a,T b)
{
int c=0;
- while(a!=b)
- {
- a++;
- c++;
- }
+ while(a!=b) {
+ a++;
+ c++;
+ }
return c;
}
@@ -275,17 +283,16 @@ template<class T>
T normalize_if_possible_with_increment(T*a,T*b,int increment)
{
T sum=0;
- for(T*i=a;i!=b;i+=increment)
+ for(T*i=a; i!=b; i+=increment)
sum+=*i;
if( sum )
- for(T*i=a;i!=b;i+=increment)
+ for(T*i=a; i!=b; i+=increment)
*i/=sum;
- else
- {
- T factor=increment/(b-a);
- for(T*i=a;i!=b;i+=increment)
- *i=factor;
- }
+ else {
+ T factor=increment/(b-a);
+ for(T*i=a; i!=b; i+=increment)
+ *i=factor;
+ }
return sum;
}
@@ -293,15 +300,14 @@ template<class T>
inline int m_comp_3way(T a,T b,int n)
{
int _n=0;
- while((_n++<n) && a && b)
- {
- const typename T::value_type &aa=*a;
- const typename T::value_type &bb=*b;
- if( aa<bb )return 1;
- if( bb<aa )return -1;
- ++a;
- ++b;
- }
+ while((_n++<n) && a && b) {
+ const typename T::value_type &aa=*a;
+ const typename T::value_type &bb=*b;
+ if( aa<bb )return 1;
+ if( bb<aa )return -1;
+ ++a;
+ ++b;
+ }
return 0;
}
@@ -309,10 +315,10 @@ template<class T>
void smooth_standard(T*a,T*b,double p)
{
int n=b-a;
- if( n==0 )
+ if( n==0 )
return;
double pp=p/n;
- for(T*i=a;i!=b;++i)
+ for(T*i=a; i!=b; ++i)
*i = (1.0-p)*(*i)+pp;
}