Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
A
Actor Framework
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
Operations
Operations
Metrics
Environments
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
cpp-libs
Actor Framework
Commits
463c97dd
Commit
463c97dd
authored
Jul 07, 2017
by
Etienne Baratte
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
pack vector<bool> on uint64_t instead of uint8_t
parent
cd85d1d6
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
44 additions
and
19 deletions
+44
-19
libcaf_core/caf/data_processor.hpp
libcaf_core/caf/data_processor.hpp
+44
-19
No files found.
libcaf_core/caf/data_processor.hpp
View file @
463c97dd
...
...
@@ -228,36 +228,61 @@ public:
// Special case to avoid using 1 byte per bool
error
apply
(
std
::
vector
<
bool
>&
x
)
{
uint64_t
len
=
x
.
size
();
auto
err
=
begin_sequence
(
len
);
if
(
err
||
len
==
0
)
// Convert vector<bool> to a vector<uint64>,
// by packing each block of 64 booleans on a 64-bits integer.
// To not waste up to 63 bits, the last uint64_t
// (ie. the last 'remainder' booleans) is encoded as a var-int
auto
remainder
=
static_cast
<
uint8_t
>
(
x
.
size
()
%
64
);
auto
err
=
apply_builtin
(
u8_v
,
&
remainder
);
if
(
err
)
return
err
;
struct
{
size_t
len
;
void
operator
()(
std
::
vector
<
bool
>&
lhs
,
std
::
vector
<
uint8_t
>&
rhs
)
const
{
lhs
.
resize
(
len
,
false
);
void
operator
()(
std
::
vector
<
bool
>&
lhs
,
std
::
vector
<
uint64_t
>&
rhs
)
const
{
lhs
.
resize
(
rhs
.
size
()
*
64
,
false
);
size_t
cpt
=
0
;
for
(
auto
v
:
rhs
)
{
for
(
int
k
=
0
;
k
<
8
;
++
k
)
{
lhs
[
cpt
]
=
((
v
&
(
1
<<
k
))
!=
0
);
if
(
++
cpt
>=
len
)
return
;
for
(
int
k
=
0
;
k
<
64
;
++
k
)
{
lhs
[
cpt
++
]
=
((
v
&
(
1ul
<<
k
))
!=
0
);
}
}
}
void
operator
()(
std
::
vector
<
uint8_t
>&
lhs
,
std
::
vector
<
bool
>&
rhs
)
const
{
size_t
k
=
0
;
lhs
.
resize
((
rhs
.
size
()
-
1
)
/
8
+
1
,
0
);
for
(
bool
b
:
rhs
)
{
void
operator
()(
std
::
vector
<
uint64_t
>&
lhs
,
std
::
vector
<
bool
>&
rhs
)
const
{
if
(
rhs
.
empty
())
return
;
size_t
len
=
rhs
.
size
()
-
rhs
.
size
()
%
64
;
lhs
.
resize
(
len
/
64
,
0
);
for
(
size_t
k
=
0
;
k
<
len
;
++
k
)
{
auto
b
=
rhs
[
k
];
if
(
b
)
lhs
[
k
/
8
]
|=
(
1
<<
(
k
%
8
));
++
k
;
lhs
[
k
/
64
]
|=
(
1ul
<<
(
k
%
64
));
}
}
}
assign
;
assign
.
len
=
len
;
std
::
vector
<
uint8_t
>
tmp
;
return
convert_apply
(
dref
(),
x
,
tmp
,
assign
);
std
::
vector
<
uint64_t
>
tmp
;
err
=
convert_apply
(
dref
(),
x
,
tmp
,
assign
);
if
(
err
||
!
remainder
)
return
err
;
// the last uint64_t for 'remainder' bits
if
(
Derived
::
reads_state
)
{
uint64_t
encoded
=
0
;
auto
len
=
x
.
size
();
for
(
int
k
=
0
;
k
<
remainder
;
++
k
)
{
auto
b
=
x
[
len
-
remainder
+
k
];
if
(
b
)
encoded
|=
(
1ul
<<
k
);
}
return
begin_sequence
(
encoded
);
}
else
{
uint64_t
encoded
=
0
;
err
=
begin_sequence
(
encoded
);
if
(
err
)
return
err
;
x
.
reserve
(
x
.
size
()
+
remainder
);
for
(
int
k
=
0
;
k
<
remainder
;
++
k
)
{
x
.
push_back
((
bool
)
(
encoded
&
(
1ul
<<
k
)));
}
return
none
;
}
}
template
<
class
T
>
...
...
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