1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222
|
/*
This file is a part of KMC software distributed under GNU GPL 3 licence.
The homepage of the KMC project is http://sun.aei.polsl.pl/kmc
Authors: Marek Kokot
Version: 3.2.4
Date : 2024-02-09
*/
#ifndef _EXPRESSION_NODE_H
#define _EXPRESSION_NODE_H
#include "defs.h"
#include "operations.h"
#include <iostream>
#include <string>
#include <sstream>
#include <memory>
#include "db_reader_factory.h"
//************************************************************************************************************
// CExpressionNode - Base abstract class representing expression node. In first stage of algorithm from
// user input there is created binary tree. Node type represents operation. This tree is only for generating
// another tree (check out CInput and CBundle)
//************************************************************************************************************
template<unsigned SIZE> class CExpressionNode
{
public:
CExpressionNode() :left(nullptr), right(nullptr)
{
}
CExpressionNode* GetLeftChild() const
{
return left;
}
CExpressionNode* GetRightChild() const
{
return right;
}
virtual CBundle<SIZE>* GetExecutionRoot() = 0;
void AddLeftChild(CExpressionNode* child)
{
#ifdef ENABLE_DEBUG
if (left)
{
std::cout << "This child node already exists\n";
exit(1);
}
#endif
left = child;
}
void AddRightChild(CExpressionNode* child)
{
#ifdef ENABLE_DEBUG
if (right)
{
std::cout << "This child node already exists\n";
exit(1);
}
#endif
right = child;
}
#ifdef ENABLE_DEBUG
virtual void Info() = 0;
void Display(int adient = 0)
{
if (right)
right->Display(adient + 5);
for (int i = 0; i < adient; ++i)
std::cout << " ";
Info();
std::cout << "\n";
if (left)
left->Display(adient + 5);
}
#endif
virtual ~CExpressionNode()
{
delete left;
delete right;
}
protected:
CExpressionNode* left, *right;
};
template<unsigned SIZE> class COperNode : public CExpressionNode<SIZE>
{
protected:
CounterOpType counter_op_type;
public:
COperNode(CounterOpType counter_op_type) :counter_op_type(counter_op_type)
{
}
void SetCounterOpType(CounterOpType _counter_op_type)
{
this->counter_op_type = _counter_op_type;
}
};
//************************************************************************************************************
// CUnionNode - represents node for union operation
//************************************************************************************************************
template<unsigned SIZE> class CUnionNode : public COperNode<SIZE>
{
public:
CUnionNode():COperNode<SIZE>(CounterOpType::SUM)
{
}
CBundle<SIZE>* GetExecutionRoot() override
{
return new CBundle<SIZE>(new CUnion<SIZE>(this->left->GetExecutionRoot(), this->right->GetExecutionRoot(), this->counter_op_type));
}
#ifdef ENABLE_DEBUG
void Info() override
{
std::cout << "+";
}
#endif
};
//************************************************************************************************************
// CKmersSubtractionNode - represents node for subtraction of k-mers (if k-mer exists in both input,
// it is absent in result) operation
//************************************************************************************************************
template<unsigned SIZE> class CKmersSubtractionNode : public COperNode<SIZE>
{
public:
CKmersSubtractionNode() :COperNode<SIZE>(CounterOpType::NONE)
{
}
CBundle<SIZE>* GetExecutionRoot() override
{
return new CBundle<SIZE>(new CKmersSubtract<SIZE>(this->left->GetExecutionRoot(), this->right->GetExecutionRoot()));
}
#ifdef ENABLE_DEBUG
void Info() override
{
std::cout << "-";
}
#endif
};
template<unsigned SIZE> class CCountersSubtractionNode : public COperNode<SIZE>
{
public:
CCountersSubtractionNode():
COperNode<SIZE>(CounterOpType::DIFF)
{
}
CBundle<SIZE>* GetExecutionRoot() override
{
return new CBundle<SIZE>(new CCountersSubtract<SIZE>(this->left->GetExecutionRoot(), this->right->GetExecutionRoot(), this->counter_op_type));
}
#ifdef ENABLE_DEBUG
void Info() override
{
std::cout << "~";
}
#endif
};
//************************************************************************************************************
// CIntersectionNode - represents node for intersection operation
//************************************************************************************************************
template<unsigned SIZE> class CIntersectionNode : public COperNode<SIZE>
{
public:
CIntersectionNode():
COperNode<SIZE>(CounterOpType::MIN)
{
}
CBundle<SIZE>* GetExecutionRoot() override
{
return new CBundle<SIZE>(new CIntersection<SIZE>(this->left->GetExecutionRoot(), this->right->GetExecutionRoot(), this->counter_op_type));
}
#ifdef ENABLE_DEBUG
void Info() override
{
std::cout << "*";
}
#endif
};
//************************************************************************************************************
// CInputNode - represents node (leaf) - KMC1 or KMC2 database
//************************************************************************************************************
template<unsigned SIZE> class CInputNode : public CExpressionNode<SIZE>
{
uint32 desc_pos;
public:
CInputNode(uint32 desc_pos) : desc_pos(desc_pos)
{
}
CBundle<SIZE>* GetExecutionRoot() override
{
CConfig& config = CConfig::GetInstance();
CInput<SIZE>* db = db_reader_factory<SIZE>(config.headers[desc_pos], config.input_desc[desc_pos], KmerDBOpenMode::sorted);
return new CBundle<SIZE>(db);
}
#ifdef ENABLE_DEBUG
void Info() override
{
std::cout << "In: " << CConfig::GetInstance().input_desc[desc_pos].file_src;
}
#endif
};
#endif
// ***** EOF
|