void iq_test(void) { int i ; for(i=1;i<10000000;i++) { iq_t iq = iq_create(name) ; if ((i % 1) == 0) { eprintf("IQ:test(%d)\n", i) ; } while (1) { switch(util_random(2)) { case 0: { marsh_t marsh = marsh_create(NULL) ; marsh_buf_t buf = marsh_to_buf(name, marsh) ; marsh_free(marsh) ; if (!iq_assign(iq, util_random(IQ_CHECK_SIZE), buf, iov)) { iovec_free(iov) ; marsh_buf_free(buf) ; } } break ; case 1: { marsh_buf_t buf ; seqno_t seqno ; iovec_t iov ; if (!iq_get_prefix(iq, &seqno, &buf, &iov)) { break ; } //eprintf("seqno=%d\n", seqno) ; iovec_free(iov) ; marsh_buf_free(buf) ; if (seqno >= IQ_CHECK_SIZE - 1) { goto out ; } } break ; case 2: { marsh_t marsh = marsh_create(NULL) ; marsh_buf_t buf = marsh_to_buf(name, marsh) ; iovec_t iov = iovec_empty(name) ; marsh_free(marsh) ; iq_add(iq, buf, iov) ; } break ; case 3: { marsh_t marsh = marsh_create(NULL) ; marsh_buf_t buf = marsh_to_buf(name, marsh) ; iovec_t iov = iovec_empty(name) ; marsh_free(marsh) ; if (!iq_opt_insert_check_doread(iq, util_random(IQ_CHECK_SIZE), buf, iov)) { iovec_free(iov) ; marsh_buf_free(buf) ; } } break ; } } out: iq_free(iq) ; } }
// okay just make a bfs and then add in like an extra counter // that counts number of things added to list and then short circuit il* limited_bfs(graph *g, unsigned int start_key, unsigned int max_steps) { // check for errors if (start_key>=g->n_vertices) { fprintf(stderr,"bfs: no such vertex (%u)\n",start_key); exit(1); } il *prev_reached, *reached; reached = NULL; iq *q = iq_new(); int curr; int list_elements = 0; enqueue(q, start_key); while (q->n > 0) { curr = dequeue(q); if (g->vs[curr]->done) continue; g->vs[curr]->done = 1; prev_reached = reached; reached = il_append(prev_reached,il_singleton(curr)); il_free(prev_reached); list_elements++; if (list_elements >= max_steps) { iq_free(q); return reached; } il *neighbors = g->es[curr]; while (neighbors != NULL) { int n = neighbors->n; enqueue(q,n); neighbors = neighbors->next; } } iq_free(q); return reached; }