Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
Chris Müller
crystal
Commits
25e8370c
Commit
25e8370c
authored
Oct 30, 2012
by
Chris Müller
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
lib: add clear and each method to pointer arrays.
parent
01f10ca1
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
26 additions
and
0 deletions
+26
-0
src/structures/array.c
src/structures/array.c
+24
-0
src/structures/array.h
src/structures/array.h
+1
-0
src/structures/structures.h
src/structures/structures.h
+1
-0
No files found.
src/structures/array.c
View file @
25e8370c
...
...
@@ -331,5 +331,29 @@ cry_ptr_array_get(struct CryPtrArray* array, size_t index)
return
0
;
}
void
cry_ptr_array_clear
(
struct
CryPtrArray
*
array
,
cry_free_funptr
fun
)
{
assert
(
array
!=
0
);
if
(
fun
!=
0
)
{
size_t
index
=
0
;
for
(
index
=
0
;
index
<
array
->
length
;
++
index
)
fun
(
*
(
array
->
data
+
index
));
}
array
->
length
=
0
;
}
void
cry_ptr_array_each
(
struct
CryPtrArray
*
array
,
cry_foreach_funptr
fun
,
pointer
data
)
{
assert
(
array
!=
0
&&
fun
!=
0
);
size_t
index
=
0
;
for
(
index
=
0
;
index
<
array
->
length
;
++
index
)
{
fun
(
*
(
array
->
data
+
index
),
data
);
}
}
src/structures/array.h
View file @
25e8370c
...
...
@@ -77,6 +77,7 @@ pointer cry_ptr_array_replace(struct CryPtrArray* array, size_t index, pointer
pointer
cry_ptr_array_get
(
struct
CryPtrArray
*
array
,
size_t
index
);
void
cry_ptr_array_each
(
struct
CryPtrArray
*
array
,
cry_foreach_funptr
fun
,
pointer
data
);
#endif // CRYSTAL_STRUCTURES_ARRAY_H
src/structures/structures.h
View file @
25e8370c
...
...
@@ -26,6 +26,7 @@
#define CRY_ENTRY_FULL -3
typedef
int
(
*
cry_ordering_funptr
)(
const_pointer
a
,
const_pointer
b
);
typedef
void
(
*
cry_foreach_funptr
)(
pointer
element
,
pointer
data
);
typedef
void
(
*
cry_free_funptr
)(
pointer
data
);
int
cry_int_compare
(
const_pointer
a
,
const_pointer
b
);
...
...
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