Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create from words. #15

Merged
merged 1 commit into from
Oct 26, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ v0.2 (not yet released)
* Generic algorithms: ``for_each_block``, ``for_each_block_reversed``
`#14 <https://github.com/msoeken/kitty/pull/14>`_

* Constructors: ``create_from_words``
`#15 <https://github.com/msoeken/kitty/pull/15>`_

* Moved generic operations from `operations.hpp` to `algorithm.hpp`
`#14 <https://github.com/msoeken/kitty/pull/14>`_

Expand Down
1 change: 1 addition & 0 deletions docs/constructors.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ The header ``<kitty/constructors.hpp>`` implements operations to construct truth
create_from_binary_string
create_from_hex_string
create_random
create_from_words
create_from_cubes
create_majority

Expand Down
17 changes: 17 additions & 0 deletions include/kitty/constructors.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,23 @@ void create_random( TT& tt )
create_random( tt, std::chrono::system_clock::now().time_since_epoch().count() );
}

/*! \brief Constructs a truth table from a range of words

The range of words is given in terms of a begin and end iterator.
Hence, it's possible to copy words from a C++ container or a C
array.

\param tt Truth table
\param begin Begin iterator
\param end End iterator
*/
template<typename TT, typename InputIt>
void create_from_words( TT& tt, InputIt begin, InputIt end )
{
assert( std::distance( begin, end ) == tt.num_blocks() );
std::copy( begin, end, tt.begin() );
}

/*! \brief Creates truth table from cubes representation

A sum-of-product is represented as a vector of products (called
Expand Down
15 changes: 15 additions & 0 deletions test/constructors.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,21 @@ TEST( ConstructorsTest, create_random )
EXPECT_TRUE( true ); /* a dummy test to enable the print out */
}

TEST( ConstructorsTest, create_from_words )
{
std::vector<uint64_t> words_vec{0xfee8e880e8808000, 0xfffefee8fee8e880};
constexpr uint64_t words_arr[]{0xfee8e880e8808000, 0xfffefee8fee8e880};

static_truth_table<7> tt_v, tt_a, tt_s;

create_from_words( tt_v, words_vec.begin(), words_vec.end() );
create_from_words( tt_a, words_arr, words_arr + 2 );
create_majority( tt_s );

EXPECT_EQ( tt_v, tt_s );
EXPECT_EQ( tt_a, tt_s );
}

TEST( ConstructorsTest, create_majority5 )
{
static_truth_table<5> tt_s;
Expand Down