Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
C
c-stuff
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Bruce Cowan
c-stuff
Commits
bf97bb95
Commit
bf97bb95
authored
6 years ago
by
Bruce Cowan
Browse files
Options
Downloads
Patches
Plain Diff
Remove mathematical functions from library, and rename to average
A bit too specialist, and a better name for the test executable
parent
721ed2f0
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
array.c
+0
-37
0 additions, 37 deletions
array.c
array.h
+0
-6
0 additions, 6 deletions
array.h
average.c
+22
-2
22 additions, 2 deletions
average.c
meson.build
+1
-1
1 addition, 1 deletion
meson.build
with
23 additions
and
46 deletions
array.c
+
0
−
37
View file @
bf97bb95
...
...
@@ -252,43 +252,6 @@ array_get_capacity (const Array *array)
return
array
->
capacity
;
}
/**
* array_total_val:
* @array: An array
* @func: A function which converts the contained data into doubles
*
* Gets the total value of the array.
*
* Returns: The total value of the array.
*/
double
array_total_val
(
const
Array
*
array
,
ValueFunc
func
)
{
double
total
=
0
;
for
(
int
i
=
0
;
i
<
array
->
length
;
i
++
)
total
+=
func
(
array
->
data
[
i
]);
return
total
;
}
/**
* array_average_val:
* @array: An array
* @func: A function which converts the contained data into ints
*
* Gets the average value of the array.
*
* Returns: The average value of the array.
*/
double
array_average_val
(
const
Array
*
array
,
ValueFunc
func
)
{
return
array_total_val
(
array
,
func
)
/
array
->
length
;
}
/**
* array_sort:
* @array: An array
...
...
This diff is collapsed.
Click to expand it.
array.h
+
0
−
6
View file @
bf97bb95
...
...
@@ -29,12 +29,6 @@ const void * array_get (const Array *array,
size_t
array_get_length
(
const
Array
*
array
);
size_t
array_get_capacity
(
const
Array
*
array
);
// Aggregate functions
double
array_total_val
(
const
Array
*
array
,
ValueFunc
func
);
double
array_average_val
(
const
Array
*
array
,
ValueFunc
func
);
// Misc
void
array_sort
(
Array
*
array
,
CompareFunc
func
);
This diff is collapsed.
Click to expand it.
p
av
g
.c
→
av
erage
.c
+
22
−
2
View file @
bf97bb95
...
...
@@ -6,6 +6,26 @@
#define INT_TO_PTR(x) ((void *) (size_t) (x))
#define PTR_TO_INT(x) ((int) (size_t) (x))
static
double
total_val
(
const
Array
*
array
,
ValueFunc
func
)
{
double
total
=
0
;
size_t
length
=
array_get_length
(
array
);
for
(
size_t
i
=
0
;
i
<
length
;
i
++
)
total
+=
func
(
array_get
(
array
,
i
));
return
total
;
}
static
double
average_val
(
const
Array
*
array
,
ValueFunc
func
)
{
return
total_val
(
array
,
func
)
/
array_get_length
(
array
);
}
static
double
array_to_int
(
const
void
*
data
)
{
...
...
@@ -19,8 +39,8 @@ print_array (Array *array)
printf
(
"Array at %p is of length %zu
\n
"
,
array
,
length
);
printf
(
"Array has capacity %zu
\n
"
,
array_get_capacity
(
array
));
double
total
=
array_
total_val
(
array
,
array_to_int
);
double
average
=
array_
average_val
(
array
,
array_to_int
);
double
total
=
total_val
(
array
,
array_to_int
);
double
average
=
average_val
(
array
,
array_to_int
);
printf
(
"Array total is %lf
\n
"
,
total
);
printf
(
"Array average is %lf
\n
"
,
average
);
...
...
This diff is collapsed.
Click to expand it.
meson.build
+
1
−
1
View file @
bf97bb95
...
...
@@ -8,4 +8,4 @@ l_src = ['array.c', 'mem.c']
lib
=
shared_library
(
'array'
,
l_src
,
dependencies
:
m
)
executable
(
'testarray'
,
'testarray.c'
,
link_with
:
lib
)
executable
(
'
p
av
g
'
,
'
p
av
g
.c'
,
link_with
:
lib
)
executable
(
'av
erage
'
,
'av
erage
.c'
,
link_with
:
lib
)
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