本文整理汇总了C++中IDX函数的典型用法代码示例。如果您正苦于以下问题:C++ IDX函数的具体用法?C++ IDX怎么用?C++ IDX使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了IDX函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: int
/*
* 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: qleftright
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)];
}
}
}
}
示例3: strspn
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);
}
示例4: pickReps
// 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);
}
示例5: write_wchars
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);
}
}
}
}
示例6: QString
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;
}
示例7: bg_lower_ilevel
/**
* 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);
}
示例8: setModelData
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 fuck 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);
}
示例9: equation_of_state
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
示例10: main
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");
}
}
示例11: revertModelData
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);
}
}
示例12: i80286_selector_address
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));
}
示例13: _op_handler
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;
}
示例14: qleftright
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
}
示例15: assert_matrix_equality
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;
}