Beispiel #1
0
/* Find the second minimum spanning tree. */
int smst(struct edge *edges, int edges_number,
		 int vertices_number, int *path, int x)
{
	int i, cost = 0;
	int ans = 0;
	int sets[MAX_EDGES];

	init_sets(sets, vertices_number);

	for (i = 0; i < edges_number; i++) {
		int root_x = find_set_root(sets, edges[i].x);
		int root_y = find_set_root(sets, edges[i].y);

		/* Combine two sets. */
		if (root_x != root_y && i != x) {
			cost += edges[i].weight;
			sets[root_x] = root_y;
		}
	}

	/* Check is there have two root of set? */
	for (i = 1; i <= vertices_number; i++) {
		if (sets[i] == i)
			ans++;
	}

	/* INF means no way to reach. */
	return ans == 1 ? cost : INF;
}
Beispiel #2
0
void
io_service::process_io(void) {
  struct pollfd fds[_CPP_REDIS_MAX_NB_FDS];

  __CPP_REDIS_LOG(debug, "cpp_redis::network::io_service starts poll loop in worker thread");

  while (!m_should_stop) {
    std::size_t nfds = init_sets(fds);

    if (poll(fds, static_cast<nfds_t>(nfds), -1) > 0) {
      __CPP_REDIS_LOG(debug, "cpp_redis::network::io_service woke up by poll");
      process_sets(fds, nfds);
    }
    else {
      __CPP_REDIS_LOG(debug, "cpp_redis::network::io_service woke up by poll, but nothing to process");
    }
  }

  __CPP_REDIS_LOG(debug, "cpp_redis::network::io_service ends poll loop in worker thread");
}