File indexing completed on 2025-04-19 09:09:48
0001 #ifndef AMEGIC_String_String_Tree_H
0002 #define AMEGIC_String_String_Tree_H
0003
0004 #include "AMEGIC++/String/MyString.H"
0005 #include "ATOOLS/Math/Kabbala.H"
0006 #include "ATOOLS/Math/MyComplex.H"
0007 #include <list>
0008 #include <vector>
0009
0010 namespace AMEGIC {
0011 class sknot {
0012 std::string* strp;
0013 static std::string emptystring;
0014 public:
0015 sknot* left;
0016 sknot* right;
0017 ATOOLS::Kabbala* value;
0018 char op;
0019
0020 sknot() {strp = 0; value =0;}
0021 sknot(const sknot& cp) {
0022 left = cp.left;
0023 right = cp.right;
0024 value = cp.value;
0025 op = cp.op;
0026 if (cp.strp!=0) strp = new std::string(cp.Str());
0027 else strp = 0;
0028 }
0029 ~sknot() {if (strp!=0) delete strp;}
0030 void KillString() {if (strp!=0) delete strp; strp=0;}
0031 void KillValue() {if (value!=0) delete value; value=0;}
0032 const std::string& Str() const { if (strp!=0) return *strp;return emptystring;}
0033 void SetString(const std::string& str) {
0034 if (strp!=0) delete strp;
0035 strp = new std::string(str);
0036 }
0037 sknot& operator=(const sknot& cp) {
0038 if (this!=&cp) {
0039 left = cp.left;
0040 right = cp.right;
0041 value = cp.value;
0042 op = cp.op;
0043 if (strp!=0) delete strp;
0044 if (cp.strp!=0) strp = new std::string(cp.Str());
0045 else strp = 0;
0046 }
0047 return *this;
0048 }
0049 };
0050
0051 class String_Tree {
0052 static sknot zero;
0053 static const int block_size;
0054 int skpos;
0055 std::vector<sknot*> sblocks;
0056 std::list<sknot*> leaflist;
0057 sknot* Leaf(std::string&,sknot*,int);
0058
0059 void Single_Expand(sknot*,int&);
0060 void Single_Delete(sknot*&,sknot*,const std::string&);
0061
0062 void SingleDeleteMinus(sknot* &,int&);
0063 int CountMinus(sknot* &);
0064
0065
0066 void LinearPM(sknot*);
0067 void OrderPM(sknot*,sknot*);
0068 void DetermineLeafAndSign(sknot*,std::vector<sknot*>&,std::vector<int>&,int&);
0069 void SetLeafAndSign(sknot*,std::vector<sknot*>&,std::vector<int>&,int&);
0070 void DeleteEquals(std::vector<sknot*>&,std::vector<int>&);
0071
0072 int CountFactorNumber(sknot*,std::vector<sknot*>*&,sknot*,std::vector<sknot*>*&,int);
0073 void CollectLeafs(sknot*,std::vector<sknot*>&,int);
0074
0075 public:
0076 String_Tree();
0077 ~String_Tree();
0078 void Reset();
0079 sknot* newsk();
0080 void popsk();
0081 sknot* String2Tree(std::string,int fixed = 0);
0082 Complex eval(sknot*);
0083 Complex evalcolor(sknot*);
0084 Complex Evaluate(sknot*);
0085 std::string Tree2String(sknot*,sknot*);
0086 std::string Tree2Tex(sknot*,sknot*);
0087 void Expand(sknot*);
0088 void DetermineDepth(sknot*,char,int&);
0089 void ExpandToDepth(sknot*,int,std::list<sknot*>&);
0090 void Linear(sknot*);
0091 void LinearOrderPM(sknot*);
0092 sknot* Copy(sknot*,int fixed = 0);
0093 void Sort(sknot*);
0094 void Delete(sknot*&,const std::string&);
0095 void GetEnd(sknot*,std::list<sknot*> &);
0096 void Find(sknot*,const std::string&,int&);
0097 void Simplify(sknot*&);
0098 void DeleteMinus(sknot* &);
0099 int SknotListSize() {return skpos+1;}
0100 void Cluster(sknot*,sknot*,int full = 0);
0101 void Addends(sknot*,std::list<sknot*> &);
0102 void Factors(sknot*,std::list<sknot*> &);
0103 void CleanValues();
0104 };
0105 }
0106 #endif