Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
crystal
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
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
Chris Müller
crystal
Commits
01f10ca1
Commit
01f10ca1
authored
Oct 30, 2012
by
Chris Müller
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
lib: add replace method for arrays.
parent
ee0b4a5c
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
35 additions
and
6 deletions
+35
-6
src/structures/array.c
src/structures/array.c
+32
-5
src/structures/array.h
src/structures/array.h
+3
-1
No files found.
src/structures/array.c
View file @
01f10ca1
...
...
@@ -121,7 +121,7 @@ cry_array_insert(struct CryArray* array, size_t index, pointer data, size_t size
{
assert
(
array
!=
0
);
if
(
index
>
array
->
length
)
if
(
index
>
=
array
->
length
)
return
CRY_OUT_OF_INDEX_RANGE
;
cry_array_ensure
(
array
,
array
->
length
+
size
);
...
...
@@ -135,13 +135,25 @@ cry_array_insert(struct CryArray* array, size_t index, pointer data, size_t size
}
return_code
cry_array_replace
(
struct
CryArray
*
array
,
size_t
index
,
pointer
data
,
size_t
size
)
{
assert
(
array
!=
0
);
if
(
index
>=
array
->
length
&&
index
+
size
>
array
->
length
)
return
CRY_OUT_OF_INDEX_RANGE
;
cry_array_ensure
(
array
,
array
->
length
+
size
);
memcpy
(
array
->
data
+
index
,
data
,
size
);
}
return_code
cry_array_remove
(
struct
CryArray
*
array
,
size_t
index
,
size_t
size
)
{
assert
(
array
!=
0
);
if
(
index
>
array
->
length
)
if
(
index
>
=
array
->
length
)
return
CRY_OUT_OF_INDEX_RANGE
;
memmove
(
array
->
data
+
index
,
array
->
data
+
index
+
size
,
array
->
length
-
index
-
size
);
...
...
@@ -260,7 +272,7 @@ cry_ptr_array_insert(struct CryPtrArray* array, size_t index, pointer ptr)
{
assert
(
array
!=
0
);
if
(
index
>
array
->
length
)
if
(
index
>
=
array
->
length
)
return
CRY_OUT_OF_INDEX_RANGE
;
cry_ptr_array_ensure
(
array
,
array
->
length
+
1
);
...
...
@@ -275,15 +287,30 @@ cry_ptr_array_insert(struct CryPtrArray* array, size_t index, pointer ptr)
}
pointer
cry_ptr_array_replace
(
struct
CryPtrArray
*
array
,
size_t
index
,
pointer
ptr
)
{
assert
(
array
!=
0
);
if
(
index
>=
array
->
length
)
return
0
;
pointer
data
=
*
(
array
->
data
+
index
);
*
(
array
->
data
+
index
)
=
ptr
;
return
data
;
}
pointer
cry_ptr_array_remove
(
struct
CryPtrArray
*
array
,
size_t
index
)
{
assert
(
array
!=
0
);
if
(
index
>
array
->
length
)
if
(
index
>
=
array
->
length
)
return
0
;
pointer
data
=
array
->
data
+
index
;
pointer
data
=
*
(
array
->
data
+
index
)
;
memmove
(
array
->
data
+
index
,
array
->
data
+
index
+
1
,
(
array
->
length
-
index
-
1
)
*
sizeof
(
pointer
));
...
...
src/structures/array.h
View file @
01f10ca1
...
...
@@ -54,6 +54,7 @@ size_t cry_array_trim(struct CryArray* array);
void
cry_array_append
(
struct
CryArray
*
array
,
pointer
data
,
size_t
size
);
return_code
cry_array_insert
(
struct
CryArray
*
array
,
size_t
index
,
pointer
data
,
size_t
size
);
return_code
cry_array_remove
(
struct
CryArray
*
array
,
size_t
index
,
size_t
size
);
return_code
cry_array_replace
(
struct
CryArray
*
array
,
size_t
index
,
pointer
data
,
size_t
size
);
pointer
cry_array_get
(
struct
CryArray
*
array
,
size_t
index
);
...
...
@@ -71,7 +72,8 @@ size_t cry_ptr_array_trim(struct CryPtrArray* array);
void
cry_ptr_array_append
(
struct
CryPtrArray
*
array
,
pointer
ptr
);
return_code
cry_ptr_array_insert
(
struct
CryPtrArray
*
array
,
size_t
index
,
pointer
ptr
);
pointer
cry_ptr_array_remove
(
struct
CryPtrArray
*
array
,
size_t
inndex
);
pointer
cry_ptr_array_remove
(
struct
CryPtrArray
*
array
,
size_t
index
);
pointer
cry_ptr_array_replace
(
struct
CryPtrArray
*
array
,
size_t
index
,
pointer
ptr
);
pointer
cry_ptr_array_get
(
struct
CryPtrArray
*
array
,
size_t
index
);
...
...
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