Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
corpus2
Manage
Activity
Members
Labels
Plan
Issues
4
Issue boards
Milestones
Wiki
Redmine
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Analysers
corpus2
Commits
7ea7f186
There was an error fetching the commit references. Please try again later.
Commit
7ea7f186
authored
14 years ago
by
ilor
Browse files
Options
Downloads
Patches
Plain Diff
Pwrutiuls: add set_bits_iterator with a test, bump version to 0.0.3
parent
42a70f5f
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
libpwrutils/CMakeLists.txt
+1
-1
1 addition, 1 deletion
libpwrutils/CMakeLists.txt
libpwrutils/bitset.h
+64
-1
64 additions, 1 deletion
libpwrutils/bitset.h
tests/tag_split.cpp
+12
-0
12 additions, 0 deletions
tests/tag_split.cpp
with
77 additions
and
2 deletions
libpwrutils/CMakeLists.txt
+
1
−
1
View file @
7ea7f186
...
@@ -4,7 +4,7 @@ PROJECT(pwrutils)
...
@@ -4,7 +4,7 @@ PROJECT(pwrutils)
set
(
pwrutils_ver_major
"0"
)
set
(
pwrutils_ver_major
"0"
)
set
(
pwrutils_ver_minor
"0"
)
set
(
pwrutils_ver_minor
"0"
)
set
(
pwrutils_ver_patch
"
2
"
)
set
(
pwrutils_ver_patch
"
3
"
)
set
(
LIBPWRUTILS_VERSION
set
(
LIBPWRUTILS_VERSION
"
${
pwrutils_ver_major
}
.
${
pwrutils_ver_minor
}
.
${
pwrutils_ver_patch
}
"
)
"
${
pwrutils_ver_major
}
.
${
pwrutils_ver_minor
}
.
${
pwrutils_ver_patch
}
"
)
...
...
This diff is collapsed.
Click to expand it.
libpwrutils/bitset.h
+
64
−
1
View file @
7ea7f186
...
@@ -58,6 +58,69 @@ inline size_t lowest_bit(const unsigned long& t)
...
@@ -58,6 +58,69 @@ inline size_t lowest_bit(const unsigned long& t)
return
boost
::
lowest_bit
(
t
);
return
boost
::
lowest_bit
(
t
);
}
}
/// Helper iterator class for iterating through set bits
template
<
typename
T
>
struct
set_bits_iterator
{
typedef
T
value_type
;
typedef
std
::
forward_iterator_tag
iterator_category
;
typedef
int
difference_type
;
typedef
const
T
*
pointer
;
typedef
const
T
&
reference
;
set_bits_iterator
(
const
set_bits_iterator
&
i
)
:
i_
(
i
.
i_
),
c_
(
i
.
c_
)
{}
set_bits_iterator
(
const
T
&
i
)
:
i_
(
i
),
c_
(
0
)
{
adv
();
}
set_bits_iterator
&
operator
++
()
{
adv
();
return
*
this
;
}
set_bits_iterator
operator
++
(
int
)
{
set_bits_iterator
c
(
*
this
);
c
.
adv
();
return
c
;
}
bool
operator
==
(
const
set_bits_iterator
&
i
)
const
{
return
i_
==
i
.
i_
&&
c_
==
i
.
c_
;
}
bool
operator
!=
(
const
set_bits_iterator
&
i
)
const
{
return
i_
!=
i
.
i_
||
c_
!=
i
.
c_
;
}
const
T
&
operator
*
()
const
{
return
c_
;
}
private
:
void
adv
()
{
c_
.
reset
();
if
(
i_
.
any
())
{
c_
.
set
(
lowest_bit
(
i_
));
i_
^=
c_
;
}
}
T
i_
;
T
c_
;
};
/**
* Function that returns a foreach-compatible iterator range that allows
* iterating through the set bits of a bitset. It only makes sense to read
* from the returned range.
*
* Example usage: \code
* foreach (const bitset<32>& b, my_bitset) {
* foo_with(b);
* }
* \endcode
*/
template
<
size_t
S
>
boost
::
iterator_range
<
set_bits_iterator
<
std
::
bitset
<
S
>
>
>
set_bits
(
const
bitset
<
S
>&
bs
)
{
return
boost
::
iterator_range
<
set_bits_iterator
<
std
::
bitset
<
S
>
>
>
(
bs
,
bitset
<
S
>
()
);
}
}
/* end ns PwrNlp */
}
/* end ns PwrNlp */
namespace
std
{
namespace
std
{
...
@@ -106,6 +169,6 @@ bool operator<(bitset<PwrNlp::ulong_bits> left, bitset<PwrNlp::ulong_bits> right
...
@@ -106,6 +169,6 @@ bool operator<(bitset<PwrNlp::ulong_bits> left, bitset<PwrNlp::ulong_bits> right
return
left
.
to_ulong
()
<
right
.
to_ulong
();
return
left
.
to_ulong
()
<
right
.
to_ulong
();
}
}
}
}
/* end ns std */
#endif // PWRNLP_BITSET_H
#endif // PWRNLP_BITSET_H
This diff is collapsed.
Click to expand it.
tests/tag_split.cpp
+
12
−
0
View file @
7ea7f186
#include
<boost/test/unit_test.hpp>
#include
<boost/test/unit_test.hpp>
#include
<set>
#include
<set>
#include
<libpwrutils/foreach.h>
#include
<libpwrutils/foreach.h>
#include
<libpwrutils/bitset.h>
#include
<libcorpus2/tagset.h>
#include
<libcorpus2/tagset.h>
#include
<libcorpus2/token.h>
#include
<libcorpus2/token.h>
...
@@ -196,3 +197,14 @@ BOOST_FIXTURE_TEST_CASE( tag_size, F )
...
@@ -196,3 +197,14 @@ BOOST_FIXTURE_TEST_CASE( tag_size, F )
}
}
BOOST_AUTO_TEST_SUITE_END
()
BOOST_AUTO_TEST_SUITE_END
()
BOOST_AUTO_TEST_CASE
(
bs_split
)
{
std
::
bitset
<
32
>
x
(
0xf6543
);
std
::
bitset
<
32
>
y
(
0
);
foreach
(
std
::
bitset
<
32
>
b
,
PwrNlp
::
set_bits
(
x
))
{
BOOST_CHECK_EQUAL
(
b
.
count
(),
1
);
y
|=
b
;
}
BOOST_CHECK_EQUAL
(
x
,
y
);
}
This diff is collapsed.
Click to expand it.
Preview
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!
Save comment
Cancel
Please
register
or
sign in
to comment