Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
argo
excit
Commits
6d4b1ebd
Commit
6d4b1ebd
authored
Jan 10, 2019
by
Nicolas Denoyelle
Browse files
working tests and checkpatch
parent
711bc674
Changes
3
Hide whitespace changes
Inline
Side-by-side
src/excit.h
View file @
6d4b1ebd
...
...
@@ -438,4 +438,5 @@ int excit_tleaf_init(excit_t it,
* "out": an array of n allocated tleaf iterators.
*/
int
tleaf_it_split
(
const
excit_t
it
,
const
ssize_t
level
,
const
ssize_t
n
,
excit_t
*
out
);
#endif
src/tleaf.c
View file @
6d4b1ebd
...
...
@@ -116,8 +116,8 @@ static ssize_t tleaf_it_value(struct tleaf_it_s *it)
ssize_t
i
,
acc
=
1
,
val
=
0
;
for
(
i
=
0
;
i
<
it
->
depth
;
i
++
)
{
val
+=
acc
*
it
->
buf
[
i
];
acc
*=
it
->
arities
[
it
->
order
[
i
]
];
val
+=
acc
*
it
->
buf
[
i
t
->
order
[
it
->
depth
-
i
-
1
]
];
acc
*=
it
->
arities
[
it
->
depth
-
i
-
1
];
}
return
val
;
}
...
...
@@ -129,7 +129,8 @@ int tleaf_it_nth(const excit_t it, ssize_t n, ssize_t *indexes)
if
(
err
!=
EXCIT_SUCCESS
)
return
err
;
*
indexes
=
tleaf_it_value
(
data_it
);
if
(
indexes
!=
NULL
)
*
indexes
=
tleaf_it_value
(
data_it
);
return
EXCIT_SUCCESS
;
}
...
...
@@ -140,7 +141,8 @@ int tleaf_it_peek(const excit_t it, ssize_t *value)
if
(
err
!=
EXCIT_SUCCESS
)
return
err
;
*
value
=
tleaf_it_value
(
data_it
);
if
(
value
!=
NULL
)
*
value
=
tleaf_it_value
(
data_it
);
return
EXCIT_SUCCESS
;
}
...
...
@@ -151,24 +153,35 @@ int tleaf_it_next(excit_t it, ssize_t *indexes)
if
(
err
!=
EXCIT_SUCCESS
)
return
err
;
*
indexes
=
tleaf_it_value
(
data_it
);
if
(
indexes
!=
NULL
)
*
indexes
=
tleaf_it_value
(
data_it
);
return
EXCIT_SUCCESS
;
}
int
tleaf_it_rank
(
const
excit_t
it
,
const
ssize_t
*
indexes
,
ssize_t
*
n
)
{
struct
tleaf_it_s
*
data_it
=
it
->
data
;
ssize_t
size
;
int
err
;
err
=
tleaf_it_size
(
it
,
&
size
);
if
(
err
!=
EXCIT_SUCCESS
)
return
err
;
int
err
=
excit_nth
(
data_it
->
levels_inverse
,
*
indexes
,
data_it
->
buf
);
if
(
indexes
==
NULL
||
*
indexes
<
0
||
*
indexes
>=
size
)
return
-
EXCIT_EINVAL
;
struct
tleaf_it_s
*
data_it
=
it
->
data
;
err
=
excit_nth
(
data_it
->
levels_inverse
,
*
indexes
,
data_it
->
buf
);
if
(
err
!=
EXCIT_SUCCESS
)
return
err
;
ssize_t
i
,
acc
=
1
,
val
=
0
;
for
(
i
=
0
;
i
<
data_it
->
depth
;
i
++
)
{
val
+=
acc
*
data_it
->
buf
[
i
];
acc
*=
data_it
->
arities
[
data_it
->
order_inverse
[
i
]
];
for
(
i
=
data_it
->
depth
-
1
;
i
>=
0
;
i
--
)
{
val
+=
acc
*
data_it
->
buf
[
data_it
->
order_inverse
[
i
]
];
acc
*=
data_it
->
arities
[
i
];
}
*
n
=
val
;
...
...
@@ -191,6 +204,7 @@ static int tleaf_add_level(excit_t levels, const ssize_t arity)
if
(
err
!=
EXCIT_SUCCESS
)
goto
error
;
return
EXCIT_SUCCESS
;
error:
excit_free
(
level
);
return
err
;
...
...
@@ -232,7 +246,7 @@ static int tleaf_init_with_it(excit_t it,
break
;
default:
err
=
-
EXCIT_EINVAL
;
goto
error_with_
levels
;
goto
error_with_
order
;
}
/* Set order inverse */
...
...
@@ -272,7 +286,7 @@ static int tleaf_init_with_it(excit_t it,
for
(
i
=
0
;
i
<
data_it
->
depth
;
i
++
)
{
ssize_t
l
=
data_it
->
order
[
i
];
err
=
tleaf_add_level
(
levels
,
err
=
tleaf_add_level
(
data_it
->
levels
,
data_it
->
arities
[
l
]);
if
(
err
!=
EXCIT_SUCCESS
)
goto
error_with_levels
;
...
...
@@ -290,7 +304,7 @@ static int tleaf_init_with_it(excit_t it,
for
(
i
=
0
;
i
<
data_it
->
depth
;
i
++
)
{
ssize_t
l
=
data_it
->
order_inverse
[
i
];
err
=
tleaf_add_level
(
levels_inverse
,
err
=
tleaf_add_level
(
data_it
->
levels_inverse
,
data_it
->
arities
[
l
]);
if
(
err
!=
EXCIT_SUCCESS
)
goto
error_with_levels_inverse
;
...
...
@@ -362,7 +376,7 @@ int tleaf_it_split(const excit_t it, const ssize_t depth,
struct
tleaf_it_s
*
data_it
=
it
->
data
;
if
(
data_it
->
arities
[
data_it
->
order
[
depth
]
]
%
n
!=
0
)
if
(
data_it
->
arities
[
depth
]
%
n
!=
0
)
return
-
EXCIT_EINVAL
;
int
err
;
...
...
tests/excit_tleaf.c
View file @
6d4b1ebd
...
...
@@ -6,44 +6,36 @@
#include
"excit.h"
#include
"excit_test.h"
static
const
ssize_t
depth
=
4
;
static
const
ssize_t
arities
[
4
]
=
{
4
,
8
,
2
,
4
};
static
excit_t
create_test_tleaf
(
const
enum
tleaf_it_policy_e
policy
,
const
ssize_t
*
user_policy
)
static
excit_t
create_test_tleaf
(
const
ssize_t
depth
,
const
ssize_t
*
arities
,
const
enum
tleaf_it_policy_e
policy
,
const
ssize_t
*
user_policy
)
{
int
err
=
EXCIT_SUCCESS
;
excit_t
it
;
it
=
excit_alloc_test
(
EXCIT_
RANGE
);
it
=
excit_alloc_test
(
EXCIT_
TLEAF
);
assert
(
it
!=
NULL
);
err
=
excit_tleaf_init
(
it
,
depth
,
arities
,
policy
,
user_policy
);
err
=
excit_tleaf_init
(
it
,
depth
+
1
,
arities
,
policy
,
user_policy
);
assert
(
err
==
EXCIT_SUCCESS
);
return
it
;
}
static
inline
ssize_t
tleaf_size
()
{
ssize_t
i
,
size
=
1
;
ssize_t
i
,
size
=
1
,
it_size
;
for
(
i
=
0
;
i
<
depth
;
i
++
)
size
*=
arities
[
i
];
return
size
;
}
static
ssize_t
tleaf_test_size
(
excit_t
tleaf
){
ssize_t
i
,
it_size
,
size
=
tlesf_size
();;
assert
(
excit_size
(
tleaf
,
&
it_size
)
==
EXCIT_SUCCESS
);
assert
(
excit_size
(
it
,
&
it_size
)
==
EXCIT_SUCCESS
);
assert
(
it_size
==
size
);
return
it
;
}
static
void
tleaf_test_round_robin_policy
(
excit_t
tleaf
){
ssize_t
i
,
size
,
value
;
ssize_t
i
,
value
,
size
;
assert
(
excit_size
(
tleaf
,
&
size
)
==
EXCIT_SUCCESS
);
assert
(
excit_rewind
(
tleaf
)
==
EXCIT_SUCCESS
);
for
(
i
=
0
;
i
<
tleaf_
size
()
;
i
++
){
for
(
i
=
0
;
i
<
size
;
i
++
){
assert
(
excit_next
(
tleaf
,
&
value
)
==
EXCIT_SUCCESS
);
assert
(
value
==
i
);
}
...
...
@@ -51,9 +43,10 @@ static void tleaf_test_round_robin_policy(excit_t tleaf){
}
void
tleaf_test_scatter_policy_no_split
(
excit_t
tleaf
){
ssize_t
i
,
j
,
r
,
n
,
c
,
value
,
val
,
size
=
tleaf_size
()
;
static
void
tleaf_test_scatter_policy_no_split
(
excit_t
tleaf
,
const
ssize_t
depth
,
const
ssize_t
*
arities
){
ssize_t
i
,
j
,
r
,
n
,
c
,
value
,
val
,
size
;
assert
(
excit_size
(
tleaf
,
&
size
)
==
EXCIT_SUCCESS
);
assert
(
excit_rewind
(
tleaf
)
==
EXCIT_SUCCESS
);
for
(
i
=
0
;
i
<
size
;
i
++
){
c
=
i
;
...
...
@@ -71,22 +64,35 @@ void tleaf_test_scatter_policy_no_split(excit_t tleaf){
assert
(
excit_next
(
tleaf
,
&
value
)
==
EXCIT_STOPIT
);
}
int
main
(
int
argc
,
char
*
argv
[])
{
excit_t
rrobin
=
create_test_tleaf
(
TLEAF_POLICY_ROUND_ROBIN
,
NULL
);
void
run_tests
(
const
ssize_t
depth
,
const
ssize_t
*
arities
){
excit_t
rrobin
=
create_test_tleaf
(
depth
,
arities
,
TLEAF_POLICY_ROUND_ROBIN
,
NULL
);
assert
(
rrobin
!=
NULL
);
tleaf_test_size
(
rrobin
);
tleaf_test_round_robin_policy
(
rrobin
);
excit_free
(
rrobin
);
excit_t
scatter
=
create_test_tleaf
(
TLEAF_POLICY_
ROUND_ROBIN
,
NULL
);
excit_t
scatter
=
create_test_tleaf
(
depth
,
arities
,
TLEAF_POLICY_
SCATTER
,
NULL
);
assert
(
scatter
!=
NULL
);
tleaf_test_scatter_policy_no_split
(
scatter
);
tleaf_test_scatter_policy_no_split
(
scatter
,
depth
,
arities
);
excit_free
(
scatter
);
return
0
;
int
i
=
0
;
while
(
synthetic_tests
[
i
])
{
excit_t
it
=
create_test_tleaf
(
depth
,
arities
,
TLEAF_POLICY_ROUND_ROBIN
,
NULL
);
synthetic_tests
[
i
](
it
);
excit_free
(
it
);
i
++
;
}
}
int
main
(
int
argc
,
char
*
argv
[])
{
const
ssize_t
depth
=
4
;
const
ssize_t
arities
[
4
]
=
{
4
,
8
,
2
,
4
};
run_tests
(
depth
,
arities
);
return
0
;
}
Write
Preview
Supports
Markdown
0%
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!
Cancel
Please
register
or
sign in
to comment