void mergesort(int s[], int n) {
    if(n <= 1)
        return;
    const int left = n / 2, right = n - n / 2;
    int l[left], r[right], i;
    for(i = 0; i < left; i++)
        l[i] = s[i];
    for(i = left; i < n; i++)
        r[i - left] = s[i];
    mergesort(l, left);
    mergesort(r, right);
    merge_(l, left, r, right, s);
}
Пример #2
0
void 
merge(int* input_array_low, int* input_array_high, int* local_array_low,
      int* local_array_high, int* temp_array_low) 
{
  if(((input_array_high - input_array_low) + 
      (local_array_high - local_array_low)) <= MAX_SIZE_LIMIT_OF_MERGE ) 
  {
    merge_( input_array_low, input_array_high, local_array_low, 
            local_array_high, temp_array_low  );
  } 
  else 
  {
    int *input_array_mid, *local_array_mid;
    if( (input_array_high - input_array_low) < 
        (local_array_high - local_array_low) ) 
    {
      local_array_mid = local_array_low + 
                        (local_array_high - local_array_low) / 2;
      input_array_mid = upper_bound(input_array_low, input_array_high,
                                    *local_array_mid);
    } 
    else 
    {
      input_array_mid = input_array_low + 
                        (input_array_high - input_array_low) / 2;
      local_array_mid = lower_bound(local_array_low, local_array_high,
                                    *input_array_mid);
    }
    int* temp_array_mid = temp_array_low + 
                          (input_array_mid - input_array_low) + 
                          (local_array_mid - local_array_low);
#pragma omp task
    merge(input_array_low, input_array_mid, local_array_low, 
          local_array_mid, temp_array_low);
    merge(input_array_mid, input_array_high, local_array_mid, 
          local_array_high, temp_array_mid);
#pragma omp taskwait  
  }
}
Пример #3
0
int main(int argc, char *argv[])
{
    int t, m, n, max;
    int a, b;
    scanf("%d", &t);
    while (t--) {
        max = 0;
        scanf("%d%d", &n, &m);
        init(n);
        while (m--) {
            scanf("%d%d", &a, &b);
            merge_(a, b);
        }
        for (i = 0; i <= n; i++) {
            ss[djs[i]]++;
            if (ss[djs[i]] > max) {
                max = ss[djs[i]];
            }
        }
        printf("%d\n", max);
    }
    return 0;
}
Пример #4
0
void merge32s(const int** src, int* dst, int len, int cn )
{
    merge_(src, dst, len, cn);
}
Пример #5
0
void merge64s(const int64** src, int64* dst, int len, int cn )
{
    merge_(src, dst, len, cn);
}
Пример #6
0
void merge8u(const uchar** src, uchar* dst, int len, int cn )
{
    merge_(src, dst, len, cn);
}
Пример #7
0
void merge16u(const ushort** src, ushort* dst, int len, int cn )
{
    merge_(src, dst, len, cn);
}
Пример #8
0
void merge64s(const int64** src, int64* dst, int len, int cn )
{
    CALL_HAL(merge64s, cv_hal_merge64s, src, dst, len, cn)
    merge_(src, dst, len, cn);
}
Пример #9
0
void merge32s(const int** src, int* dst, int len, int cn )
{
    CALL_HAL(merge32s, cv_hal_merge32s, src, dst, len, cn)
    merge_(src, dst, len, cn);
}
Пример #10
0
void merge16u(const ushort** src, ushort* dst, int len, int cn )
{
    CALL_HAL(merge16u, cv_hal_merge16u, src, dst, len, cn)
    merge_(src, dst, len, cn);
}
Пример #11
0
void merge8u(const uchar** src, uchar* dst, int len, int cn )
{
    CALL_HAL(merge8u, cv_hal_merge8u, src, dst, len, cn)
    merge_(src, dst, len, cn);
}
Пример #12
0
/*
 * Joins contig 'lnconr' to contig 'lnconl' at offset 'relx', producing a
 * new contig in place of 'lnconl'.
 * The old 'lnconr' is removed.
 *
 * Returns 0 for success, -1 for error (currently never)
 */
int dojoin(GapIO *io, int lnconl, int lnconr, int relx) {
    int gl_r = io_crnbr(io, lnconl);
    int gl_l;
    int gr_l = io_clnbr(io, lnconr);
    int i, len, right = 0;
    f_int tmp;
    GContigs c;
    reg_length rl;
    reg_join rj;

    /* Shift readings in lnconr by relx */
    io_relpos(io, gr_l) = relx+1;
    i = gr_l;
    while (i = io_rnbr(io, i)) {
	io_relpos(io, i) += relx;
    }

    /* Linkup ends of contigs (but not yet in correct left to right order) */
    io_lnbr(io, gr_l) = gl_r;
    io_rnbr(io, gl_r) = gr_l;

    /* Call MERGE() to shuffle the links to the correct order */
    tmp = io_dbsize(io) - lnconl;
    merge_(&io_relpos(io,1), &io_length(io,1), &io_lnbr(io,1), &io_rnbr(io,1),
	   &tmp, &io_dbsize(io));

    /* MERGE() doesn't save the readings, so do that ourselves */
    for (right = i = io_clnbr(io, lnconl); i; right = i, i = io_rnbr(io, i)) {
	GReadings r;

	gel_read(io, i, r);
	r.left = io_lnbr(io, i);
	r.right = io_rnbr(io, i);
	r.position = io_relpos(io, i);
	gel_write(io, i, r);
    }

    /* merge contig annotation lists and update contig length */
    merge_contig_tags(io, lnconl, lnconr, relx);

    /* merge note lists */
    merge_contig_notes(io, lnconr, lnconl);

    contig_read(io, lnconr, c);
    len = c.length + relx;

    contig_read(io, lnconl, c);
    if (c.length < len)
	c.length = len;
    c.right = right;
    contig_write(io, lnconl, c);
    io_clength(io, lnconl) = c.length;
    io_crnbr(io, lnconl) = c.right;

    /*
     * The order of notifications here is crucial.
     *
     * We need to firstly notify the right contig that it's been joined to
     * the left contig.
     *
     * Merge the contig registration lists (copy right into left).
     *
     * Then we delete the right contig. Note that this may imply that the
     * left contig number changes, so we convert to a gel number during the
     * duration of this call.
     *
     * Finally we then tell the left contig that it's length has changed.
     */

    /* Notify right of join */
    rj.job = REG_JOIN_TO;
    rj.contig = lnconl;
    rj.offset = relx;
    contig_notify(io, lnconr, (reg_data *)&rj);

    /* Merge lists */
    contig_register_join(io, lnconr, lnconl);
        
    /* Delete old contig (lnconr) */
    gl_l = io_clnbr(io, lnconl);
    io_delete_contig(io, lnconr);
    lnconl = rnumtocnum(io, gl_l);

    /* Notify left of join */
    rl.job = REG_LENGTH;
    rl.length = c.length;
    contig_notify(io, lnconl, (reg_data *)&rl);

    flush2t(io);

    return 0;
}