22#if defined(__cpp_lib_is_invocable)
23 template <
typename Fn,
typename... Args>
26 template <
typename Fn,
typename... Args>
27 struct is_invokable: std::is_constructible<std::function<void(Args...)>, std::reference_wrapper<typename std::remove_reference<Fn>::type>> {};
34 template <
template <
typename...>
typename Container,
typename... Ts>
35 static inline int int_size(Container<Ts...>
const &c) {
36 assert(c.size() <= (
typename Container<Ts...>::size_type)std::numeric_limits<int>::max());
40 template <
template <
typename...>
typename Container,
typename... Ts>
41 static inline bool check_int_size(Container<Ts...>
const &c) {
42 return c.size() <= (
typename Container<Ts...>::size_type)std::numeric_limits<int>::max();
45 static inline bool check_int_max(
int i) {
46 return i == std::numeric_limits<int>::max();
49 template <
typename Iterator>
50 static inline int int_distance(Iterator begin, Iterator it) {
51 typename std::iterator_traits<Iterator>::difference_type d = std::distance(begin, it);
52 assert(d <= (
typename std::iterator_traits<Iterator>::difference_type)std::numeric_limits<int>::max());
53 assert(d >= (
typename std::iterator_traits<Iterator>::difference_type)std::numeric_limits<int>::lowest());
62 std::ostream&
operator<<(std::ostream& os,
const std::vector<T>& v) {
74 std::ostream&
operator<<(std::ostream& os,
const std::set<T>& s) {
88 ForEachEdge([&] (
int id,
bool c) {
89 std::cout << delim << (c?
"!":
"") <<
id;
106 template <
typename T>
108 template <
typename T,
typename... Args>
109 void PrintNext(std::ostream &os, T t, Args... args);
111 static inline void PrintNext(std::ostream &os,
int t) {
112 os << std::setw(4) << t;
115 template <
typename... Args>
116 static inline void PrintNext(std::ostream &os,
int t, Args... args) {
117 os << std::setw(4) << t <<
" ";
121 static inline void PrintNext(std::ostream &os,
bool arg) {
125 template <
typename... Args>
126 static inline void PrintNext(std::ostream &os,
bool arg, Args... args) {
135 static inline void PrintNext(std::ostream &os,
double t) {
136 os << std::fixed << std::setprecision(2) << std::setw(8) << t;
139 template <
typename... Args>
140 static inline void PrintNext(std::ostream &os,
double t, Args... args) {
141 os << std::fixed << std::setprecision(2) << std::setw(8) << t <<
" ";
145 template <
typename T>
146 static inline void PrintNext(std::ostream &os,
SW sw, T arg) {
150 os << std::setw(sw.width) << arg;
156 template <
typename T,
typename... Args>
157 static inline void PrintNext(std::ostream &os,
SW sw, T arg, Args... args) {
161 os << std::setw(sw.width) << arg <<
" ";
168 template <
typename T,
typename... Args>
169 static inline void PrintNext(std::ostream &os,
NS ns, T arg, Args... args) {
175 template <
typename T>
176 static inline void PrintNext(std::ostream& os, std::vector<T>
const &arg) {
178 for(T
const &e: arg) {
185 template <
typename T,
typename... Args>
186 static inline void PrintNext(std::ostream& os, std::vector<T>
const &arg, Args... args) {
188 for(T
const &e: arg) {
196 template <
typename T>
197 static inline void PrintNext(std::ostream& os, std::set<T>
const &arg) {
199 for(T
const &e: arg) {
206 template <
typename T,
typename... Args>
207 static inline void PrintNext(std::ostream& os, std::set<T>
const &arg, Args... args) {
209 for(T
const &e: arg) {
217 template <
typename T>
222 template <
typename T,
typename... Args>
232 static inline void PrintWarning(std::string message) {
233 std::cerr <<
"[w] " << message << std::endl;
244 for(
int i = v.back() + 1; i < n - k + 1; i++) {
254 static inline void ForEachCombinationStop(
int n,
int k, std::function<
bool(std::vector<int>
const &)>
const &func) {
282 static inline char GetVarValueChar(
VarValue x) {
304 static inline char const *GetActionTypeCstr(
Action const &action) {
305 switch(action.type) {
307 return "remove fanin";
309 return "remove unused";
311 return "remove buffer";
313 return "remove const";
317 return "trivial collapse";
319 return "trivial decompose";
321 return "sort fanins";
338 static inline std::stringstream GetActionDescription(
Action const &action) {
339 std::stringstream ss;
340 ss << GetActionTypeCstr(action);
341 std::string delim =
" : ";
342 if(action.id != -1) {
347 if(action.fi != -1) {
349 PrintNext(ss,
"fanin", (
bool)action.c, action.fi);
352 if(action.idx != -1) {
360 if(!action.vFanins.empty()) {
364 if(!action.vIndices.empty()) {
368 if(!action.vFanouts.empty()) {
380 return clock_type::now();
384 seconds t = (std::chrono::duration_cast<std::chrono::seconds>(end - start)).count();
390 double t = (std::chrono::duration<double>(end - start)).count();
#define ABC_NAMESPACE_CXX_HEADER_START
#define ABC_NAMESPACE_CXX_HEADER_END
void PrintComplementedEdges(std::function< void(std::function< void(int, bool)> const &)> const &ForEachEdge)
void PrintNext(std::ostream &os, T t)
bool ForEachCombinationStopRec(std::vector< int > &v, int n, int k, std::function< bool(std::vector< int > const &)> const &func)
std::chrono::time_point< clock_type > time_point
std::ostream & operator<<(std::ostream &os, const std::vector< T > &v)