/* Invocation:
 *  $0 INPUT-FILE OUTPUTFILE
 */
int main(int argc, char **argv)
{
	assert(argc == 3);
	(void) argc;
	const char *const filename_in= argv[1];
	const char *const filename_out= argv[2];

	struct sgraph1_reader_a r;

	if (0 > sgraph1_open_read_a(filename_in, &r, 2)) {
		exit(1); 
	}

	if (0 > sgraph1_advise_a(&r, MADV_RANDOM)) {
		perror(filename_in);
		exit(1); 
	}

	unsigned char *lcc= lcc_find(&r);

	if (0 > sgraph1_subgraph_a(&r, lcc, filename_out)) {
		exit(1); 
	}

	exit(0); 
}
Example #2
0
int main(int argc, char **argv)
{
	if (argc != 3) {
		fprintf(stderr, "*** Expected 2 parameters\n");
		exit(1);
	}

	const char *const filename_sg1= argv[1];

	struct sgraph1_reader_a r;

	if (0 > sgraph1_open_read_a(filename_sg1, &r, 2)) {
		exit(1); 
	}

	if (0 > sgraph1_advise_a(&r, MADV_SEQUENTIAL)) {
		perror(filename_sg1); 
		exit(1);
	}

	uintmax_t t= 0;

	const ma_ft len_m= 2 * r.h->m - r.loops;
	assert(len_m == r.len_m); 
	const ua_ft n= (ua_ft)r.h->n1;
	r_to= r.to;

	for (ua_ft u= 0;  u < n;  ++u) {

		const ma_ft beg1_u= read_ma(r.adj_to, u);
		const ma_ft end1= (u + 1 == n ? len_m : read_ma(r.adj_to, u+1));

		for (ma_ft i= beg1_u;  i < end1;  ++i) {

			const va_ft v= read_va(r.to, i);

			if (v >= u)
				break;

			ma_ft beg1= beg1_u;
			ma_ft beg2= read_ma(r.adj_to, v);
			const ma_ft end2= (v + 1 == n) ? len_m : read_ma(r.adj_to, v+1);
			
			assert(beg1 <= end1);
			assert(beg2 <= end2); 
			assert(beg1 >= end2 || beg2 >= end1); 

#if VARIANT == 0
			while (beg1 < end1 && beg2 < end2) {

				/* This network is without multiple edges */ 
				assert(beg1 + 1 == end1 || read_u(r.to, beg1) < read_u(r.to, beg1 + 1));
				assert(beg2 + 1 == end2 || read_u(r.to, beg2) < read_u(r.to, beg2 + 1));
					    
				const ua_ft x1= read_u(r.to, beg1);
				const ua_ft x2= read_u(r.to, beg2);

				assert(SIZE_MAX - 1 >= t); 
				t += (x1 == x2);

				if (x1 <= x2)  ++beg1;
				if (x2 <= x1)  ++beg2; 
			}
#elif VARIANT == 1

			ma_ft t_uv= common_elements(beg1, end1, beg2, end2); 

			assert(SIZE_MAX - t_uv >= t); 
			t += t_uv;
#endif
		}
	}

	assert(t % 3 == 0); 
	t /= 3;

	if (0 > printf("%" PRIuMAX "\n", t)) {
		perror("printf");
		exit(1); 
	}

	exit(0);
}
Example #3
0
int main(int argc, char **argv)
{
    if (argc != 3) {
        fprintf(stderr, "*** Invalid number of parameters\n");
        exit(1);
    }

    const char *const filename_sg1= argv[1];
    const char *const filename_ft= argv[2];

    struct sgraph1_reader_a r;

    if (0 > sgraph1_open_read_a(filename_sg1, &r, 2)) {
        exit(1);
    }

    if (0 > sgraph1_advise_a(&r, MADV_SEQUENTIAL)) {
        perror(filename_sg1);
        exit(1);
    }

    struct feature_a f;

    if (0 > feature_open_write_a(filename_ft, &f, r.h->n1
#if FEATURE_N2
                                 , r.h->n2
#endif
                                )) {
        exit(1);
    }

    if (0 > feature_advise_a(&f, MADV_SEQUENTIAL)) {
        perror(filename_ft);
        exit(1);
    }

    for (ua_ft u= 0;  u < r.h->n1;  ++u) {
        const ma_ft beg= read_ma(r.adj_to, u);
        const ma_ft end= u == r.h->n1 - 1 ? r.len_m : read_ma(r.adj_to, u + 1);
        assert(beg <= end);
        assert((ma_ft)(end - beg) < fa_max);
        writeonzero_fa(f.f1, u, end - beg);
    }

#if FEATURE_N2
    for (u_ft v= 0;  v < r.h->n2;  ++v) {
        const m_ft beg= read_m(r.adj_from, v);
        const m_ft end= v == r.h->n2 - 1 ? r.len_m : read_m(r.adj_from, v + 1);
        assert(end - beg < f_max);
        writeonzero_f(f.f2, v, end - beg);
    }
#endif

    if (0 > feature_close_write_a(&f)) {
        perror(filename_ft);
        if (0 > unlink(filename_ft)) {
            perror(filename_ft);
        }
        exit(1);
    }

    exit(0);
}