github.com/igggame/nebulas-go@v2.1.0+incompatible/nbre/test/runtime/nr/test_algo.cpp (about) 1 // Copyright (C) 2018 go-nebulas authors 2 // 3 // This file is part of the go-nebulas library. 4 // 5 // the go-nebulas library is free software: you can redistribute it and/or 6 // modify 7 // it under the terms of the GNU General Public License as published by 8 // the Free Software Foundation, either version 3 of the License, or 9 // (at your option) any later version. 10 // 11 // the go-nebulas library is distributed in the hope that it will be useful, 12 // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 // GNU General Public License for more details. 15 // 16 // You should have received a copy of the GNU General Public License 17 // along with the go-nebulas library. If not, see 18 // <http://www.gnu.org/licenses/>. 19 // 20 21 #include "runtime/nr/graph/algo.h" 22 #include "util/chrono.h" 23 24 int main(int argc, char *argv[]) { 25 neb::rt::transaction_graph tg; 26 int32_t n = std::stoi(argv[1]); 27 std::string s = argv[2]; 28 char cc = s[0]; 29 int opt = std::stoi(argv[3]); 30 31 for (char ch = 'a'; ch < cc; ch++) { 32 for (int32_t i = 0; i < n; i++) { 33 tg.add_edge(neb::to_address(std::string(1, ch)), 34 neb::to_address(std::string(1, ch + 1)), ch - 'a' + 1, 35 ch - 'a' + 1); 36 } 37 } 38 for (int32_t i = 0; i < n; i++) { 39 tg.add_edge(neb::to_address(std::string(1, cc)), 40 neb::to_address(std::string(1, 'a')), cc - 'a' + 1, 0); 41 } 42 43 auto start_ts = neb::util::now(); 44 auto &graph = tg.internal_graph(); 45 if (opt == 0) { 46 LOG(INFO) << "start to remove cycle"; 47 neb::rt::graph_algo::remove_cycles_based_on_time_sequence(graph); 48 LOG(INFO) << "done with remove cycle"; 49 } else if (opt == 1) { 50 LOG(INFO) << "start to remove cycle"; 51 neb::rt::graph_algo::non_recursive_remove_cycles_based_on_time_sequence( 52 graph); 53 LOG(INFO) << "done with remove cycle"; 54 } 55 auto end_ts = neb::util::now(); 56 std::cout << "ts: " << end_ts - start_ts << std::endl; 57 58 return 0; 59 }