Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
E
excit
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
1
Issues
1
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
argo
excit
Commits
4fbca5f8
Commit
4fbca5f8
authored
Jan 07, 2019
by
Brice Videau
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'split' into 'master'
Split refactoring See merge request
!4
parents
2f228ce7
17132c39
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
112 additions
and
156 deletions
+112
-156
cons.c
src/cons.c
+1
-52
excit.c
src/excit.c
+48
-3
excit.h
src/excit.h
+33
-22
prod.c
src/prod.c
+1
-50
repeat.c
src/repeat.c
+28
-28
excit.c
tests/excit.c
+1
-1
No files found.
src/cons.c
View file @
4fbca5f8
...
...
@@ -84,57 +84,6 @@ static int cons_it_size(const excit_t data, ssize_t *size)
return
EXCIT_SUCCESS
;
}
static
int
cons_it_split
(
const
excit_t
data
,
ssize_t
n
,
excit_t
*
results
)
{
ssize_t
size
;
int
err
=
cons_it_size
(
data
,
&
size
);
if
(
err
)
return
err
;
if
(
size
<
n
)
return
-
EXCIT_EDOM
;
if
(
!
results
)
return
EXCIT_SUCCESS
;
excit_t
range
=
excit_alloc
(
EXCIT_RANGE
);
if
(
!
range
)
return
-
EXCIT_ENOMEM
;
err
=
excit_range_init
(
range
,
0
,
size
-
1
,
1
);
if
(
err
)
goto
error1
;
err
=
excit_split
(
range
,
n
,
results
);
if
(
err
)
goto
error1
;
int
i
;
for
(
i
=
0
;
i
<
n
;
i
++
)
{
excit_t
tmp
,
tmp2
;
tmp
=
excit_dup
(
data
);
if
(
!
tmp
)
goto
error2
;
tmp2
=
results
[
i
];
results
[
i
]
=
excit_alloc
(
EXCIT_SLICE
);
if
(
!
results
[
i
])
{
excit_free
(
tmp2
);
goto
error2
;
}
err
=
excit_slice_init
(
results
[
i
],
tmp
,
tmp2
);
if
(
err
)
{
excit_free
(
tmp2
);
goto
error2
;
}
}
excit_free
(
range
);
return
EXCIT_SUCCESS
;
error2:
for
(;
i
>=
0
;
i
--
)
excit_free
(
results
[
i
]);
error1:
excit_free
(
range
);
return
err
;
}
static
int
cons_it_nth
(
const
excit_t
data
,
ssize_t
n
,
ssize_t
*
indexes
)
{
ssize_t
size
;
...
...
@@ -295,7 +244,7 @@ struct excit_func_table_s excit_cons_func_table = {
cons_it_peek
,
cons_it_size
,
cons_it_rewind
,
cons_it_split
,
NULL
,
cons_it_nth
,
cons_it_rank
,
cons_it_pos
...
...
src/excit.c
View file @
4fbca5f8
...
...
@@ -239,9 +239,54 @@ int excit_split(const excit_t it, ssize_t n, excit_t *results)
return
-
EXCIT_EINVAL
;
if
(
n
<=
0
)
return
-
EXCIT_EDOM
;
if
(
!
it
->
func_table
->
split
)
return
-
EXCIT_ENOTSUP
;
return
it
->
func_table
->
split
(
it
,
n
,
results
);
if
(
!
it
->
func_table
->
split
)
{
ssize_t
size
;
int
err
=
excit_size
(
it
,
&
size
);
if
(
err
)
return
err
;
if
(
size
<
n
)
return
-
EXCIT_EDOM
;
if
(
!
results
)
return
EXCIT_SUCCESS
;
excit_t
range
=
excit_alloc
(
EXCIT_RANGE
);
if
(
!
range
)
return
-
EXCIT_ENOMEM
;
err
=
excit_range_init
(
range
,
0
,
size
-
1
,
1
);
if
(
err
)
goto
error1
;
err
=
excit_split
(
range
,
n
,
results
);
if
(
err
)
goto
error1
;
for
(
int
i
=
0
;
i
<
n
;
i
++
)
{
excit_t
tmp
,
tmp2
;
tmp
=
excit_dup
(
it
);
if
(
!
tmp
)
goto
error2
;
tmp2
=
results
[
i
];
results
[
i
]
=
excit_alloc
(
EXCIT_SLICE
);
if
(
!
results
[
i
])
{
excit_free
(
tmp2
);
goto
error2
;
}
err
=
excit_slice_init
(
results
[
i
],
tmp
,
tmp2
);
if
(
err
)
{
excit_free
(
tmp2
);
goto
error2
;
}
}
excit_free
(
range
);
return
EXCIT_SUCCESS
;
error2:
for
(
int
i
=
0
;
i
<
n
;
i
++
)
excit_free
(
results
[
i
]);
error1:
excit_free
(
range
);
return
err
;
}
else
return
it
->
func_table
->
split
(
it
,
n
,
results
);
}
int
excit_nth
(
const
excit_t
it
,
ssize_t
n
,
ssize_t
*
indexes
)
...
...
src/excit.h
View file @
4fbca5f8
...
...
@@ -79,66 +79,66 @@ struct excit_func_table_s {
* allocation, the inner data pointer will already be set.
* Returns EXCIT_SUCCESS or an error code.
*/
int
(
*
alloc
)
(
excit_t
it
);
int
(
*
alloc
)(
excit_t
it
);
/*
* This function is called during excit_free. After this function is
* called the iterator and the data will be freed.
*/
void
(
*
free
)
(
excit_t
it
);
void
(
*
free
)(
excit_t
it
);
/*
* This funciton is called during excit_dup. It is responsible for
* duplicating the content of the inner data between src_it and dst_it.
* Returns EXCIT_SUCCESS or an error code.
*/
int
(
*
copy
)
(
excit_t
dst_it
,
const
excit_t
src_it
);
int
(
*
copy
)(
excit_t
dst_it
,
const
excit_t
src_it
);
/*
* This function is responsible for implementing the next functionality
* of the iterator.
* Returns EXCIT_SUCCESS, EXCIT_STOPIT or an error code.
*/
int
(
*
next
)
(
excit_t
it
,
ssize_t
*
indexes
);
int
(
*
next
)
(
excit_t
it
,
ssize_t
*
indexes
);
/*
* This function is responsible for implementing the peek functionality
* of the iterator.
* Returns EXCIT_SUCCESS, EXCIT_STOPIT or an error code.
*/
int
(
*
peek
)
(
const
excit_t
it
,
ssize_t
*
indexes
);
int
(
*
peek
)
(
const
excit_t
it
,
ssize_t
*
indexes
);
/*
* This function is responsible for implementing the size functionality
* of the iterator.
* Returns EXCIT_SUCCESS or an error code.
*/
int
(
*
size
)
(
const
excit_t
it
,
ssize_t
*
size
);
int
(
*
size
)
(
const
excit_t
it
,
ssize_t
*
size
);
/*
* This function is responsible for implementing the rewind
* functionality of the iterator.
* Returns EXCIT_SUCCESS or an error code.
*/
int
(
*
rewind
)
(
excit_t
it
);
int
(
*
rewind
)(
excit_t
it
);
/*
* This function is responsible for implementing the split
* functionality of the iterator.
* Returns EXCIT_SUCCESS or an error code.
*/
int
(
*
split
)
(
const
excit_t
it
,
ssize_t
n
,
excit_t
*
results
);
int
(
*
split
)
(
const
excit_t
it
,
ssize_t
n
,
excit_t
*
results
);
/*
* This function is responsible for implementing the nth functionality
* of the iterator.
* Returns EXCIT_SUCCESS or an error code.
*/
int
(
*
nth
)
(
const
excit_t
it
,
ssize_t
n
,
ssize_t
*
indexes
);
int
(
*
nth
)
(
const
excit_t
it
,
ssize_t
n
,
ssize_t
*
indexes
);
/*
* This function is responsible for implementing the rank functionality
* of the iterator.
* Returns EXCIT_SUCCESS or an error code.
*/
int
(
*
rank
)
(
const
excit_t
it
,
const
ssize_t
*
indexes
,
ssize_t
*
n
);
int
(
*
rank
)
(
const
excit_t
it
,
const
ssize_t
*
indexes
,
ssize_t
*
n
);
/*
* This function is responsible for implementing the pos functionality
* of the iterator.
* Returns EXCIT_SUCCESS, EXCIT_STOPIT or an error code.
*/
int
(
*
pos
)
(
const
excit_t
it
,
ssize_t
*
n
);
int
(
*
pos
)
(
const
excit_t
it
,
ssize_t
*
n
);
};
/*
...
...
@@ -205,7 +205,7 @@ int excit_type(excit_t it, enum excit_type_e *type);
* "dimension": a pointer where the result will be written.
* Returns EXCIT_SUCCESS or an error code.
*/
int
excit_dimension
(
excit_t
it
,
ssize_t
*
dimension
);
int
excit_dimension
(
excit_t
it
,
ssize_t
*
dimension
);
/*
* Gets the current element of an iterator and increments it.
...
...
@@ -215,7 +215,7 @@ int excit_dimension(excit_t it, ssize_t * dimension);
* Returns EXCIT_SUCCESS if a valid element was retured or EXCIT_STOPIT if the
* iterator is depleted or an error code.
*/
int
excit_next
(
excit_t
it
,
ssize_t
*
indexes
);
int
excit_next
(
excit_t
it
,
ssize_t
*
indexes
);
/*
* Gets the current element of an iterator.
...
...
@@ -225,7 +225,7 @@ int excit_next(excit_t it, ssize_t * indexes);
* Returns EXCIT_SUCCESS if a valid element was retured or EXCIT_STOPIT if the
* iterator is depleted or an error code.
*/
int
excit_peek
(
const
excit_t
it
,
ssize_t
*
indexes
);
int
excit_peek
(
const
excit_t
it
,
ssize_t
*
indexes
);
/*
* Rewinds an iterator to its initial state.
...
...
@@ -240,7 +240,7 @@ int excit_rewind(excit_t it);
* "size": an pointer to the variable where the result will be stored.
* Returns EXCIT_SUCCESS or an error code.
*/
int
excit_size
(
const
excit_t
it
,
ssize_t
*
size
);
int
excit_size
(
const
excit_t
it
,
ssize_t
*
size
);
/*
* Splits an iterator envenly into several suub iterators.
...
...
@@ -251,7 +251,7 @@ int excit_size(const excit_t it, ssize_t * size);
* Returns EXCIT_SUCCESS, -EXCIT_EDOM if the source iterator is too small to be
* subdivised in the wanted number or an error code.
*/
int
excit_split
(
const
excit_t
it
,
ssize_t
n
,
excit_t
*
results
);
int
excit_split
(
const
excit_t
it
,
ssize_t
n
,
excit_t
*
results
);
/*
* Gets the nth element of an iterator.
...
...
@@ -262,7 +262,7 @@ int excit_split(const excit_t it, ssize_t n, excit_t * results);
* iterator, no results is returned if NULL.
* Returns EXCIT_SUCCESS or an error code.
*/
int
excit_nth
(
const
excit_t
it
,
ssize_t
rank
,
ssize_t
*
indexes
);
int
excit_nth
(
const
excit_t
it
,
ssize_t
rank
,
ssize_t
*
indexes
);
/*
* Gets the rank of an element of an iterator.
...
...
@@ -272,7 +272,7 @@ int excit_nth(const excit_t it, ssize_t rank, ssize_t * indexes);
* returned if NULL.
* Returns EXCIT_SUCCESS or an error code.
*/
int
excit_rank
(
const
excit_t
it
,
const
ssize_t
*
indexes
,
ssize_t
*
rank
);
int
excit_rank
(
const
excit_t
it
,
const
ssize_t
*
indexes
,
ssize_t
*
rank
);
/*
* Gets the position of the iterator.
...
...
@@ -282,7 +282,7 @@ int excit_rank(const excit_t it, const ssize_t * indexes, ssize_t * rank);
* Returns EXCIT_SUCCESS or EXCIT_STOPIT if the iterator is depleted or an error
* code.
*/
int
excit_pos
(
const
excit_t
it
,
ssize_t
*
rank
);
int
excit_pos
(
const
excit_t
it
,
ssize_t
*
rank
);
/*
* Increments the iterator.
...
...
@@ -300,7 +300,7 @@ int excit_skip(excit_t it);
* iterator, no results is returned if NULL.
* Returns EXCIT_SUCCESS or an error code.
*/
int
excit_cyclic_next
(
excit_t
it
,
ssize_t
*
indexes
,
int
*
looped
);
int
excit_cyclic_next
(
excit_t
it
,
ssize_t
*
indexes
,
int
*
looped
);
/*
* Initializes a range iterator to iterate from first to last (included) by sep.
...
...
@@ -331,6 +331,17 @@ int excit_cons_init(excit_t it, excit_t src, ssize_t n);
*/
int
excit_repeat_init
(
excit_t
it
,
excit_t
src
,
ssize_t
n
);
/*
* Splits a repeat iterator between repetitions.
* "it": a product iterator.
* "n": number of iterators desired.
* "results": an array of at least n excit_t, or NULL in which case no iterator
* is created.
* Returns EXCIT_SUCCESS, -EXCIT_EDOM if the selected iterator is too small to
* be subdivised in the wanted number or an error code.
*/
int
excit_repeat_split
(
const
excit_t
it
,
ssize_t
n
,
excit_t
*
results
);
/*
* Creates a two dimensional Hilbert space-filling curve iterator.
* "it": an hilbert2d iterator.
...
...
@@ -362,7 +373,7 @@ int excit_product_add_copy(excit_t it, excit_t added_it);
* "count": a pointer to a variable where the result will be stored.
* Returns EXCIT_SUCCESS or an error code.
*/
int
excit_product_count
(
const
excit_t
it
,
ssize_t
*
count
);
int
excit_product_count
(
const
excit_t
it
,
ssize_t
*
count
);
/*
* Splits a product iterator along the nth iterator.
...
...
@@ -376,7 +387,7 @@ int excit_product_count(const excit_t it, ssize_t * count);
* be subdivised in the wanted number or an error code.
*/
int
excit_product_split_dim
(
const
excit_t
it
,
ssize_t
dim
,
ssize_t
n
,
excit_t
*
results
);
excit_t
*
results
);
/*
* Initializes a slice iterator by giving asrc iterator and an indexer iterator.
...
...
src/prod.c
View file @
4fbca5f8
...
...
@@ -221,55 +221,6 @@ static int prod_it_next(excit_t data, ssize_t *indexes)
return
prod_it_peeknext_helper
(
data
,
indexes
,
1
);
}
static
int
prod_it_split
(
const
excit_t
data
,
ssize_t
n
,
excit_t
*
results
)
{
ssize_t
size
;
int
err
=
prod_it_size
(
data
,
&
size
);
if
(
err
)
return
err
;
if
(
size
<
n
)
return
-
EXCIT_EDOM
;
if
(
!
results
)
return
EXCIT_SUCCESS
;
excit_t
range
=
excit_alloc
(
EXCIT_RANGE
);
if
(
!
range
)
return
-
EXCIT_ENOMEM
;
err
=
excit_range_init
(
range
,
0
,
size
-
1
,
1
);
if
(
err
)
goto
error1
;
err
=
excit_split
(
range
,
n
,
results
);
if
(
err
)
goto
error1
;
for
(
int
i
=
0
;
i
<
n
;
i
++
)
{
excit_t
tmp
,
tmp2
;
tmp
=
excit_dup
(
data
);
if
(
!
tmp
)
goto
error2
;
tmp2
=
results
[
i
];
results
[
i
]
=
excit_alloc
(
EXCIT_SLICE
);
if
(
!
results
[
i
])
{
excit_free
(
tmp2
);
goto
error2
;
}
err
=
excit_slice_init
(
results
[
i
],
tmp
,
tmp2
);
if
(
err
)
{
excit_free
(
tmp2
);
goto
error2
;
}
}
excit_free
(
range
);
return
EXCIT_SUCCESS
;
error2:
for
(
int
i
=
0
;
i
<
n
;
i
++
)
excit_free
(
results
[
i
]);
error1:
excit_free
(
range
);
return
err
;
}
int
excit_product_count
(
const
excit_t
it
,
ssize_t
*
count
)
{
if
(
!
it
||
it
->
type
!=
EXCIT_PRODUCT
||
!
count
)
...
...
@@ -362,7 +313,7 @@ struct excit_func_table_s excit_prod_func_table = {
prod_it_peek
,
prod_it_size
,
prod_it_rewind
,
prod_it_split
,
NULL
,
prod_it_nth
,
prod_it_rank
,
prod_it_pos
...
...
src/repeat.c
View file @
4fbca5f8
...
...
@@ -96,7 +96,34 @@ static int repeat_it_pos(const excit_t data, ssize_t *n)
return
EXCIT_SUCCESS
;
}
static
int
repeat_it_split
(
const
excit_t
data
,
ssize_t
n
,
excit_t
*
results
)
struct
excit_func_table_s
excit_repeat_func_table
=
{
repeat_it_alloc
,
repeat_it_free
,
repeat_it_copy
,
repeat_it_next
,
repeat_it_peek
,
repeat_it_size
,
repeat_it_rewind
,
NULL
,
repeat_it_nth
,
NULL
,
repeat_it_pos
};
int
excit_repeat_init
(
excit_t
it
,
excit_t
src
,
ssize_t
n
)
{
if
(
!
it
||
it
->
type
!=
EXCIT_REPEAT
||
!
src
||
n
<=
0
)
return
-
EXCIT_EINVAL
;
struct
repeat_it_s
*
repeat_it
=
(
struct
repeat_it_s
*
)
it
->
data
;
excit_free
(
repeat_it
->
it
);
it
->
dimension
=
src
->
dimension
;
repeat_it
->
it
=
src
;
repeat_it
->
n
=
n
;
repeat_it
->
counter
=
0
;
return
EXCIT_SUCCESS
;
}
int
excit_repeat_split
(
const
excit_t
data
,
ssize_t
n
,
excit_t
*
results
)
{
const
struct
repeat_it_s
*
it
=
(
const
struct
repeat_it_s
*
)
data
->
data
;
int
err
=
excit_split
(
it
->
it
,
n
,
results
);
...
...
@@ -125,30 +152,3 @@ error:
excit_free
(
results
[
i
]);
return
err
;
}
struct
excit_func_table_s
excit_repeat_func_table
=
{
repeat_it_alloc
,
repeat_it_free
,
repeat_it_copy
,
repeat_it_next
,
repeat_it_peek
,
repeat_it_size
,
repeat_it_rewind
,
repeat_it_split
,
repeat_it_nth
,
NULL
,
repeat_it_pos
};
int
excit_repeat_init
(
excit_t
it
,
excit_t
src
,
ssize_t
n
)
{
if
(
!
it
||
it
->
type
!=
EXCIT_REPEAT
||
!
src
||
n
<=
0
)
return
-
EXCIT_EINVAL
;
struct
repeat_it_s
*
repeat_it
=
(
struct
repeat_it_s
*
)
it
->
data
;
excit_free
(
repeat_it
->
it
);
it
->
dimension
=
src
->
dimension
;
repeat_it
->
it
=
src
;
repeat_it
->
n
=
n
;
repeat_it
->
counter
=
0
;
return
EXCIT_SUCCESS
;
}
tests/excit.c
View file @
4fbca5f8
...
...
@@ -372,7 +372,7 @@ void test_repeat_iterator(void)
assert
(
excit_peek
(
it
,
indexes
)
==
EXCIT_STOPIT
);
assert
(
excit_next
(
it
,
indexes
)
==
EXCIT_STOPIT
);
assert
(
excit_split
(
it
,
2
,
its
)
==
ES
);
assert
(
excit_
repeat_
split
(
it
,
2
,
its
)
==
ES
);
for
(
int
i
=
0
;
i
<=
1
;
i
++
)
{
for
(
int
j
=
0
;
j
<
2
;
j
++
)
{
assert
(
excit_peek
(
its
[
0
],
indexes
)
==
ES
);
...
...
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