RegexItem * RegexItems::createItem(int start, int end, int depth) { // TODO Theres still some improvements to be made. Here or in RAdd minimizing assert(rItemMatrix[depth][start-1][end-1] == NULL); if (rItemMatrix[depth][start-1][end-1]) { return rItemMatrix[depth][start-1][end-1]; } RegexItem * newItem = new RegexItem(); rItemMatrix[depth][start-1][end-1] = newItem; if (depth == 0) return newItem; // variables in the equation // Not optimal since not all will be required, but good enough. RegexItem * Rij = getItem(start, end, depth - 1); RegexItem * Rik = getItem(start, depth, depth - 1); RegexItem * Rkk = getItem(depth, depth, depth - 1); RegexItem * Rkj = getItem(depth, end, depth - 1); if (Rij->head) { if (!Rik->head || !Rkk->head || !Rkj->head) { newItem->head = Rij->head; return newItem; } if (RNode::compareNodes(Rij->head, Rik->head) && RNode::compareNodes(Rkk->head, Rkj->head)) { RCon * conNode = new RCon(); RStar * starNode = new RStar(Rkk->head); rNodeList.push_back(conNode); rNodeList.push_back(starNode); conNode->children.push_back(Rij->head); conNode->children.push_back(starNode); newItem->head = conNode; return newItem; } if (RNode::compareNodes(Rij->head, Rkj->head) && RNode::compareNodes(Rik->head, Rkk->head)) { RCon * conNode = new RCon(); RStar * starNode = new RStar(Rkk->head); rNodeList.push_back(conNode); rNodeList.push_back(starNode); conNode->children.push_back(starNode); conNode->children.push_back(Rij->head); newItem->head = conNode; return newItem; } RAdd * addNode = new RAdd(); RCon * conNode = new RCon(); RStar * starNode = new RStar(Rkk->head); rNodeList.push_back(addNode); rNodeList.push_back(conNode); rNodeList.push_back(starNode); conNode->children.push_back(Rik->head); conNode->children.push_back(starNode); conNode->children.push_back(Rkj->head); addNode->children.push_back(conNode); addNode->children.push_back(Rij->head); newItem->head = addNode; return newItem; } else { if (!Rik->head || !Rkk->head || !Rkj->head) { return newItem; } RCon * conNode = new RCon; RStar * starNode = new RStar(Rkk->head); rNodeList.push_back(conNode); rNodeList.push_back(starNode); conNode->children.push_back(Rik->head); conNode->children.push_back(starNode); conNode->children.push_back(Rkj->head); newItem->head = conNode; } return newItem; }