示例#1
0
文件: text.c 项目: mycoboco/beluga
/*
 *  finds the first occurrence of a text in a text
 *
 *  Considering characters that signed char cannot represent and implementations where "plain" char
 *  is signed, casts to unsigned char * are added.
 */
int (text_find)(text_t s, int i, int j, text_t str)
{
    assert(str.len >= 0 && str.str);    /* validity check for texts */
    assert(s.len >= 0 && s.str);

    i = IDX(i, s.len);
    j = IDX(j, s.len);

    if (i > j)
        SWAP(i, j);

    assert(i >= 0 && j <= s.len);    /* validity check for position; see text_pos() */

    if (str.len == 0)    /* finding empty text always succeeds */
        return i + 1;
    else if (str.len == 1) {    /* finding-character case */
        for (; i < j; i++)    /* note that < is used */
            if (((unsigned char *)s.str)[i] == *(unsigned char *)str.str)
                return i + 1;
    } else
        for (; i + str.len <= j; i++)    /* note that <= is used and str.len added */
            if (EQUAL(s, i, str))
                return i + 1;

    return 0;
}
示例#2
0
文件: text.c 项目: mycoboco/beluga
/*
 *  finds the last occurrence of a text in a text
 *
 *  Considering characters that signed char cannot represent and implementations where "plain" char
 *  is signed, casts to unsigned char * are added.
 */
int (text_rfind)(text_t s, int i, int j, text_t str)
{
    assert(str.len >= 0 && str.str);    /* validity check for text */
    assert(s.len >= 0 && s.str);

    i = IDX(i, s.len);
    j = IDX(j, s.len);

    if (i > j)
        SWAP(i, j);

    assert(i >= 0 && j <= s.len);    /* validity check for position; see text_pos() */

    if (str.len == 0)    /* finding empty text always succeeds */
        return j + 1;
    else if (str.len == 1) {    /* finding-character case */
        while (j > i)    /* note that > and prefix -- are used */
            if (((unsigned char *)s.str)[--j] == *(unsigned char *)str.str)
                return j + 1;
    } else
        for (; j - str.len >= i; j--)    /* note that >= is used and str.len subtracted */
            if (EQUAL(s, j - str.len, str))
                return j - str.len + 1;

    return 0;
}
示例#3
0
void
// qleftright(const int idim, const hydroparam_t H, hydrovarwork_t * Hvw)
qleftright(const int idim,
           const int Hnx,
           const int Hny,
           const int Hnxyt,
           const int Hnvar,
           const int slices, const int Hstep,
	   double *qxm,
	   double *qxp, double *qleft, double *qright) {
           //double qxm[Hnvar][Hstep][Hnxyt],
           //double qxp[Hnvar][Hstep][Hnxyt], double qleft[Hnvar][Hstep][Hnxyt], double qright[Hnvar][Hstep][Hnxyt]) {
  // #define IHVW(i,v) ((i) + (v) * Hnxyt)
  int nvar, i, s;
  int bmax;
  WHERE("qleftright");
  if (idim == 1) {
    bmax = Hnx + 1;
  } else {
    bmax = Hny + 1;
  }

#pragma acc parallel pcopyin(qxm[0:Hnvar*Hstep*Hnxyt], qxp[0:Hnvar*Hstep*Hnxyt]) pcopyout(qleft[0:Hnvar*Hstep*Hnxyt], qright[0:Hnvar*Hstep*Hnxyt]) 
#pragma acc loop gang collapse(2)
  for (nvar = 0; nvar < Hnvar; nvar++) {
    for (s = 0; s < slices; s++) {
#pragma acc loop vector
      for (i = 0; i < bmax; i++) {
        qleft[IDX(nvar,s,i)] = qxm[IDX(nvar,s,i + 1)];
        qright[IDX(nvar,s,i)] = qxp[IDX(nvar,s,i + 2)];
      }
    }
  }
}
示例#4
0
size_t
strspn(const char *s, const char *charset)
{
	/*
	 * NB: idx and bit are temporaries whose use causes gcc 3.4.2 to
	 * generate better code.  Without them, gcc gets a little confused.
	 */
	const char *s1;
	u_long bit;
	u_long tbl[(UCHAR_MAX + 1) / LONG_BIT];
	int idx;

	if(*s == '\0')
		return (0);

#if LONG_BIT == 64	/* always better to unroll on 64-bit architectures */
	tbl[3] = tbl[2] = tbl[1] = tbl[0] = 0;
#else
	for (idx = 0; idx < sizeof(tbl) / sizeof(tbl[0]); idx++)
		tbl[idx] = 0;
#endif
	for (; *charset != '\0'; charset++) {
		idx = IDX(*charset);
		bit = BIT(*charset);
		tbl[idx] |= bit;
	}

	for(s1 = s; ; s1++) {
		idx = IDX(*s1);
		bit = BIT(*s1);
		if ((tbl[idx] & bit) == 0)
			break;
	}
	return (s1 - s);
}
示例#5
0
文件: rbc.cpp 项目: sourekj/Packages
// Chooses representatives at random from x and stores them in r.
void pickReps(matrix x, matrix *r){
  unint n = x.r;
  unint i, j;

  unint *shuf = (unint*)calloc(n, sizeof(*shuf));
  for(i=0; i<n; i++)
    shuf[i]=i;


  //generate a random permutation of 1..n
  struct timeval tv;
  gettimeofday(&tv,NULL);
  gsl_rng * rng;
  const gsl_rng_type *rngT;
  
  gsl_rng_env_setup();
  rngT = gsl_rng_default;
  rng = gsl_rng_alloc(rngT);
  gsl_rng_set(rng,tv.tv_usec);
  
  gsl_ran_shuffle(rng, shuf, n, sizeof(*shuf));
  gsl_rng_free(rng);
 
  for(i=0; i<r->r; i++){
    for(j=0; j<r->c; j++){
      r->mat[IDX( i, j, r->ld )] = x.mat[IDX( shuf[i], j, x.ld )];
    }
  }
  free(shuf);
}
示例#6
0
static inline void
write_wchars(wchar_t buf[], size_t start, size_t end, bool escape,
             bool open_field, bool close_field) {
  size_t j;
  if (escape) {
    if (open_field)
      putwchar(L'"');
    for (j = start; j <= end; ++j) {
      if (buf[IDX(j)] == L'"')
        putwchar(L'"');
      if (putwchar(buf[IDX(j)]) == WEOF) {
        fprintf(stderr, "putwchar error");
        exit(1);
      }
    }
    if (close_field)
      putwchar(L'"');
  } else {
    for (j = start; j <= end; ++j) {
      if (putwchar(buf[IDX(j)]) == WEOF) {
        fprintf(stderr, "putwchar error");
        exit(1);
      }
    }
  }
}
示例#7
0
void WSInfoDelegate::setModelData(QWidget* editor, QAbstractItemModel* model, const QModelIndex& thisindex) const
{
	WeightModel *mymodel = qobject_cast<WeightModel *>(currCombo.model);
	WSInfoModel *wsim = WSInfoModel::instance();
	QModelIndexList matches = wsim->match(wsim->index(0,0), Qt::DisplayRole, currCombo.activeText);
	int row;
	if (matches.isEmpty()) {
		// we need to add this puppy
		wsim->insertRows(wsim->rowCount(), 1);
		wsim->setData(wsim->index(wsim->rowCount() - 1, 0), currCombo.activeText);
		row = wsim->rowCount() - 1;
	} else {
		row = matches.first().row();
	}
	int grams = wsim->data(wsim->index(row, WSInfoModel::GR)).toInt();
	QVariant v = QString(currCombo.activeText);

	// don't set if it's the same as it was before setting.
	if (mymodel->data(thisindex, WeightModel::TYPE).toString() == currCombo.activeText){
		return;
	}
	mymodel->setData(IDX(WeightModel::TYPE), v, Qt::EditRole);
	mymodel->passInData(IDX(WeightModel::WEIGHT), grams);
	qDebug() << "Fixme, every weigth is 0.0 grams. see:" << grams;
}
示例#8
0
/**
 * bg_lower_ilevel - lower the index level
 */
void bg_lower_ilevel(ptst_t *ptst)
{
        unsigned long zero = sl_zero;
        node_t  *node = set->head;
        node_t  *node_next = node;

        ptst = ptst_critical_enter();

        if (node->level-2 <= sl_zero)
                return; /* no more room to lower */

        /* decrement the level of all nodes */

        while (node) {
                node_next = node->succs[IDX(0,zero)];
                if (!node->marker) {
                        if (node->level > 0) {
                                if (1 == node->level && node->raise_or_remove)
                                        node->raise_or_remove = 0;
                                //BARRIER();
                                /* null out the ptr for level being removed */
                                node->succs[IDX(0,zero)] = NULL;
                                --node->level;
                        }
                }
                node = node_next;
        }

        /* remove the lowest index level */
        BARRIER(); /* do all of the above first */
        ++sl_zero;

        ptst_critical_exit(ptst);
}
示例#9
0
void TankInfoDelegate::setModelData(QWidget* editor, QAbstractItemModel* model, const QModelIndex& thisindex) const
{
	CylindersModel *mymodel = qobject_cast<CylindersModel *>(currCombo.model);
	TankInfoModel *tanks = TankInfoModel::instance();
	QModelIndexList matches = tanks->match(tanks->index(0,0), Qt::DisplayRole, currCombo.activeText);
	int row;
	if (matches.isEmpty()) {
		// we need to add this
		tanks->insertRows(tanks->rowCount(), 1);
		tanks->setData(tanks->index(tanks->rowCount() -1, 0), currCombo.activeText);
		row = tanks->rowCount() - 1;
	} else {
		row = matches.first().row();
	}
	int tankSize = tanks->data(tanks->index(row, TankInfoModel::ML)).toInt();
	int tankPressure = tanks->data(tanks->index(row, TankInfoModel::BAR)).toInt();

	// don't f**k the other data, jimmy.
	if ( mymodel->data(thisindex, CylindersModel::TYPE).toString() == currCombo.activeText){
		return;
	}

	mymodel->setData(IDX(CylindersModel::TYPE), currCombo.activeText, Qt::EditRole);
	mymodel->passInData(IDX(CylindersModel::WORKINGPRESS), tankPressure);
	mymodel->passInData(IDX(CylindersModel::SIZE), tankSize);
}
示例#10
0
void
equation_of_state(int imin,
                  int imax,
                  const int Hnxyt,
                  const int Hnvar,
                  const double Hsmallc,
                  const double Hgamma,
                  const int slices, const int Hstep,
                  double *eint, double *q, double *c) {
  //double eint[Hstep][Hnxyt], double q[Hnvar][Hstep][Hnxyt], double c[Hstep][Hnxyt]) {
  int k, s;
  double smallp;

  WHERE("equation_of_state");
  smallp = Square(Hsmallc) / Hgamma;
  CFLOPS(1);

#pragma acc parallel pcopyin(eint[0:Hstep*Hnxyt]) pcopy(q[0:Hnvar*Hstep*Hnxyt]) pcopyout(c[0:Hstep*Hnxyt])
#pragma acc loop gang
  for (s = 0; s < slices; s++) {
#pragma acc loop vector
    for (k = imin; k < imax; k++) {
      double rhok = q[IDX(ID,s,k)];
      double base = (Hgamma - one) * rhok * eint[IDXE(s,k)];
      base = MAX(base, (double) (rhok * smallp));

      q[IDX(IP,s,k)] = base;
      c[IDXE(s,k)] = sqrt(Hgamma * base / rhok);

      CFLOPS(7);
    }
  }
}                               // equation_of_state
示例#11
0
文件: p109.cpp 项目: alxsoares/OI
int main()
{
	freopen("t.in", "r", stdin);
	freopen("t.out", "w", stdout);
	int n;
	scanf("%d", &n);
	printf("%d", n);
	for(int i = 0; i < n; i ++)
		for(int j = 0; j < n; j ++)
			if(i + j > n)
				printf(" %d", IDX(i,j));
	printf("\n");
	printf("%d", nextOdd());
	for(int i = 0; i < n; i ++)
		for(int j = 0; j < n; j ++)
			if(i + j == n)
				printf(" %d", IDX(i,j));
	printf("\n");
	for(int i = n; i >= 2; i --)
	{
		printf("%d", nextOdd());
		for(int j = 0; j < i; j ++)
			printf(" %d", IDX(j, i - j - 1));
		printf("\n");
	}
}
示例#12
0
文件: text.c 项目: mycoboco/beluga
/*
 *  checks if a text ends with another text
 *
 *  Considering characters that signed char cannot represent and implementations where "plain" char
 *  is signed, casts to unsigned char * are added.
 */
int (text_rmatch)(text_t s, int i, int j, text_t str)
{
    assert(str.len >= 0 && str.str);    /* validity check for texts */
    assert(s.len >= 0 && s.str);

    i = IDX(i, s.len);
    j = IDX(j, s.len);

    if (i > j)
        SWAP(i, j);

    assert(i >= 0 && j <= s.len);    /* validity check for position; see text_pos() */

    if (str.len == 0)    /* finding empty text always succeeds */
        return j + 1;
    else if (str.len == 1) {    /* finding-character case */
        if (j > i &&    /* note that > is used */
            ((unsigned char *)s.str)[j-1] == *(unsigned char *)str.str)
            return j;
    } else if (j - str.len >= i && EQUAL(s, j - str.len, str))    /* note that >= is used and
                                                                     str.len subtracted */
        return j - str.len + 1;

    return 0;
}
void WSInfoDelegate::revertModelData(QWidget* widget, QAbstractItemDelegate::EndEditHint hint)
{
	if (hint == QAbstractItemDelegate::NoHint || hint == QAbstractItemDelegate::RevertModelCache){
		WeightModel *mymodel = qobject_cast<WeightModel *>(currCombo.model);
		mymodel->setData(IDX(WeightModel::TYPE), currWeight.type, Qt::EditRole);
		mymodel->passInData(IDX(WeightModel::WEIGHT), currWeight.weight);
	}
}
static UINT32 i80286_selector_address(i80286_state *cpustate,UINT16 sel)
{
	UINT32 base;
	UINT16 limit;
	if(TBL(sel)) { base = cpustate->ldtr.base; limit = cpustate->ldtr.limit; }
	else { base = cpustate->gdtr.base; limit = cpustate->gdtr.limit; }
	return ((IDX(sel)>=limit)||!IDXTBL(sel)?-1:base+IDX(sel));
}
示例#15
0
static int _op_handler(double *lu, int i, double h2, hpx_addr_t u, hpx_addr_t f) {
  double left, right, lf;

  hpx_gas_memget_sync(&left, IDX(u,i-1), sizeof(left));
  hpx_gas_memget_sync(&right, IDX(u,i+1), sizeof(right));
  hpx_gas_memget_sync(&lf, IDX(f,i), sizeof(lf));
  *lu = left + right + h2*lf/2;
  return HPX_SUCCESS;
}
示例#16
0
void
// qleftright(const int idim, const hydroparam_t H, hydrovarwork_t * Hvw)
qleftright (const int idim,
            const int Hnx,
            const int Hny,
            const int Hnxyt,
            const int Hnvar,
            const int slices, const int Hstep,
            hydro_real_t *qxm, hydro_real_t *qxp, hydro_real_t *qleft, hydro_real_t *qright)
{
    //double qxm[Hnvar][Hstep][Hnxyt],
    //double qxp[Hnvar][Hstep][Hnxyt], double qleft[Hnvar][Hstep][Hnxyt], double qright[Hnvar][Hstep][Hnxyt]) {
    // #define IHVW(i,v) ((i) + (v) * Hnxyt)
    //int nvar, i, s;
    int bmax;
    WHERE ("qleftright");
    if (idim == 1)
    {
        bmax = Hnx + 1;
    }
    else
    {
        bmax = Hny + 1;
    }

#pragma acc kernels present(qxm[0:Hnvar*Hstep*Hnxyt], qxp[0:Hnvar*Hstep*Hnxyt]) present(qleft[0:Hnvar*Hstep*Hnxyt], qright[0:Hnvar*Hstep*Hnxyt])
    {

#ifdef GRIDIFY
#ifndef GRIDIFY_TUNE_PHI
#pragma hmppcg gridify(nvar*s,i)
#else
#pragma hmppcg gridify(nvar*s,i), blocksize 512x1
#endif
#endif /* GRIDIFY */
#ifndef GRIDIFY
#pragma acc loop independent
#endif /* !GRIDIFY */
        for (int nvar = 0; nvar < Hnvar; nvar++)
        {
#ifndef GRIDIFY
#pragma acc loop independent
#endif /* !GRIDIFY */
            for (int s = 0; s < slices; s++)
            {
#ifndef GRIDIFY
#pragma acc loop independent
#endif /* !GRIDIFY */
                for (int i = 0; i < bmax; i++)
                {
                    qleft[IDX (nvar, s, i)] = qxm[IDX (nvar, s, i + 1)];
                    qright[IDX (nvar, s, i)] = qxp[IDX (nvar, s, i + 2)];
                }
            }
        }
    }//kernels region
}
示例#17
0
int assert_matrix_equality(double *A, double *B, int n){
    int i, j;
    double epsilon = 0.0001;
    for (i = 0; i < n; i++)
        for (j = 0; j < n; j++)
            if (fabs(A[IDX(i, j, n)] - B[IDX(i, j, n)]) > epsilon)
                return 1;
    return 0;
}
void TankInfoDelegate::revertModelData(QWidget* widget, QAbstractItemDelegate::EndEditHint hint)
{
	if (hint == QAbstractItemDelegate::NoHint || hint == QAbstractItemDelegate::RevertModelCache){
		CylindersModel *mymodel = qobject_cast<CylindersModel *>(currCombo.model);
		mymodel->setData(IDX(CylindersModel::TYPE), currCylinderData.type, Qt::EditRole);
		mymodel->passInData(IDX(CylindersModel::WORKINGPRESS), currCylinderData.pressure);
		mymodel->passInData(IDX(CylindersModel::SIZE), currCylinderData.size);
	}
}
示例#19
0
const glsl_type *
glsl_type::get_instance(unsigned base_type, unsigned rows, unsigned columns)
{
   if (base_type == GLSL_TYPE_VOID)
      return void_type;

   if ((rows < 1) || (rows > 4) || (columns < 1) || (columns > 4))
      return error_type;

   /* Treat GLSL vectors as Nx1 matrices.
    */
   if (columns == 1) {
      switch (base_type) {
      case GLSL_TYPE_UINT:
	 return uint_type + (rows - 1);
      case GLSL_TYPE_INT:
	 return int_type + (rows - 1);
      case GLSL_TYPE_FLOAT:
	 return float_type + (rows - 1);
      case GLSL_TYPE_BOOL:
	 return bool_type + (rows - 1);
      default:
	 return error_type;
      }
   } else {
      if ((base_type != GLSL_TYPE_FLOAT) || (rows == 1))
	 return error_type;

      /* GLSL matrix types are named mat{COLUMNS}x{ROWS}.  Only the following
       * combinations are valid:
       *
       *   1 2 3 4
       * 1
       * 2   x x x
       * 3   x x x
       * 4   x x x
       */
#define IDX(c,r) (((c-1)*3) + (r-1))

      switch (IDX(columns, rows)) {
      case IDX(2,2): return mat2_type;
      case IDX(2,3): return mat2x3_type;
      case IDX(2,4): return mat2x4_type;
      case IDX(3,2): return mat3x2_type;
      case IDX(3,3): return mat3_type;
      case IDX(3,4): return mat3x4_type;
      case IDX(4,2): return mat4x2_type;
      case IDX(4,3): return mat4x3_type;
      case IDX(4,4): return mat4_type;
      default: return error_type;
      }
   }

   assert(!"Should not get here.");
   return error_type;
}
示例#20
0
void copyMat(matrix *x, matrix *y){
  unint i,j;
  
  x->r=y->r; x->pr=y->pr; x->c=y->c; x->pc=y->pc; x->ld=y->ld;
  for(i=0; i<y->r; i++){
    for(j=0; j<y->c; j++){
      x->mat[IDX( i, j, x->ld )] = y->mat[IDX( i, j, y->ld )];
    }
  }
}
示例#21
0
// C = A^T
Mat Mat::T() {
  // create new Mat for output, and do operation
  Mat *C = new Mat(ncols,nrows);
  for (long int j=0; j<ncols; j++)
    for (long int i=0; i<nrows; i++)
      C->data[IDX(j,i,ncols)] = data[IDX(i,j,nrows)];

  // return result
  return *C;
}
示例#22
0
int pdf_jsimp_to_type(pdf_jsimp *imp, pdf_jsimp_obj *obj)
{
	js_State *J = imp->J;
	if (js_isnull(J, IDX(obj))) return JS_TYPE_NULL;
	if (js_isboolean(J, IDX(obj))) return JS_TYPE_BOOLEAN;
	if (js_isnumber(J, IDX(obj))) return JS_TYPE_NUMBER;
	if (js_isstring(J, IDX(obj))) return JS_TYPE_STRING;
	if (js_isarray(J, IDX(obj))) return JS_TYPE_ARRAY;
	return JS_TYPE_UNKNOWN;
}
示例#23
0
文件: main.c 项目: romanz/thesis
static void transpose(real_t *A, uint_t dim)
{
    for (uint_t i = 0; i < dim; ++i) {
        for (uint_t j = 0; j < i; ++j) {
            real_t x = A[IDX(i, j, dim)];
            A[IDX(i, j, dim)] = A[IDX(j, i, dim)];
            A[IDX(j, i, dim)] = x;
        }
    }
}
示例#24
0
//computes the distance between the kth row of x and the lth row of y
float distVec(matrix x, matrix y, unint k, unint l){
  unint i, j;
  float sum=0;
  
  for(i=0; i<x.pc; i+=VEC_LEN){
    for(j=0; j<VEC_LEN; j++)
     sum += DIST( x.mat[IDX(k,i+j,x.ld)], y.mat[IDX(l,i+j,x.ld)] );
  }
  return DIST_EXP(sum);

}
示例#25
0
文件: punch.c 项目: arkamar/wdtools
void
set(const int day, const struct interval * interval, const int label) {
	int i, tmp;
	if ((interval->stop - interval->start) < 0)
		return;
	tmp = interval->start;
	for (i = interval->start / bin; i < interval->stop / bin; i++) {
		data[IDX(day, i, label)] += (i + 1) * bin - tmp;
		tmp = (i + 1) * bin;
	}
	data[IDX(day, interval->stop / bin, label)] += interval->stop - tmp;
}
示例#26
0
static void
ComputeQEforRow (const int j,
		 const hydro_real_t Hsmallr,
		 const int Hnx,
		 const int Hnxt,
		 const int Hnyt,
		 const int Hnxyt,
		 const int Hnvar,
		 const int slices, const int Hstep, hydro_real_t *uold,
		 hydro_real_t *q, hydro_real_t *e)
{
  int i, s;
  //  double eken;

#define IHV(i, j, v)  ((i) + Hnxt * ((j) + Hnyt * (v)))
#define IDX(i,j,k)    ( (i*Hstep*Hnxyt) + (j*Hnxyt) + k )
#define IDXE(i,j)     ( (i*Hnxyt) + j )
#pragma acc kernels present(q[0:Hnvar*Hstep*Hnxyt], uold[0:Hnvar*Hnxt*Hnyt],e[0:Hstep*Hnxyt])
  {
#ifdef GRIDIFY
#ifndef GRIDIFY_TUNE_PHI
#pragma hmppcg gridify(s,i)
#else
#pragma hmppcg gridify(s,i), blocksize 256x2
#endif
#endif /* GRIDIFY */
#ifndef GRIDIFY
#pragma acc loop independent
#endif /* !GRIDIFY */
  for (s = 0; s < slices; s++)
    {
#ifndef GRIDIFY
#pragma acc loop independent
#endif /* !GRIDIFY */
      for (i = 0; i < Hnx; i++)
	{
hydro_real_t eken;
	  int idxuID = IHV (i + ExtraLayer, j + s, ID);
	  int idxuIU = IHV (i + ExtraLayer, j + s, IU);
	  int idxuIV = IHV (i + ExtraLayer, j + s, IV);
	  int idxuIP = IHV (i + ExtraLayer, j + s, IP);
	  q[IDX(ID,s,i)] = MAX (uold[idxuID], Hsmallr);
	  q[IDX(IU,s,i)] = uold[idxuIU] / q[IDX(ID,s,i)];
	  q[IDX(IV,s,i)] = uold[idxuIV] / q[IDX(ID,s,i)];
	  eken = half * (Square (q[IDX(IU,s,i)]) + Square (q[IDX(IV,s,i)]));
	  q[IDX(IP,s,i)] = uold[idxuIP] / q[IDX(ID,s,i)] - eken;
	  e[IDXE(s,i)] = q[IDX(IP,s,i)];
	}
    }
  }
#undef IHV
#undef IHVW
}
示例#27
0
void pushdown(int l,int r)
{
	int rt=IDX(l,r),mid=l+r>>1;
	int rtl=IDX(l,mid),rtr=IDX(mid+1,r);
	if(lzy[rt])
	{
		lzy[rtl]+=lzy[rt];
		tree[rtl]+=lzy[rt]*(mid-l+1);
		lzy[rtr]+=lzy[rt];
		tree[rtr]+=lzy[rt]*(r-mid);
		lzy[rt]=0;
	}
}
示例#28
0
void DiamondSquare::smoothHeightField()
/*
* Smoothes the Vector, by averaging
*/
{
	std::vector<float> tempHeightField(inputResolution*inputResolution);

	for (int x = 0; x < inputResolution; x++)
	{
		for (int y = 0; y < inputResolution; y++)
		{
			float sum = 0.0f;
			int count = 0;

			for (int i = -smoothRange; i <= smoothRange; i++)
			{
				int tmp = x + i;

				if (tmp >= 0 && tmp < inputResolution)
				{
					sum += field[IDX(tmp, y, inputResolution)];
					count++;
				}
			}

			tempHeightField[IDX(x, y, inputResolution)] = sum / count;
		}
	}

	for (int x = 0; x < inputResolution; x++)
	{
		for (int y = 0; y < inputResolution; y++)
		{
			float sum = 0.0f;
			int count = 0;

			for (int j = -smoothRange; j <= smoothRange; j++)
			{
				int tmp = y + j;

				if (tmp >= 0 && tmp < inputResolution)
				{
					sum += tempHeightField[IDX(x, tmp, inputResolution)];
					count++;
				}
			}

			field[IDX(x, y, inputResolution)] = sum / count;
		}
	}
}
示例#29
0
void GameScene::updatePlayerInfo()
{
	for(int i=0; i<4; i++)
	{
		char szAmount[128];
		sprintf(szAmount, "$ %d", player_info[i].getMoney());
		pLabelPlayerMoney[i]->setString(szAmount);

		char szName[128];
		if(player_info[i].getPlayerName().length() > 0)
		{
			sprintf(szName, "Player%02d", i);
			pLabelPlayerName[i]->setString(szName);
			pLabelPlayerName[i]->setColor(ccc3(255, 255, 255));
		}
		else
		{
			pLabelPlayerName[i]->setString("WAITING");
			pLabelPlayerName[i]->setColor(ccc3(80, 80, 80));
		}

		char szOption[128];
		if(player_info[i].getLastOption() == TYPE_CALL)
		{
			sprintf(szOption, "CALL (%d$)", player_info[i].getMoney());
		}
		else if(player_info[i].getLastOption() == TYPE_DOUBLE)
		{
			sprintf(szOption, "DOUBLE (%d$)", player_info[i].getMoney());
		}
		else if(player_info[i].getLastOption() == TYPE_CHECK)
		{
			sprintf(szOption, "CHECK (%d$)", player_info[i].getMoney());
		}
		else if(player_info[i].getLastOption() == TYPE_DIE)
		{
			pLabelPlayerName[i]->setString("(DIE)");
			pLabelPlayerName[i]->setColor(ccc3(80, 80, 80));

			sprintf(szOption, "DIE (0$)");
		}
		else if(player_info[i].getLastOption() == -1)
		{
			sprintf(szOption, "waiting...", player_info[i].getMoney());
		}
		pLabelPlayerStatus[i]->setString(szOption);
	}

	pLabelPlayerName[IDX(0)]->setString(player_info[IDX(0)].getPlayerName().c_str());
}
示例#30
0
int chol(double *A, int n){

    unsigned int i;
    unsigned int j;
    unsigned int k;

    for (j = 0; j < n; j++) {
        for (i = j; i < n; i++) {
            for (k = 0; k < j; ++k) {
                A[IDX(i, j, n)] -= A[IDX(i, k, n)] *
                                   A[IDX(j, k, n)];
            }
        }

        if (A[IDX(j, j, n)] < 0.0) {
            return (1);
        }

        A[IDX(j, j, n)] = sqrt(A[IDX(j, j, n)]);
        for (i = j + 1; i < n; i++)
            A[IDX(i, j, n)] /= A[IDX(j, j, n)];
    }

    return (0);
}