G
Gernot Frisch
Hi,
my code is slow. I have to rethink of it. Can you help?
I'm displaying a logfile from a license server.
I have a vector (m_lines) of
struct LINE
{
STATUS status; // LOGIN or LOGOUT
int hex; // the "user" id
time_t time; // time of login/out
};
which are sorted by time.
Now for each hex's LOGIN there must be a LOGOUT.
If there is none (no idea why), I'll have to add it.
Here's my code so far:
void ForceLogouts()
{
int num = (int)m_lines.size();
for(int i=0; i<num; ++i)
{
LINE& line1 = m_lines;
if(line1.status==ST_LOGIN)
{
for(int j=i+1; j<num; ++j)
{
LINE& line2 = m_lines;
// good logout
if(line2.hex == line1.hex && line2.status==ST_LOGOUT)
{
goto skipme;
}
}
// this one needs a logout badly!
LINE lt(line1);
tmday = &line1.time + 10000;
lt.status=ST_LOGOUT;
m_lines.push_back(lt);
}
skipme:;
}
// sort(m_lines, ...); // sort in new entries by time
}
What can I do? Sort the data by 'hex' first?
my code is slow. I have to rethink of it. Can you help?
I'm displaying a logfile from a license server.
I have a vector (m_lines) of
struct LINE
{
STATUS status; // LOGIN or LOGOUT
int hex; // the "user" id
time_t time; // time of login/out
};
which are sorted by time.
Now for each hex's LOGIN there must be a LOGOUT.
If there is none (no idea why), I'll have to add it.
Here's my code so far:
void ForceLogouts()
{
int num = (int)m_lines.size();
for(int i=0; i<num; ++i)
{
LINE& line1 = m_lines;
if(line1.status==ST_LOGIN)
{
for(int j=i+1; j<num; ++j)
{
LINE& line2 = m_lines;
// good logout
if(line2.hex == line1.hex && line2.status==ST_LOGOUT)
{
goto skipme;
}
}
// this one needs a logout badly!
LINE lt(line1);
tmday = &line1.time + 10000;
lt.status=ST_LOGOUT;
m_lines.push_back(lt);
}
skipme:;
}
// sort(m_lines, ...); // sort in new entries by time
}
What can I do? Sort the data by 'hex' first?