ABC: A System for Sequential Synthesis and Verification
 
Loading...
Searching...
No Matches
kitty_algorithm.hpp
Go to the documentation of this file.
1#ifndef _KITTY_ALGORITHM_H_
2#define _KITTY_ALGORITHM_H_
3#pragma once
4
5#include <algorithm>
6#include <cassert>
7
8#include "kitty_constants.hpp"
10#include "kitty_static_tt.hpp"
11
13
14namespace kitty
15{
16
24template<typename TT, typename Fn>
25TT unary_operation( const TT& tt, Fn&& op )
26{
27 TT result = tt.construct();
28 std::transform( tt.cbegin(), tt.cend(), result.begin(), op );
29 result.mask_bits();
30 return result;
31}
32
45template<typename TT, typename Fn>
46TT binary_operation( const TT& first, const TT& second, Fn&& op )
47{
48 assert( first.num_vars() == second.num_vars() );
49
50 TT result = first.construct();
51 std::transform( first.cbegin(), first.cend(), second.cbegin(), result.begin(), op );
52 result.mask_bits();
53 return result;
54}
55
68template<typename TT, typename Fn>
69bool binary_predicate( const TT& first, const TT& second, Fn&& op )
70{
71 assert( first.num_vars() == second.num_vars() );
72
73 return std::equal( first.begin(), first.end(), second.begin(), op );
74}
75
84template<typename TT, typename Fn>
85void assign_operation( TT& tt, Fn&& op )
86{
87 std::generate( tt.begin(), tt.end(), op );
88 tt.mask_bits();
89}
90
98template<typename TT, typename Fn>
99void for_each_block( const TT& tt, Fn&& op )
100{
101 std::for_each( tt.cbegin(), tt.cend(), op );
102}
103
113template<typename TT, typename Fn>
114void for_each_block_reversed( const TT& tt, Fn&& op )
115{
116 std::for_each( tt.crbegin(), tt.crend(), op );
117}
118
119} // namespace kitty
120
122
123#endif // _KITTY_ALGORITHM_H_
#define ABC_NAMESPACE_CXX_HEADER_START
#define ABC_NAMESPACE_CXX_HEADER_END
TT binary_operation(const TT &first, const TT &second, Fn &&op)
Perform bitwise binary operation on two truth tables.
bool binary_predicate(const TT &first, const TT &second, Fn &&op)
Computes a predicate based on two truth tables.
void assign_operation(TT &tt, Fn &&op)
Assign computed values to bits.
void for_each_block_reversed(const TT &tt, Fn &&op)
Iterates through each block of a truth table in reverse order.
TT unary_operation(const TT &tt, Fn &&op)
Perform bitwise unary operation on truth table.
void for_each_block(const TT &tt, Fn &&op)
Iterates through each block of a truth table.
#define assert(ex)
Definition util_old.h:213