Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
E
excit
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
argo
excit
Commits
17132c39
Commit
17132c39
authored
Jan 07, 2019
by
Brice Videau
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Normalized split functions.
parent
d1db2a56
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
90 additions
and
134 deletions
+90
-134
src/cons.c
src/cons.c
+1
-52
src/excit.c
src/excit.c
+48
-3
src/excit.h
src/excit.h
+11
-0
src/prod.c
src/prod.c
+1
-50
src/repeat.c
src/repeat.c
+28
-28
tests/excit.c
tests/excit.c
+1
-1
No files found.
src/cons.c
View file @
17132c39
...
...
@@ -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 @
17132c39
...
...
@@ -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 @
17132c39
...
...
@@ -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.
...
...
src/prod.c
View file @
17132c39
...
...
@@ -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 @
17132c39
...
...
@@ -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 @
17132c39
...
...
@@ -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