Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
cppack
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
passwords
cppack
Commits
1b008f81
Commit
1b008f81
authored
Feb 3, 2020
by
Mathieu Valois
Browse files
Options
Downloads
Patches
Plain Diff
proper reverse order using comparator from STL
parent
4806d489
No related branches found
No related tags found
No related merge requests found
Pipeline
#6263
passed
Feb 3, 2020
Stage: test
Changes
3
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
include/Utils.h
+9
-11
9 additions, 11 deletions
include/Utils.h
src/core/Statsgen.cpp
+5
-12
5 additions, 12 deletions
src/core/Statsgen.cpp
src/gui/MainWindow.cpp
+17
-24
17 additions, 24 deletions
src/gui/MainWindow.cpp
with
31 additions
and
47 deletions
include/Utils.h
+
9
−
11
View file @
1b008f81
...
...
@@ -18,6 +18,7 @@
#include
<fstream>
#include
<unordered_map>
#include
<iomanip>
#include
<utility>
inline
float
percentage
(
const
float
&
num
,
const
float
&
den
){
return
100
*
num
/
den
;
...
...
@@ -36,11 +37,11 @@ using MapIterator = typename std::map<K, V>::const_iterator;
* @return ordered map
*/
template
<
typename
A
>
std
::
multi
map
<
uint64_t
,
A
>
flip_map
(
const
std
::
unordered_map
<
A
,
uint64_t
>
&
src
)
{
std
::
multi
map
<
uint64_t
,
A
>
dst
;
std
::
map
<
uint64_t
,
A
,
std
::
greater
<
uint64_t
>
>
flip_map
(
const
std
::
unordered_map
<
A
,
uint64_t
>
&
src
)
{
std
::
map
<
uint64_t
,
A
,
std
::
greater
<
uint64_t
>
>
dst
;
for
(
UnorderedMapIterator
<
A
,
uint64_t
>
it
=
src
.
begin
();
it
!=
src
.
end
();
++
it
)
dst
.
insert
(
std
::
pair
<
uint64_t
,
A
>
(
it
->
second
,
it
->
first
));
dst
.
insert
(
std
::
make_pair
(
it
->
second
,
it
->
first
));
return
dst
;
}
...
...
@@ -82,18 +83,15 @@ void readResult(const uint64_t & res, const Type& carac, int & count, const uint
template
<
typename
Type
>
void
showMap
(
const
std
::
unordered_map
<
Type
,
uint64_t
>
&
stats
,
const
int
&
top
,
const
uint64_t
&
total_counter
,
const
int
&
hiderare
,
int
&
count
)
{
count
=
0
;
std
::
multimap
<
uint64_t
,
Type
>
reverse
=
flip_map
<
Type
>
(
stats
);
MapIterator
<
uint64_t
,
Type
>
it
;
for
(
it
=
reverse
.
end
();
it
!=
reverse
.
begin
();
it
--
)
{
if
(
it
==
reverse
.
end
())
continue
;
readResult
<
Type
>
(
it
->
first
,
it
->
second
,
count
,
total_counter
,
hiderare
);
std
::
map
<
uint64_t
,
Type
,
std
::
greater
<
uint64_t
>>
reverse
=
flip_map
<
Type
>
(
stats
);
std
::
pair
<
uint64_t
,
Type
>
it
;
for
(
std
::
pair
<
uint64_t
,
Type
>
it
:
reverse
)
{
readResult
<
Type
>
(
it
.
first
,
it
.
second
,
count
,
total_counter
,
hiderare
);
if
(
top
!=
-
1
&&
count
==
top
)
break
;
}
if
(
count
!=
top
)
{
readResult
<
Type
>
(
it
->
first
,
it
->
second
,
count
,
total_counter
,
hiderare
);
readResult
<
Type
>
(
it
.
first
,
it
.
second
,
count
,
total_counter
,
hiderare
);
}
}
...
...
This diff is collapsed.
Click to expand it.
src/core/Statsgen.cpp
+
5
−
12
View file @
1b008f81
...
...
@@ -112,11 +112,6 @@ int Statsgen::generate_stats() {
pthread_t
threads
[
MAX_THREADS
];
pthread_attr_t
attr
;
pthread_attr_init
(
&
attr
);
pthread_attr_setdetachstate
(
&
attr
,
PTHREAD_CREATE_JOINABLE
);
// split stdin into nbThread files on disk
if
(
is_stdin
){
string
line
;
...
...
@@ -160,7 +155,6 @@ int Statsgen::generate_stats() {
}
void
*
status
;
pthread_attr_destroy
(
&
attr
);
for
(
int
i
=
0
;
i
<
nbThread
;
i
++
)
{
int
rc
=
pthread_join
(
threads
[
i
],
&
status
);
if
(
rc
)
{
...
...
@@ -233,14 +227,13 @@ void Statsgen::print_stats() {
cout
<<
"
\n
Statistics relative to advancedmask:
\n
"
<<
endl
;
showMap
(
stats_advancedmasks
,
top
,
total_counter
,
hiderare
,
count
);
if
(
outfile_name
!=
""
){
if
(
!
outfile_name
.
empty
()
){
locale
::
global
(
locale
(
"C"
));
ofstream
outfile_stream
(
outfile_name
);
multimap
<
uint64_t
,
string
>
reverse
=
flip_map
<
string
>
(
stats_advancedmasks
);
for
(
auto
it
=
reverse
.
end
();
it
!=
reverse
.
begin
();
it
--
){
if
(
it
==
reverse
.
end
())
continue
;
if
(
it
->
second
==
"othermasks"
)
continue
;
outfile_stream
<<
it
->
second
<<
","
<<
it
->
first
<<
endl
;
map
<
uint64_t
,
string
,
greater
<
uint64_t
>>
reverse
=
flip_map
(
stats_advancedmasks
);
for
(
pair
<
uint64_t
,
string
>
it
:
reverse
){
if
(
it
.
second
==
"othermasks"
)
continue
;
outfile_stream
<<
it
.
second
<<
","
<<
it
.
first
<<
endl
;
}
outfile_stream
.
close
();
}
...
...
This diff is collapsed.
Click to expand it.
src/gui/MainWindow.cpp
+
17
−
24
View file @
1b008f81
...
...
@@ -162,24 +162,22 @@ double MainWindow::initGraphicalStats(QBarSeries * barLength, QPieSeries * pieCh
percentageSecurity
=
percentage
(
stats
.
getNbSecurePasswords
(),
total
);
/* LENGTH HISTOGRAM */
multi
map
<
uint64_t
,
int
>
reverseL
=
flip_map
<
int
>
(
stats
.
getStatsLength
());
map
<
uint64_t
,
int
,
greater
<
uint64_t
>
>
reverseL
=
flip_map
<
int
>
(
stats
.
getStatsLength
());
double
percentageL
;
double
maxPercLength
=
0
;
uint64_t
nbHideL
=
0
;
barLength
->
clear
();
MapIterator
<
uint64_t
,
int
>
itL
;
for
(
itL
=
reverseL
.
end
();
itL
!=
reverseL
.
begin
();
itL
--
)
{
if
(
itL
==
reverseL
.
end
())
continue
;
for
(
pair
<
uint64_t
,
int
>
itL
:
reverseL
)
{
percentageL
=
percentage
(
itL
->
first
,
total
);
percentageL
=
percentage
(
itL
.
first
,
total
);
maxPercLength
=
percentageL
>
maxPercLength
?
percentageL
:
maxPercLength
;
if
(
percentageL
>=
perc_other
)
{
QBarSet
*
set
=
new
QBarSet
(
QString
::
number
(
itL
->
second
));
QBarSet
*
set
=
new
QBarSet
(
QString
::
number
(
itL
.
second
));
*
set
<<
percentageL
;
barLength
->
append
(
set
);
}
else
{
nbHideL
+=
itL
->
first
;
nbHideL
+=
itL
.
first
;
}
}
...
...
@@ -189,55 +187,50 @@ double MainWindow::initGraphicalStats(QBarSeries * barLength, QPieSeries * pieCh
/* CHARSET PIECHART */
multi
map
<
uint64_t
,
string
>
reverseC
=
flip_map
<
string
>
(
stats
.
getStatsCharsets
());
map
<
uint64_t
,
string
,
greater
<
uint64_t
>
>
reverseC
=
flip_map
(
stats
.
getStatsCharsets
());
uint64_t
top
=
0
;
uint64_t
nbHideC
=
0
;
pieCharset
->
clear
();
MapIterator
<
uint64_t
,
string
>
itC
;
for
(
itC
=
reverseC
.
end
();
itC
!=
reverseC
.
begin
();
itC
--
)
{
if
(
itC
==
reverseC
.
end
())
continue
;
for
(
pair
<
uint64_t
,
string
>
itC
:
reverseC
)
{
top
++
;
if
(
top
<=
display_charsets
)
{
pieCharset
->
append
(
QString
::
fromStdString
(
itC
->
second
),
itC
->
first
);
pieCharset
->
append
(
QString
::
fromStdString
(
itC
.
second
),
itC
.
first
);
}
else
{
nbHideC
+=
itC
->
first
;
nbHideC
+=
itC
.
first
;
}
}
pieCharset
->
append
(
"Other charsets"
,
nbHideC
);
/* SIMPLE PIECHART */
multi
map
<
uint64_t
,
string
>
reverseS
=
flip_map
<
string
>
(
stats
.
getStatsSimple
());
map
<
uint64_t
,
string
,
greater
<
uint64_t
>
>
reverseS
=
flip_map
(
stats
.
getStatsSimple
());
uint64_t
top_simple
=
0
;
uint64_t
nbHideS
=
0
;
pieSimple
->
clear
();
MapIterator
<
uint64_t
,
string
>
itS
;
for
(
itS
=
reverseS
.
end
();
itS
!=
reverseS
.
begin
();
itS
--
)
{
if
(
itS
==
reverseS
.
end
())
continue
;
for
(
pair
<
uint64_t
,
string
>
itS
:
reverseS
)
{
top_simple
++
;
if
(
top_simple
<=
display_simples
)
{
pieSimple
->
append
(
QString
::
fromStdString
(
itS
->
second
),
itS
->
first
);
pieSimple
->
append
(
QString
::
fromStdString
(
itS
.
second
),
itS
.
first
);
}
else
{
nbHideS
+=
itS
->
first
;
nbHideS
+=
itS
.
first
;
}
}
pieSimple
->
append
(
"Other Masks"
,
nbHideS
);
/* ADVANCED PIECHART */
multi
map
<
uint64_t
,
string
>
reverseA
=
flip_map
<
string
>
(
stats
.
getStatsAdvanced
());
map
<
uint64_t
,
string
,
greater
<
uint64_t
>
>
reverseA
=
flip_map
(
stats
.
getStatsAdvanced
());
uint64_t
top_advanced
=
0
;
uint64_t
nbHideA
=
0
;
pieAdvanced
->
clear
();
MapIterator
<
uint64_t
,
string
>
itA
;
for
(
itA
=
reverseA
.
end
();
itA
!=
reverseA
.
begin
();
itA
--
)
{
if
(
itA
==
reverseA
.
end
())
continue
;
for
(
pair
<
uint64_t
,
string
>
itA
:
reverseA
)
{
top_advanced
++
;
if
(
top_advanced
<=
display_advanced
)
{
pieAdvanced
->
append
(
QString
::
fromStdString
(
itA
->
second
),
itA
->
first
);
pieAdvanced
->
append
(
QString
::
fromStdString
(
itA
.
second
),
itA
.
first
);
}
else
{
nbHideA
+=
itA
->
first
;
nbHideA
+=
itA
.
first
;
}
}
pieAdvanced
->
append
(
"Other Masks"
,
nbHideA
);
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment