/* Copyright (C) 1997,1998,1999,2000,2001 Franz Josef Och mkcls - a program for making word classes . This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #ifndef FIXARRAY_H_DEFINED #define FIXARRAY_H_DEFINED #include #include #include template bool writeOb(ostream&out,const T&f) { out << f << " "; return 1; } template bool readOb(istream&in,T&f) { in >> f; char c; in.get(c); massert(c==' '); return 1; } template bool writeOb(ostream&out,const string &s,const T&f) { out << s << " " << f << " "; return 1; } template bool readOb(istream&in,const string&s,T&f) { string ss; in >> ss; if( s!=ss ) { cerr << "ERROR: readOb should be '" << s << "' and is '" << ss << "'" << endl; return 0; } in >> f; char c; in.get(c); massert(c==' '); return 1; } template class FixedArray { private: void copy(T *aa,const T *bb,int nnn) {for(int iii=0;iii &x) : p(new T[x.realSize]),realSize(x.realSize) {copy(p,x.p,realSize);} explicit FixedArray(int n) : p(new T[n]),realSize(n){} FixedArray(int n,const T&_init) : p(new T[n]),realSize(n){for(int z=0;z& operator=(const FixedArray&x) { if( this!= &x ) { delete [] p; realSize = x.realSize; p = new T[x.realSize]; copy(p,x.p,realSize); } return *this; } void resize(int n) { if( n<=realSize ) shrink(n); else { T*np=new T[n]; copy(np,p,realSize); delete []p; p=np; realSize=n; } } void shrink(int n) { assert(n<=realSize); realSize=n; } void init(int n,const T&_init) { delete []p; p=new T[n]; realSize=n; for(int l=0;l> s; if( !(s=="FixedArray") ) { cerr << "ERROR(FixedArray): FixedArray!='"<> biggest; resize(biggest); for(int a=0;a()); } int binary_locate(const T&t) { T*ppos=std::lower_bound(p,p+size(),t); int pos=ppos-p; if( pos>=-1&&pos=0&&pos bool operator<(const FixedArray &x, const FixedArray &y) { return lexicographical_compare(x.begin(),x.end(),y.begin(),y.end()); } template bool operator==(const FixedArray &x, const FixedArray &y) { if( &x == &y )return 1; const int s = x.size(); if( s !=y.size() )return 0; for(int iii=0;iii int Hash(const FixedArray&a) { int n=0; const int s=a.size(); for(int iii=0;iii const void FixedArray:: errorAccess(int n) const { massert(0); cerr << "ERROR: Access to array element " << n << " (" << realSize << "," << (void*)p << ")\n"; } template ostream& operator<<(ostream&o,const FixedArray&a) { o << "FixedArray(" << a.size() << "){ "; for(int iii=0;iii istream& operator>>(istream&in, FixedArray&) { return in;} template FixedArray operator+(const FixedArray&a,const FixedArray&b) { massert(a.size()==b.size()); FixedArray x(a.size()); for(int iii=0;iii FixedArray operator|(const FixedArray&aaa,const FixedArray&bbb) { iassert(aaa.size()==bbb.size()); FixedArray xxx(aaa.size()); for(int iii=0;iii