M
ma740988
Hopefully I'm not asking too much here, nontheless consider the test
source:
#include <vector>
#include <utility>
using std::vector;
using std:
air;
#define INVALID_ID -1
struct lsp_input_def
{
int segment;
lsp_input_def(void):
segment(INVALID_ID)
{
}
};
typedef vector<int> proccessor_vec;
typedef pair< unsigned int, proccessor_vec > segment_proc_pair;
typedef vector< segment_proc_pair > vec_pair;
// Transform the input to the output in sorted form.
void Transform(lsp_input_def* pStruct, unsigned int waveformCount,
unsigned int procCount, vec_pair& rsVect)
{
rsVect.resize(waveformCount);
size_t curOff = waveformCount * procCount;
unsigned int i = waveformCount;
while(i--)
{
rsVect.first = i;
unsigned int j = procCount;
while(j--)
{
const lsp_input_def& curStruct = pStruct[--curOff];
if(curStruct.segment != INVALID_ID) // ID number is valid. Add
it to the vector.
rsVect[curStruct.segment].second.push_back(j);
}
}
}
int main()
{
typedef unsigned int uint_type;
uint_type const max_segments = 7;
uint_type const max_processors = 24;
lsp_input_def wf[max_segments][max_processors];
wf[0][0].segment = 1; // element first is the segment / element
second processor
wf[1][0].segment = 0;
wf[2][0].segment = 3;
//wf[3][0].segment = 2;
//wf[0][1].segment = 3;
wf[0][1].segment = 1;
//wf[1][1].segment = 2;
wf[1][1].segment = 0;
// Transform the input to the output.
vec_pair sampleVect;
Transform((lsp_input_def*)wf, max_segments, max_processors,
sampleVect);
printf(" segment processor\n");
printf("-------------------------------\n");
for(size_t i = 0; i < sampleVect.size(); i++)
{
proccessor_vec& curVect = sampleVect.second;
if(curVect.size())
{
printf("\t%i\t", sampleVect.first);
printf("%i", curVect[0]);
for(size_t j = 1; j < curVect.size(); j++)
printf(", %i", curVect[j]);
printf("\n");
}
}
printf("\n");
return 0;
}
I'm trying to work my way through understanding how I could achieve the
same results using a map:
typedef std::map< unsigned int, proccessor_vec > id_vec_map;
Source snippet appreaciated.
Thanks
source:
#include <vector>
#include <utility>
using std::vector;
using std:
#define INVALID_ID -1
struct lsp_input_def
{
int segment;
lsp_input_def(void):
segment(INVALID_ID)
{
}
};
typedef vector<int> proccessor_vec;
typedef pair< unsigned int, proccessor_vec > segment_proc_pair;
typedef vector< segment_proc_pair > vec_pair;
// Transform the input to the output in sorted form.
void Transform(lsp_input_def* pStruct, unsigned int waveformCount,
unsigned int procCount, vec_pair& rsVect)
{
rsVect.resize(waveformCount);
size_t curOff = waveformCount * procCount;
unsigned int i = waveformCount;
while(i--)
{
rsVect.first = i;
unsigned int j = procCount;
while(j--)
{
const lsp_input_def& curStruct = pStruct[--curOff];
if(curStruct.segment != INVALID_ID) // ID number is valid. Add
it to the vector.
rsVect[curStruct.segment].second.push_back(j);
}
}
}
int main()
{
typedef unsigned int uint_type;
uint_type const max_segments = 7;
uint_type const max_processors = 24;
lsp_input_def wf[max_segments][max_processors];
wf[0][0].segment = 1; // element first is the segment / element
second processor
wf[1][0].segment = 0;
wf[2][0].segment = 3;
//wf[3][0].segment = 2;
//wf[0][1].segment = 3;
wf[0][1].segment = 1;
//wf[1][1].segment = 2;
wf[1][1].segment = 0;
// Transform the input to the output.
vec_pair sampleVect;
Transform((lsp_input_def*)wf, max_segments, max_processors,
sampleVect);
printf(" segment processor\n");
printf("-------------------------------\n");
for(size_t i = 0; i < sampleVect.size(); i++)
{
proccessor_vec& curVect = sampleVect.second;
if(curVect.size())
{
printf("\t%i\t", sampleVect.first);
printf("%i", curVect[0]);
for(size_t j = 1; j < curVect.size(); j++)
printf(", %i", curVect[j]);
printf("\n");
}
}
printf("\n");
return 0;
}
I'm trying to work my way through understanding how I could achieve the
same results using a map:
typedef std::map< unsigned int, proccessor_vec > id_vec_map;
Source snippet appreaciated.
Thanks