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
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
PREMIERE
PROG_SEQ
dynamic_vectors
Commits
32fc7414
Commit
32fc7414
authored
3 years ago
by
abivarma.kandiah
Browse files
Options
Downloads
Patches
Plain Diff
Add Vector filter
parent
56b778db
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide 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
+12
-0
12 additions, 0 deletions
src/vectors.c
with
24 additions
and
0 deletions
header/vectors.h
+
1
−
0
View file @
32fc7414
...
@@ -31,5 +31,6 @@ void vector_empty(vector vec);
...
@@ -31,5 +31,6 @@ void vector_empty(vector vec);
void
vector_free
(
vector
vec
);
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
));
#endif
#endif
\ No newline at end of file
This diff is collapsed.
Click to expand it.
src/test_vectors.c
+
11
−
0
View file @
32fc7414
...
@@ -12,6 +12,7 @@
...
@@ -12,6 +12,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
);
int
main
()
int
main
()
{
{
...
@@ -63,12 +64,17 @@ int main()
...
@@ -63,12 +64,17 @@ int main()
//Test Vector map
//Test Vector map
vector
test_2
=
vector_map
(
test
,
&
times_two
);
vector
test_2
=
vector_map
(
test
,
&
times_two
);
vector_print
(
test_2
,
&
print_type
);
vector_print
(
test_2
,
&
print_type
);
printf
(
"
\n
"
);
//Test Vector filter
//Test Vector filter
vector
test_3
=
vector_filter
(
test_2
,
lower_than_five
);
vector_print
(
test_3
,
&
print_type
);
printf
(
"
\n
"
);
//Test Vector Free
//Test Vector Free
vector_free
(
test
);
vector_free
(
test
);
vector_free
(
test_2
);
vector_free
(
test_2
);
vector_free
(
test_3
);
return
0
;
return
0
;
}
}
...
@@ -81,4 +87,9 @@ void print_type(type val)
...
@@ -81,4 +87,9 @@ void print_type(type val)
int
times_two
(
type
a
)
int
times_two
(
type
a
)
{
{
return
2
*
a
;
return
2
*
a
;
}
bool
lower_than_five
(
type
a
)
{
return
(
a
<
5
);
}
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
src/vectors.c
+
12
−
0
View file @
32fc7414
...
@@ -147,3 +147,15 @@ vector vector_map(vector vec, type (*f)(type))
...
@@ -147,3 +147,15 @@ vector vector_map(vector vec, type (*f)(type))
return
new_vec
;
return
new_vec
;
}
}
vector
vector_filter
(
vector
vec
,
bool
(
*
f
)(
type
))
{
vector
new_vec
=
vector_create
();
for
(
int
i
=
0
;
i
<
vec
->
length
;
i
++
)
{
if
(
f
(
vec
->
content
[
i
]))
{
vector_push
(
new_vec
,
vec
->
content
[
i
]);
}
}
return
new_vec
;
}
\ 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