//---------------------------------------------------------------------------

#ifndef TTreeH
#define TTreeH
//---------------------------------------------------------------------------
class TTreeNode {
  friend class TTree;
  private:
        TTreeNode *one;
        TTreeNode *dc;
        TTreeNode *zero;
        unsigned int level;        // variable number

		list<Term>::iterator term;					// pointer to the term in a TermList. It is descarded by a copying constructor!
		bool isterm;							// is there a term? (term iterator is valid)

public:
        TTreeNode& operator=( const TTreeNode& n);

        TTreeNode( const unsigned int _level );
        TTreeNode( const TTreeNode& n );
        ~TTreeNode(void);

		void SetTerm( const list<Term>::iterator _term );	// sets term iterator
		list<Term>::iterator GetTerm(void);				// retrieves term iterator
		bool IsTerm(void) { return isterm; };			// is there term iterator?
};

class TTree {
    private:
        TTreeNode *root;
        unsigned int vars;
        unsigned long nodes;
        unsigned int terms;

        TTreeNode *AddTTreeNode( const unsigned int _level );
        void DeleteTree( TTreeNode *node );

    public:
        TTree& operator=( const TTree& n );
        TTree(void);
        TTree( const unsigned int _vars );
        ~TTree(void);
        void clear(void);

		// setters & getters
		unsigned int GetNodes(void) const { return nodes; };
        unsigned int GetTerms(void) const { return terms; };
        void SetInputs( const unsigned int _vars );

		
		TTreeNode *InsertTerm( const string term );   // Inserts a term into a TT. Returns a pointer to the terminal node.
        TTreeNode *FindTerm( const string term ) const;     // Returns a pointer to the terminal node or NULL
        bool DeleteTerm( const string term );			// Deletes a term from TT

};

#endif
