fix combinaton
This commit is contained in:
@@ -8,62 +8,63 @@
|
||||
using std::cout;
|
||||
using std::vector;
|
||||
|
||||
Tree Tree::operator+ (const Tree& other)//
|
||||
Tree Tree::operator+ (const Tree& other) const
|
||||
{
|
||||
Tree result(treeName + other.treeName); //The tree resulting from the addition
|
||||
vector<person_id> newId; //The indexes members of the II tree will have in result
|
||||
newId.reserve(other.numPeople);
|
||||
/* Tree result(treeName + other.treeName); //The tree resulting from the addition */
|
||||
/* vector<person_id> newId; //The indexes members of the II tree will have in result */
|
||||
/* newId.reserve(other.numPeople); */
|
||||
|
||||
U32 idCounter = numPeople;
|
||||
for (U32 i = 0, j; i < other.numPeople; ++i) //Searches for people present in both trees and gives them the same index in result
|
||||
{
|
||||
for (j = 0; j < numPeople; ++j)
|
||||
{
|
||||
if (other.people[i] == people[j])
|
||||
{
|
||||
newId[i] = j;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (j >= numPeople)
|
||||
newId[i] = ++idCounter;
|
||||
}
|
||||
result.numPeople = idCounter; //The number of members the resulting tree has
|
||||
/* U32 idCounter = numPeople; */
|
||||
/* for (U32 i = 0, j; i < other.numPeople; ++i) //Searches for people present in both trees and gives them the same index in result */
|
||||
/* { */
|
||||
/* for (j = 0; j < numPeople; ++j) */
|
||||
/* { */
|
||||
/* if (other.people[i] == people[j]) */
|
||||
/* { */
|
||||
/* newId[i] = j; */
|
||||
/* break; */
|
||||
/* } */
|
||||
/* } */
|
||||
/* if (j >= numPeople) */
|
||||
/* newId[i] = ++idCounter; */
|
||||
/* } */
|
||||
/* result.numPeople = idCounter; //The number of members the resulting tree has */
|
||||
|
||||
result.people.reserve(result.numPeople);
|
||||
result.people = people; //Adds the members of the I tree to the resulting tree
|
||||
for (U32 i=0; i < other.numPeople; ++i) //Adds the members of the II tree to the resulting tree
|
||||
{
|
||||
if (newId[i] >= numPeople)
|
||||
result.people.push_back(other.people[i]);
|
||||
}
|
||||
/* result.people.reserve(result.numPeople); */
|
||||
/* result.people = people; //Adds the members of the I tree to the resulting tree */
|
||||
/* for (U32 i=0; i < other.numPeople; ++i) //Adds the members of the II tree to the resulting tree */
|
||||
/* { */
|
||||
/* if (newId[i] >= numPeople) */
|
||||
/* result.people.push_back(other.people[i]); */
|
||||
/* } */
|
||||
|
||||
result.relations.reserve(result.numPeople);
|
||||
result.relations = relations;
|
||||
/* result.relations.reserve(result.numPeople); */
|
||||
/* result.relations = relations; */
|
||||
|
||||
for (U32 i=0; i < other.numPeople; ++i) //Adds the relatives from the II tree
|
||||
{
|
||||
if (newId[i] >= numPeople) //If the member is found in the II tree but not in the I
|
||||
{
|
||||
result.relations.push_back(other.relations[i]);
|
||||
}
|
||||
else //If he's found in both
|
||||
{
|
||||
for (unsigned j = 0; j < other.people[i].numRel_; ++j) //Adds the number of relatives from the II to the number in the I
|
||||
{
|
||||
if (newId[other.relations[i][j].id] > numPeople)
|
||||
++result.people[newId[i]].numRel_;
|
||||
}
|
||||
/* for (U32 i=0; i < other.numPeople; ++i) //Adds the relatives from the II tree */
|
||||
/* { */
|
||||
/* if (newId[i] >= numPeople) //If the member is found in the II tree but not in the I */
|
||||
/* { */
|
||||
/* result.relations.push_back(other.relations[i]); */
|
||||
/* } */
|
||||
/* else //If he's found in both */
|
||||
/* { */
|
||||
/* for (person_id j = 0; j < other.relations[i].size(); ++j) //Adds the number of relatives from the II to the number in the I */
|
||||
/* { */
|
||||
/* if (newId[other.relations[i][j].id] > numPeople) */
|
||||
/* ++result.people[newId[i]].numRel_; */
|
||||
/* } */
|
||||
|
||||
result.relations[newId[i]].reserve(result.people[newId[i]].numRel_);
|
||||
/* result.relations[newId[i]].reserve(result.people[newId[i]].numRel_); */
|
||||
|
||||
result.relations[newId[i]] = relations[newId[i]];
|
||||
/* result.relations[newId[i]] = relations[newId[i]]; */
|
||||
|
||||
result.relations[newId[i]] += other.relations[i]; //The relatives from the II tree
|
||||
}
|
||||
}
|
||||
/* result.relations[newId[i]] += other.relations[i]; //The relatives from the II tree */
|
||||
/* } */
|
||||
/* } */
|
||||
Tree result(*this);
|
||||
|
||||
return result;
|
||||
return result += other;
|
||||
}
|
||||
|
||||
Tree& Tree::operator+=(const Tree& other)
|
||||
@@ -72,7 +73,7 @@ Tree& Tree::operator+=(const Tree& other)
|
||||
newId.reserve(other.numPeople);
|
||||
|
||||
U32 idCounter = numPeople;
|
||||
for (U32 i = 0, j; i < other.numPeople; ++i) //Searches for people present in both trees and gives them the same index in I
|
||||
for (person_id i = 0, j; i < other.numPeople; ++i) //find the new ids for people in II, people present in both trees get the ids from I
|
||||
{
|
||||
for (j = 0; j < numPeople; ++j)
|
||||
{
|
||||
@@ -82,40 +83,52 @@ Tree& Tree::operator+=(const Tree& other)
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (j >= numPeople)
|
||||
if (j >= numPeople) /* not present in I */
|
||||
newId[i] = idCounter++;
|
||||
}
|
||||
|
||||
people.reserve(idCounter);
|
||||
for (U32 i = 0; i < other.numPeople; ++i) //Adds the member personal data of II tree to I tree
|
||||
for (person_id i = 0; i < other.numPeople; ++i) /* add the personal data of II to I */
|
||||
{
|
||||
if (newId[i] >= numPeople)
|
||||
if (newId[i] >= numPeople) /* isnt already in I */
|
||||
people.push_back(other.people[i]);
|
||||
}
|
||||
|
||||
relations.reserve(idCounter);
|
||||
for (U32 i = 0; i < other.numPeople; ++i) //Merges the relative data
|
||||
for (person_id i = 0; i < other.numPeople; ++i) //merge the relative data
|
||||
{
|
||||
if (newId[i] >= numPeople)
|
||||
if (newId[i] >= numPeople) /* isnt already in I */
|
||||
{
|
||||
relations.push_back(other.relations[i]);
|
||||
for (U32 j = 0; j < other.people[i].numRel_; ++j)
|
||||
relations[newId[i]][j].id = newId[ relations[newId[i]][j].id ];
|
||||
for (Relation& rel: relations.back())
|
||||
rel.id = newId[rel.id];
|
||||
/* for (person_id j = 0; j < other.people[i].numRel_; ++j) */
|
||||
/* relations[newId[i]][j].id = newId[ relations[newId[i]][j].id ]; */
|
||||
}
|
||||
else //If the member is present in both trees
|
||||
else //if present in both trees
|
||||
{
|
||||
for (U32 j = 0; j < other.people[i].numRel_; ++j) //Adds the number of relatives from the II to the number in the I
|
||||
/* for (person_id j = 0; j < other.people[i].numRel_; ++j) //combine relations */
|
||||
/* { */
|
||||
/* if (newId[other.relations[i][j].id] >= numPeople) */
|
||||
/* ++people[newId[i]].numRel_; */
|
||||
/* } */
|
||||
person_id idIn1 = newId[i];
|
||||
relations[idIn1].reserve(relations[idIn1].size() + other.relations[i].size());
|
||||
|
||||
for (Relation rel: other.relations[i])
|
||||
{
|
||||
if (newId[other.relations[i][j].id] >= numPeople)
|
||||
++people[newId[i]].numRel_;
|
||||
if(newId[rel.id] >= numPeople) /* not already in I */
|
||||
relations[idIn1].push_back( {newId[rel.id], rel.type} );
|
||||
else
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
relations[newId[i]].reserve(people[newId[i]].numRel_);
|
||||
for (U32 j = 0; j < other.people[i].numRel_; ++j)
|
||||
{
|
||||
relations[newId[i]][j + people[newId[i]].numRel_ - other.people[i].numRel_].id = newId[other.relations[i][j].id];
|
||||
relations[newId[i]][j + people[newId[i]].numRel_ - other.people[i].numRel_].type = other.relations[i][j].type;
|
||||
}
|
||||
/* for (person_id j = 0; j < other.people[i].numRel_; ++j) */
|
||||
/* { */
|
||||
/* relations[newId[i]][j + people[newId[i]].numRel_ - other.people[i].numRel_].id = newId[other.relations[i][j].id]; */
|
||||
/* relations[newId[i]][j + people[newId[i]].numRel_ - other.people[i].numRel_].type = other.relations[i][j].type; */
|
||||
/* } */
|
||||
}
|
||||
}
|
||||
|
||||
@@ -415,7 +428,7 @@ void Tree::display()
|
||||
I32 c;
|
||||
do
|
||||
{
|
||||
c = std::tolower(getch());
|
||||
c = std::toupper(getch());
|
||||
|
||||
switch(c)
|
||||
{
|
||||
@@ -424,41 +437,41 @@ void Tree::display()
|
||||
draw();
|
||||
break;
|
||||
case KEY_LEFT:
|
||||
--offsetX_;
|
||||
draw();
|
||||
break;
|
||||
case KEY_RIGHT:
|
||||
++offsetX_;
|
||||
draw();
|
||||
break;
|
||||
case KEY_DOWN:
|
||||
++offsetY_;
|
||||
case KEY_RIGHT:
|
||||
--offsetX_;
|
||||
draw();
|
||||
break;
|
||||
case KEY_UP:
|
||||
case KEY_DOWN:
|
||||
--offsetY_;
|
||||
draw();
|
||||
break;
|
||||
case 'h':
|
||||
case KEY_UP:
|
||||
++offsetY_;
|
||||
draw();
|
||||
break;
|
||||
case 'H':
|
||||
selectLeft();
|
||||
break;
|
||||
case 'j':
|
||||
case 'J':
|
||||
selectDown();
|
||||
break;
|
||||
case 'k':
|
||||
case 'K':
|
||||
selectUp();
|
||||
break;
|
||||
case 'l':
|
||||
case 'L':
|
||||
selectRight();
|
||||
break;
|
||||
case 'i':
|
||||
case 'I':
|
||||
people[selected_].displayInfo();
|
||||
draw();
|
||||
break;
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
while(c != 'w');
|
||||
while(c != 'W');
|
||||
}
|
||||
|
||||
void Tree::draw() const
|
||||
@@ -560,17 +573,17 @@ void Tree::commonAncestorRec(person_id id, vector<U8> &visited) const
|
||||
|
||||
static U8 linkToFirstBorn(I16 startY, I16 startX, bool moreSiblings)
|
||||
{
|
||||
if (startY >= -2 && startX >= 0)
|
||||
if (willBeVisible(startY, startX, 3, 1))
|
||||
{
|
||||
WINDOW* win = newwin(3, 1, startY, startX); /* TODO: pad */
|
||||
WINDOW* pad = newpad(3, 1);
|
||||
|
||||
waddch(win, ACS_VLINE);
|
||||
mvwaddch(win, 1, 0,
|
||||
waddch(pad, ACS_VLINE);
|
||||
mvwaddch(pad, 1, 0,
|
||||
moreSiblings ? ACS_LTEE : ACS_VLINE);
|
||||
mvwaddch(win, 2, 0, ACS_VLINE);
|
||||
mvwaddch(pad, 2, 0, ACS_VLINE);
|
||||
|
||||
wnoutrefresh(win);
|
||||
delwin(win);
|
||||
drawpad(pad, startY, startX);
|
||||
delwin(pad);
|
||||
}
|
||||
return 3;
|
||||
}
|
||||
@@ -578,23 +591,22 @@ static U8 linkToFirstBorn(I16 startY, I16 startX, bool moreSiblings)
|
||||
static U8 linkToChild(I16 startY, I16 startX, I16 endX, bool moreSiblings)
|
||||
{
|
||||
assert(endX >= startX);
|
||||
|
||||
if (startY >= -1 && endX >= 0)
|
||||
const I16 len = endX - startX;
|
||||
if (willBeVisible(startY, startX, 2, len))
|
||||
{
|
||||
const I16 len = endX - startX;
|
||||
WINDOW* win = newwin(2, len, startY, startX);
|
||||
WINDOW* pad = newpad(2, len);
|
||||
|
||||
for(U16 i = 0; i < len-1; ++i)
|
||||
waddch(win, ACS_HLINE);
|
||||
/* whline(win, '_', len-1); */
|
||||
waddch(win, moreSiblings ? ACS_TTEE : ACS_URCORNER);
|
||||
waddch(pad, ACS_HLINE);
|
||||
/* whline(pad, '_', len-1); */
|
||||
waddch(pad, moreSiblings ? ACS_TTEE : ACS_URCORNER);
|
||||
|
||||
mvwaddch(win, 1, len-1, ACS_VLINE);
|
||||
mvwaddch(pad, 1, len-1, ACS_VLINE);
|
||||
|
||||
wnoutrefresh(win);
|
||||
delwin(win);
|
||||
drawpad(pad, startY, startX);
|
||||
delwin(pad);
|
||||
}
|
||||
return 3;
|
||||
return 2;
|
||||
}
|
||||
|
||||
|
||||
@@ -667,7 +679,7 @@ I16 Tree::drawLineWithWives(const person_id id, I16 drawY, const I16 drawX) cons
|
||||
|
||||
for(size_t j = 1; j < numKids; ++j)
|
||||
{
|
||||
lnHt = linkToChild(drawY+1, prevX+1, childX+1, j < numKids-1);
|
||||
lnHt = linkToChild(drawY+1, prevX+1, childX+1, j < numKids-1) + 1; /* +1 because LTC starts lower then LTFB */
|
||||
prevX = childX;
|
||||
childX = drawLineWithWives(children[j], drawY + lnHt, childX);
|
||||
}
|
||||
@@ -677,7 +689,7 @@ I16 Tree::drawLineWithWives(const person_id id, I16 drawY, const I16 drawX) cons
|
||||
childX);
|
||||
}
|
||||
|
||||
void Tree::selectLeft() /* todo */
|
||||
void Tree::selectLeft()
|
||||
{
|
||||
if (findCommonAncestor(focused_, selected_) != Nobody) //if the selected is part of main tree
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user