00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00035 #include "projectiontreelabels.h"
00036
00037 ProjectionTreeLabels::ProjectionTreeLabels(ProjectionTreeNode * root) {
00038 unsigned id = 0;
00039
00040 computeProjectionTreeLabels(root, id, 0);
00041 }
00042
00043 ProjectionTreeLabels::~ProjectionTreeLabels() {
00044 for (unsigned i = 0; i < labels.size(); i++) {
00045 delete labels[i];
00046 }
00047 }
00048
00049 void ProjectionTreeLabels::updateParentPredecessorInformation() {
00050 labels[0]->updateParentPredecessorInformation(NULL, NULL);
00051 }
00052
00053 void ProjectionTreeLabels::print(OutputStream & dos) {
00054 for (unsigned i = 0; i < labels.size(); i++) {
00055 labels[i]->print(dos);
00056 }
00057 }
00058
00059 void ProjectionTreeLabels::getAllRecursiveDosNodeSuccessors(unsigned id,
00060 vector <
00061 unsigned >&succ) {
00062
00063 ProjectionTreeLabel *sls = getLabelById(id)->getSameLevelSuccessor();
00064
00065 if (sls && sls->isDosNodeLabel()) {
00066 succ.push_back(sls->getId());
00067 getAllRecursiveDosNodeSuccessors(sls->getId(), succ);
00068 }
00069
00070 vector < ProjectionTreeLabel * >*css =
00071 getLabelById(id)->getChildSuccessors();
00072 for (unsigned i = 0; i < css->size(); i++) {
00073 ProjectionTreeLabel *cur = (*css)[i];
00074
00075 if (cur->isDosNodeLabel()) {
00076 succ.push_back(cur->getId());
00077 getAllRecursiveDosNodeSuccessors(cur->getId(), succ);
00078 }
00079 }
00080 }
00081
00082 ProjectionTreeLabel *ProjectionTreeLabels::
00083 computeProjectionTreeLabels(ProjectionTreeNode * n, unsigned &id,
00084 unsigned cur_position) {
00085
00086
00087 labels.push_back(NULL);
00088
00089 unsigned this_id = id;
00090 unsigned this_position = cur_position;
00091
00092 ProjectionTreeLabel *same_level_successor = NULL;
00093
00094 vector < ProjectionTreeLabel * >self_successors;
00095 vector < ProjectionTreeLabel * >child_successors;
00096
00097
00098 if (n->getPath() && ++cur_position < n->getPath()->getPathSize()) {
00099 same_level_successor =
00100 computeProjectionTreeLabels(n, ++id, cur_position);
00101
00102
00103 } else {
00104 vector < ProjectionTreeNode * >*children = n->getChildren();
00105 for (unsigned i = 0; i < children->size(); i++) {
00106 ProjectionTreeLabel *child_label =
00107 computeProjectionTreeLabels((*children)[i], ++id, 0);
00108
00109
00110
00111 if (child_label->getProjectionTreeNode()->getPath()) {
00112 child_successors.push_back(child_label);
00113
00114
00115
00116 } else {
00117
00118
00119 self_successors.push_back(child_label);
00120
00121 vector < ProjectionTreeLabel * >*child_self_successors =
00122 child_label->getSelfSuccessors();
00123 for (unsigned j = 0; j < child_self_successors->size(); j++) {
00124 self_successors.push_back((*child_self_successors)[j]);
00125 }
00126
00127
00128
00129 vector < ProjectionTreeLabel * >*child_child_successors =
00130 child_label->getChildSuccessors();
00131 for (unsigned j = 0; j < child_child_successors->size(); j++) {
00132 child_successors.push_back((*child_child_successors)[j]);
00133 }
00134
00135 }
00136 }
00137 }
00138
00139
00140 ProjectionTreeLabel *l = new ProjectionTreeLabel(n, this_position, this_id,
00141 same_level_successor,
00142 child_successors,
00143 self_successors);
00144
00145 labels[this_id] = l;
00146
00147
00148 return l;
00149 }