Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
dynamic_vectors
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
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
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
PREMIERE
PROG_SEQ
dynamic_vectors
Commits
71e7f697
Commit
71e7f697
authored
3 years ago
by
abivarma.kandiah
Browse files
Options
Downloads
Patches
Plain Diff
add Vector Reduce
parent
32fc7414
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
header/vectors.h
+1
-0
1 addition, 0 deletions
header/vectors.h
src/test_vectors.c
+11
-0
11 additions, 0 deletions
src/test_vectors.c
src/vectors.c
+9
-0
9 additions, 0 deletions
src/vectors.c
with
21 additions
and
0 deletions
header/vectors.h
+
1
−
0
View file @
71e7f697
...
@@ -32,5 +32,6 @@ void vector_free(vector vec);
...
@@ -32,5 +32,6 @@ void vector_free(vector vec);
void
vector_print
(
vector
vec
,
void
(
*
print
)(
type
));
void
vector_print
(
vector
vec
,
void
(
*
print
)(
type
));
vector
vector_map
(
vector
vec
,
type
(
*
f
)(
type
));
vector
vector_map
(
vector
vec
,
type
(
*
f
)(
type
));
vector
vector_filter
(
vector
vec
,
bool
(
*
f
)(
type
));
vector
vector_filter
(
vector
vec
,
bool
(
*
f
)(
type
));
type
vector_reduce
(
vector
vec
,
type
neutral
,
type
(
*
f
)(
type
,
type
));
#endif
#endif
\ No newline at end of file
This diff is collapsed.
Click to expand it.
src/test_vectors.c
+
11
−
0
View file @
71e7f697
...
@@ -13,6 +13,7 @@
...
@@ -13,6 +13,7 @@
void
print_type
(
type
val
);
void
print_type
(
type
val
);
int
times_two
(
type
a
);
int
times_two
(
type
a
);
bool
lower_than_five
(
type
a
);
bool
lower_than_five
(
type
a
);
type
add
(
type
lhs
,
type
rhs
);
int
main
()
int
main
()
{
{
...
@@ -71,6 +72,11 @@ int main()
...
@@ -71,6 +72,11 @@ int main()
vector_print
(
test_3
,
&
print_type
);
vector_print
(
test_3
,
&
print_type
);
printf
(
"
\n
"
);
printf
(
"
\n
"
);
//Test Vector Reduce
type
sum
=
vector_reduce
(
test_3
,
0
,
add
);
print_type
(
sum
);
printf
(
"
\n
"
);
//Test Vector Free
//Test Vector Free
vector_free
(
test
);
vector_free
(
test
);
vector_free
(
test_2
);
vector_free
(
test_2
);
...
@@ -93,3 +99,8 @@ bool lower_than_five(type a)
...
@@ -93,3 +99,8 @@ bool lower_than_five(type a)
{
{
return
(
a
<
5
);
return
(
a
<
5
);
}
}
type
add
(
type
lhs
,
type
rhs
)
{
return
lhs
+
rhs
;
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
src/vectors.c
+
9
−
0
View file @
71e7f697
...
@@ -159,3 +159,12 @@ vector vector_filter(vector vec, bool (*f)(type))
...
@@ -159,3 +159,12 @@ vector vector_filter(vector vec, bool (*f)(type))
}
}
return
new_vec
;
return
new_vec
;
}
}
type
vector_reduce
(
vector
vec
,
type
neutral
,
type
(
*
f
)(
type
,
type
))
{
for
(
int
i
=
0
;
i
<
vec
->
length
;
i
++
)
{
neutral
=
f
(
neutral
,
vec
->
content
[
i
]);
}
return
neutral
;
}
\ No newline at end of file
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