/* * Licensed under the Apache License, Version 2.0 (the "License"); you may * not use this file except in compliance with the License. You may obtain * a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations * under the License. */#ifndef BST_H#define BST_H#include "Edge.h"#include <vector>#include "ValHeap.h"#include "CntxArray.h"#include "ECString.h"#include <iostream>#define NORMALVAL 0#define TERMINALVAL 1#define EXTRAVAL 2classBst;typedeflist<Bst*>Bsts;typedefvector<short>shorts;typedefshorts::iteratorshortIter;classVal{public:staticVal*newIth(intith,Val*oval,bool&stop);Val():status(NORMALVAL),len_(1),prob_(0),edge_(NULL),trm_(-1),wrd_(-1){vec_.push_back(0);}Val(Edge*e,doubleprb);~Val();Edge*edge()const{returnedge_;}Bsts&bsts(){returnbsts_;}shortlen()const{returnlen_;}short&len(){returnlen_;}shorttrm()const;short&trm1(){returntrm_;}intwrd()const;int&wrd1(){returnwrd_;}vector<short>&vec(){returnvec_;}vector<short>vec()const{returnvec_;}short&vec(inti){returnvec_[i];}doubleprob()const{returnprob_;}double&prob(){returnprob_;}doublefom(){returnprob_;}voidextendTrees(Bst&bst2,intpos);friendostream&operator<<(ostream&os,constVal&v);friendbooloperator==(Val&v1,Val&v2);boolcheck();shortstatus;private:Val(Val*oval);shortlen_;doubleprob_;Edge*edge_;shorttrm_;intwrd_;Bstsbsts_;vector<short>vec_;};classBst{public:Bst():explored_(false),done_(false),num_(0),sum_(0){}~Bst();Val*next(intn);boolexplored()const{returnexplored_;}bool&explored(){returnexplored_;}Val*nth(inti){returnnbest[i];}intnum()const{returnnum_;}int&num(){returnnum_;}boolempty(){returnnum_==0;}doubleprob(){returnnum_==0?0:nbest[0]->prob();}doublesum()const{returnsum_;}double&sum(){returnsum_;}ValHeapheap;voidpush(Val*val){heap.push(val);}Val*pop(){returnheap.pop();}voidaddnth(Val*val){num_++;nbest.push_back(val);}staticvoidtester(Val*val);boolptst(Val*val);private:boolexplored_;booldone_;intnum_;doublesum_;vector<Val*>nbest;};typedefmap<CntxArray,Bst,less<CntxArray>>BstMap;Bst&bstFind(CntxArray&hi,BstMap&bm);Bst&ithBst(inti,Bsts&bsts);#endif /* ! BST_H */