| 91 | } |
| 92 | |
| 93 | static bool check_diff(const char* new_file, const char* old_file, |
| 94 | const DIFF_RES* res = NULL) |
| 95 | { |
| 96 | // 首先定义差集比较器 |
| 97 | acl::diff_manager manager; |
| 98 | // 存放当前对象 |
| 99 | std::vector<acl::diff_object*> cur_objs; |
| 100 | // 存放旧的对象 |
| 101 | std::vector<acl::diff_object*> old_objs; |
| 102 | |
| 103 | // 先从文件中读取当前的对象至新对象集合中 |
| 104 | int n = load_objs(manager, new_file, cur_objs); |
| 105 | if (n < 0) |
| 106 | { |
| 107 | printf("load curr objs error from %s\r\n", new_file); |
| 108 | return false; |
| 109 | } |
| 110 | printf("cur objs: %d\r\n", n); |
| 111 | |
| 112 | // 再从文件中读取旧的对象至旧对象集合中 |
| 113 | n = load_objs(manager, old_file, old_objs); |
| 114 | if (n < 0) |
| 115 | { |
| 116 | printf("load old objs error from %s\r\n", old_file); |
| 117 | return false; |
| 118 | } |
| 119 | |
| 120 | struct timeval begin; |
| 121 | gettimeofday(&begin, NULL); |
| 122 | |
| 123 | // 开始进行差集比较,并获得最终新增对象人个数 |
| 124 | manager.diff_changes(cur_objs, old_objs); |
| 125 | |
| 126 | struct timeval end; |
| 127 | gettimeofday(&end, NULL); |
| 128 | |
| 129 | double spent = acl::stamp_sub(end, begin); |
| 130 | printf("spent: %.4f ms\r\n", spent); |
| 131 | |
| 132 | printf("-------------------------------------------------------\r\n"); |
| 133 | |
| 134 | // 获得新增对象集合 |
| 135 | const std::vector<acl::diff_object*>& new_objs = manager.get_new(); |
| 136 | |
| 137 | // 打印新增对象至屏幕,限定最大输出 10 个 |
| 138 | print_objs(new_objs, "new objs", 10); |
| 139 | printf("new nobjs: %d\r\n", (int) new_objs.size()); |
| 140 | |
| 141 | printf("-------------------------------------------------------\r\n"); |
| 142 | |
| 143 | // 获得被删除的对象集合 |
| 144 | const std::vector<acl::diff_object*>& del_objs = manager.get_deleted(); |
| 145 | |
| 146 | // 打印删除的对象至屏幕,限定最大输出 10 个 |
| 147 | print_objs(del_objs, "deleted objs", 10); |
| 148 | printf("deleted objs: %d\r\n", (int) del_objs.size()); |
| 149 | |
| 150 | printf("-------------------------------------------------------\r\n"); |
no test coverage detected
searching dependent graphs…