Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
ccan
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
mirror
ccan
Commits
60b47bf5
Commit
60b47bf5
authored
Sep 25, 2010
by
Rusty Russell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
tally: invert histograms so maximum is on top.
parent
097857e6
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
14 additions
and
20 deletions
+14
-20
ccan/tally/tally.c
ccan/tally/tally.c
+8
-5
ccan/tally/test/run-histogram.c
ccan/tally/test/run-histogram.c
+6
-15
No files found.
ccan/tally/tally.c
View file @
60b47bf5
...
...
@@ -455,14 +455,17 @@ char *tally_histogram(const struct tally *tally,
}
for
(
i
=
0
;
i
<
height
;
i
++
)
{
unsigned
covered
=
1
;
count
=
(
double
)
tally
->
counts
[
i
]
/
largest_bucket
*
(
width
-
1
)
+
1
;
unsigned
covered
=
1
,
row
;
if
(
i
==
0
)
/* People expect minimum at the bottom. */
row
=
height
-
i
-
1
;
count
=
(
double
)
tally
->
counts
[
row
]
/
largest_bucket
*
(
width
-
1
)
+
1
;
if
(
row
==
0
)
covered
=
snprintf
(
p
,
width
,
"%zi"
,
tally
->
min
);
else
if
(
i
==
height
-
1
)
else
if
(
row
==
height
-
1
)
covered
=
snprintf
(
p
,
width
,
"%zi"
,
tally
->
max
);
else
if
(
i
==
bucket_of
(
tally
->
min
,
tally
->
step_bits
,
0
))
else
if
(
row
==
bucket_of
(
tally
->
min
,
tally
->
step_bits
,
0
))
*
p
=
'+'
;
else
*
p
=
'|'
;
...
...
ccan/tally/test/run-histogram.c
View file @
60b47bf5
...
...
@@ -6,7 +6,6 @@ int main(void)
int
i
;
struct
tally
*
tally
;
char
*
graph
,
*
p
;
bool
trunc
;
plan_tests
(
100
+
1
+
10
+
1
+
100
+
1
+
10
+
1
+
10
*
2
+
1
);
...
...
@@ -28,21 +27,13 @@ int main(void)
free
(
graph
);
/* Reduced height. */
trunc
=
false
;
graph
=
p
=
tally_histogram
(
tally
,
20
,
10
);
for
(
i
=
0
;
i
<
10
;
i
++
)
{
char
*
eol
=
strchr
(
p
,
'\n'
);
/*
La
st once can be truncated (bucket aliasing) */
/*
Fir
st once can be truncated (bucket aliasing) */
if
(
eol
)
{
if
(
eol
-
p
<
20
)
{
ok1
(
!
trunc
);
trunc
=
true
;
}
else
if
(
eol
-
p
==
20
)
{
ok1
(
!
trunc
);
}
else
{
fail
(
"Overwidth line %s"
,
p
);
}
ok1
(
eol
-
p
==
20
||
(
eol
-
p
<
20
&&
i
==
0
));
}
else
/* We should, at worst, half-fill graph */
ok1
(
i
>
5
);
...
...
@@ -76,7 +67,7 @@ int main(void)
graph
=
p
=
tally_histogram
(
tally
,
10
,
10
);
for
(
i
=
0
;
i
<
10
;
i
++
)
{
char
*
eol
=
strchr
(
p
,
'\n'
);
ok1
(
eol
-
p
==
i
+
1
);
ok1
(
eol
-
p
==
10
-
i
);
p
=
eol
+
1
;
}
ok1
(
!*
p
);
...
...
@@ -99,10 +90,10 @@ int main(void)
/* Check min/max labels. */
if
(
i
==
0
)
ok1
(
strncmp
(
p
,
"-5*"
,
3
)
==
0
);
else
if
(
i
==
9
)
ok1
(
strncmp
(
p
,
"4*"
,
2
)
==
0
);
else
if
(
i
==
5
)
else
if
(
i
==
9
)
ok1
(
strncmp
(
p
,
"-5*"
,
3
)
==
0
);
else
if
(
i
==
4
)
ok1
(
p
[
0
]
==
'+'
);
/* 0 marker */
else
ok1
(
p
[
0
]
==
'|'
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment