Example #1
0
/*
* generate a particular table
*/
void
gen_tbl (int tnum, DSS_HUGE start, DSS_HUGE count, long upd_num)
{
	static order_t o;
	supplier_t supp;
	customer_t cust;
	part_t part;
	code_t code;
	static int completed = 0;
	DSS_HUGE i;

	DSS_HUGE rows_per_segment=0;
	DSS_HUGE rows_this_segment=-1;
	DSS_HUGE residual_rows=0;

	if (insert_segments)
		{
		rows_per_segment = count / insert_segments;
		residual_rows = count - (rows_per_segment * insert_segments);
		}

	for (i = start; count; count--, i++)
	{
		LIFENOISE (1000, i);
		row_start(tnum);

		switch (tnum)
		{
		case LINE:
		case ORDER:
  		case ORDER_LINE: 
			mk_order (i, &o, upd_num % 10000);

		  if (insert_segments  && (upd_num > 0))
			if((upd_num / 10000) < residual_rows)
				{
				if((++rows_this_segment) > rows_per_segment) 
					{						
					rows_this_segment=0;
					upd_num += 10000;					
					}
				}
			else
				{
				if((++rows_this_segment) >= rows_per_segment) 
					{
					rows_this_segment=0;
					upd_num += 10000;
					}
				}

			if (set_seeds == 0)
				tdefs[tnum].loader(&o, upd_num);
			break;
		case SUPP:
			mk_supp (i, &supp);
			if (set_seeds == 0)
				tdefs[tnum].loader(&supp, upd_num);
			break;
		case CUST:
			mk_cust (i, &cust);
			if (set_seeds == 0)
				tdefs[tnum].loader(&cust, upd_num);
			break;
		case PSUPP:
		case PART:
  		case PART_PSUPP: 
			mk_part (i, &part);
			if (set_seeds == 0)
				tdefs[tnum].loader(&part, upd_num);
			break;
		case NATION:
			mk_nation (i, &code);
			if (set_seeds == 0)
				tdefs[tnum].loader(&code, 0);
			break;
		case REGION:
			mk_region (i, &code);
			if (set_seeds == 0)
				tdefs[tnum].loader(&code, 0);
			break;
		}
		row_stop(tnum);
		if (set_seeds && (i % tdefs[tnum].base) < 2)
		{
			printf("\nSeeds for %s at rowcount %ld\n", tdefs[tnum].comment, i);
			dump_seeds(tnum);
		}
	}
	completed |= 1 << tnum;
}
Example #2
0
File: driver.c Project: YIwama/bcb
/*
* generate a particular table
*/
void
gen_tbl (int tnum, long start, long count, long upd_num)
{
	static order_t o;
	supplier_t supp;
	customer_t cust;
	part_t part;
#ifdef SSBM
	date_t dt;
#else
	code_t code;
#endif
	static int completed = 0;
	static int init = 0;
	long i;

	int rows_per_segment=0;
	int rows_this_segment=-1;
	int residual_rows=0;

	if (insert_segments)
		{
		rows_per_segment = count / insert_segments;
		residual_rows = count - (rows_per_segment * insert_segments);
		}

	if (init == 0)
	{
		INIT_HUGE(o.okey);
		for (i=0; i < O_LCNT_MAX; i++)
#ifdef SSBM
			INIT_HUGE(o.lineorders[i].okey);	
#else
			INIT_HUGE(o.l[i].okey);
#endif
		init = 1;
	}

	for (i = start; count; count--, i++)
	{
		LIFENOISE (1000, i);
		row_start(tnum);

		switch (tnum)
		{
		case LINE:
#ifdef SSBM
#else
		case ORDER:
  		case ORDER_LINE: 
#endif
			mk_order (i, &o, upd_num % 10000);

		  if (insert_segments  && (upd_num > 0))
			if((upd_num / 10000) < residual_rows)
				{
				if((++rows_this_segment) > rows_per_segment) 
					{						
					rows_this_segment=0;
					upd_num += 10000;					
					}
				}
			else
				{
				if((++rows_this_segment) >= rows_per_segment) 
					{
					rows_this_segment=0;
					upd_num += 10000;
					}
				}

			if (set_seeds == 0)
				if (validate)
					tdefs[tnum].verify(&o, 0);
				else
					tdefs[tnum].loader[direct] (&o, upd_num);
			break;
		case SUPP:
			mk_supp (i, &supp);
			if (set_seeds == 0)
				if (validate)
					tdefs[tnum].verify(&supp, 0);
				else
					tdefs[tnum].loader[direct] (&supp, upd_num);
			break;
		case CUST:
			mk_cust (i, &cust);
			if (set_seeds == 0)
				if (validate)
					tdefs[tnum].verify(&cust, 0);
				else
					tdefs[tnum].loader[direct] (&cust, upd_num);
			break;
#ifdef SSBM
		case PART:
#else
		case PSUPP:
		case PART:
  		case PART_PSUPP:
#endif 
			mk_part (i, &part);
			if (set_seeds == 0)
				if (validate)
					tdefs[tnum].verify(&part, 0);
				else
					tdefs[tnum].loader[direct] (&part, upd_num);
			break;
#ifdef SSBM
		case DATE:
			mk_date (i, &dt);
			if (set_seeds == 0)
				if (validate)
					tdefs[tnum].verify(&dt, 0);
				else
					tdefs[tnum].loader[direct] (&dt, 0);
			break;
#else
		case NATION:
			mk_nation (i, &code);
			if (set_seeds == 0)
				if (validate)
					tdefs[tnum].verify(&code, 0);
				else
					tdefs[tnum].loader[direct] (&code, 0);
			break;
		case REGION:
			mk_region (i, &code);
			if (set_seeds == 0)
				if (validate)
					tdefs[tnum].verify(&code, 0);
				else
					tdefs[tnum].loader[direct] (&code, 0);
			break;
#endif
		}
		row_stop(tnum);
		if (set_seeds && (i % tdefs[tnum].base) < 2)
		{
			printf("\nSeeds for %s at rowcount %ld\n", tdefs[tnum].comment, i);
			dump_seeds(tnum);
		}
	}
	completed |= 1 << tnum;
}
Example #3
0
  const Sparse<T> sparse_binop(const Sparse<T> &m1, const Sparse<T> &m2,
                               binop op)
  {
    size_t rows = m1.rows();
    size_t cols = m1.columns();

    assert(rows == m2.rows() && cols == m2.columns());

    if (rows == 0 || cols == 0)
      return m1;

    index max_size = m1.priv_data().size() + m2.priv_data().size();
    Vector<T> data(max_size);
    Indices column(max_size);
    Indices row_start(rows + 1);

    typename Vector<T>::iterator out_data = data.begin();
    typename Indices::iterator out_column = column.begin();
    typename Indices::iterator out_row_start = row_start.begin();
    typename Vector<T>::iterator out_begin = out_data;

    typename Vector<T>::const_iterator m1_data = m1.priv_data().begin();
    typename Indices::const_iterator m1_row_start = m1.priv_row_start().begin();
    typename Indices::const_iterator m1_column = m1.priv_column().begin();

    typename Vector<T>::const_iterator m2_data = m2.priv_data().begin();
    typename Indices::const_iterator m2_row_start = m2.priv_row_start().begin();
    typename Indices::const_iterator m2_column = m2.priv_column().begin();

    index j1 = *(m1_row_start++);    // data start for this row in M1
    index l1 = (*m1_row_start) - j1; // # elements in this row in M1
    index j2 = *(m2_row_start++);    // data start for this row in M2
    index l2 = (*m2_row_start) - j2; // # elements in this row in M2
    *out_row_start = 0;
    while (1) {
      // We look for the next unprocessed matrix element on this row,
      // for both matrices. c1 and c2 are the columns associated to
      // each element on each matrix.
      index c1 = l1 ? *m1_column : cols;
      index c2 = l2 ? *m2_column : cols;
      T value;
      index c;
      if (c1 < c2) {
        // There is an element a column c1 on matrix m1, but the
        // same element at m2 is zero
        value = op(*m1_data, number_zero<T>());
        c = c1;
        l1--; m1_column++; m1_data++;
      } else if (c2 < c1) {
        // There is an element a column c2 on matrix m2, but the
        // same element at m1 is zero
        value = op(number_zero<T>(), *m2_data);
        c = c2;
        l2--; m2_column++; m2_data++;
      } else if (c2 < cols) {
        // Both elements in m1 and m2 are nonzero.
        value = op(*m1_data, *m2_data);
        c = c1;
        l1--; l2--;
        m1_column++; m1_data++;
        m2_column++; m2_data++;
      } else {
        // We have processed all elements in this row.
        out_row_start++;
        *out_row_start = out_data - out_begin;
        if (--rows == 0) {
          break;
        }
        j1 = *m1_row_start; m1_row_start++; l1 = (*m1_row_start) - j1;
        j2 = *m2_row_start; m2_row_start++; l2 = (*m2_row_start) - j2;
        continue;
      }
      if (!(value == number_zero<T>())) {
        *(out_data++) = value;
        *(out_column++) = c;
      }
    }
    index j = out_data - out_begin;
    Indices the_column(j);
    std::copy(column.begin(), column.begin() + j, the_column.begin());
    Vector<T> the_data(j);
    std::copy(data.begin(), data.begin() + j, the_data.begin());
    return Sparse<T>(m1.dimensions(), row_start, the_column, the_data);
  }