linktrie.h

Go to the documentation of this file.
00001 #ifndef LINKTRIE_H
00002 #define LINKTRIE_H
00003 
00004 #include "bioseq.h"
00005 #include "matrix.h"
00006 #include <string>
00007 #include <iostream>
00008 #include <vector>
00009 
00010 using namespace std;
00011 
00012 struct intnode {
00013    intnode() : value(-1), next(0) { }
00014    intnode(int v) : value(v), next(0) { }
00015    int value;
00016    intnode* next;
00017 };
00018 
00021 struct lnode {
00022    lnode() : data('0'), sibling(0), child(0), key(0), pos(0) { }
00023    lnode(char c) : data(c), sibling(0), child(0), key(0), pos(0) { }
00024 
00025    void addChild(char c) { child=new lnode(c); }
00026    void addSibling(char c) { sibling= new lnode(c); }
00032    lnode* findSibling(char c);
00033    //lnode* findChild(char c) const;
00034    void deleteSelf();
00035    friend void deleteNode(lnode* n);
00039    friend ostream& operator<<(ostream &ous, const lnode& n);
00040 
00041    char data; // current node char
00042    lnode* sibling;
00043    lnode* child;
00044    char *key;  // final key, path from root to here
00045    intnode *pos; // as linked list, location in sequence
00046    //vector<int> position; // a list of positions
00047 };
00048 
00052 class ltrie {
00053    public:
00054       ltrie() : root(new lnode), leafnodes(), ws(4) { }
00055       ltrie(int depth) : root(new lnode), leafnodes(), ws(depth) { }
00056       ltrie(const string &seq);
00057 
00058       void build(const string &seq, const Matrix &mat, float T, float F);
00062       void insert(const char word[], int index);
00068       const lnode* find(const char word[]) const;
00069       //bool find(const string &word);
00070       void showLeafs(ostream &ous) const;
00071       ~ltrie();
00072 
00073    protected:
00074       lnode* root;
00075       int ws; // word size
00076       vector<lnode*> leafnodes; // alias to all leaf nodes
00077 };
00078 
00079 #endif

Generated on Wed Aug 10 11:56:54 2011 for Softwares from Orpara by  doxygen 1.5.6