File: alignarrays.cpp

package info (click to toggle)
pilercr 1.06%2Bdfsg-5
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, trixie
  • size: 844 kB
  • sloc: cpp: 14,339; makefile: 67; sh: 36
file content (57 lines) | stat: -rwxr-xr-x 1,389 bytes parent folder | download | duplicates (2)
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
#include "pilercr.h"

static bool CmpAA(const ArrayAln *AA1, const ArrayAln *AA2)
	{
	return AA1->Pos < AA2->Pos;
	}

void AlignArrays(const std::vector<ArrayData *> &ADVec,
  std::vector<ArrayAln *> &AAVec)
	{
	AAVec.clear();

// Create array alignments
	const size_t ArrayDataCount = ADVec.size();
	for (size_t Index = 0; Index < ArrayDataCount; ++Index)
		{
		ArrayData &AD = *(ADVec[Index]);
		ArrayAln &AA = *new ArrayAln;
		AlignArray(AD, AA);

		if (AA.Repeats.size() > 0 && AcceptedAA(AA))
			AAVec.push_back(&AA);
		}

// Sort by position
	std::sort(AAVec.begin(), AAVec.end(), CmpAA);

// Check for arrays where we missed some repeats, these got split
// and can be merged.
	size_t ArrayIndex = 0;
	for (;;)
		{
		size_t ArrayCount = AAVec.size();
		if (ArrayIndex + 1 >= ArrayCount)
			break;
		bool Merged = MergeAAs(*AAVec[ArrayIndex], *AAVec[ArrayIndex+1]);
		if (Merged)
			{
		// Delete entry from array and continue.
		// This allows merger of three or more arrays.
			assert(ArrayCount > 1);
			for (size_t i = ArrayIndex + 1; i < ArrayCount - 1; ++i)
				AAVec[i] = AAVec[i+1];
			AAVec.resize(ArrayCount - 1);
			}
		++ArrayIndex;
		}

// Assign ids
	size_t ArrayCount = AAVec.size();
	int Id = 1;
	for (size_t Index = 0; Index < ArrayCount; ++Index)
		{
		ArrayAln &AA = *(AAVec[Index]);
		AA.Id = Id++;
		}
	}