예제 #1
0
파일: sparselib.c 프로젝트: bremond/siconos
void dswapVector1(sparseVector *sparse, REAL *dense, int indexStart, int indexEnd)
{
  int i, d, n;
  REAL *x;

  if(indexStart <= 0)
    indexStart = 1;
  n = lastIndex(sparse);
  if(indexEnd <= 0) 
    indexEnd = n;
  CALLOC(x, (MAX(indexEnd,n)+1));

  getVector(sparse, x, indexStart, n, FALSE);
  d = getDiagonalIndex(sparse);
  clearVector(sparse, indexStart, n);
  for(i = indexStart; i<=indexEnd; i++) {
    if(dense[i] != 0)
      putItem(sparse, i, dense[i]);
  }
  for(i = indexEnd+1; i<=n; i++) {
    if(x[i] != 0)
      putItem(sparse, i, x[i]);
  }
  MEMCOPY(&dense[indexStart], &x[indexStart], (indexEnd-indexStart+1));

#ifdef DEBUG_SPARSELIB
  verifyVector(sparse);
#endif
  
  MEMFREE(x);
}
예제 #2
0
/* Pre: perm is initialized, hist[0..rank-1] is descending.
 * Create the list of permutations (as powers of 2)
 * that preserve hist[0..rank-1]  */
Arraylist specPerm(int rank, int* hist) {
	int i, j, k, m, x;
	Intstack prim = newIntstack(rank, NULL) ;
	Arraylist result = newArraylist(1) ;
	Arraylist locperm;
	prim->size = rank;
	for (i = 0, x = 1; i < rank; i++, x <<= 1) {
		prim->it[i] = x;
	}
	putItem(prim, result) ;
	i = 0;
	while (i + 1 < rank) {
		j = i+1;
		while (j < rank && hist[i] == hist[j])
			j++;
		if (i+1 < j) {
			x = result->size;
			locperm = getPerm(j-i) ;
			for (k = 0; k < locperm->size - 1; k++)
				for (m = 0; m < x; m++)
					putItem(applyPerm(i, result->it[m], locperm->it[k]), result) ;
		}
		i = j;
	}
	return result;
}
예제 #3
0
파일: ugraph.c 프로젝트: germuth/Kekule
int main(int argc, char *argv[]) {
  int i, rank;
  Arraylist r;
  assert(argc > 1);
  rank = atoi(argv[1]);
  r = allGraphs(rank);
  if (rank % 2 == 1){
    printf("Graphs: %d.\n", r->size);
    printAsGraphList(rank, r);
  } else {
    Arraylist r0, r1;
    r0 = newArraylist(5);
    r1 = newArraylist(5);
    for (i = 0 ; i < r->size ; i++) {
      if (matched(rank, r->it[i])) putItem(r->it[i], r0);
      else putItem(r->it[i], r1);
    }
    printf("Matched graphs: %d.\n", r0->size);
    printAsGraphList(rank, r0);
    printf("Unmatched graphs: %d.\n", r1->size);
    printAsGraphList(rank, r1);
    freeArraylist(r0);
    freeArraylist(r1);
  }
  freeArraylist(r);
  freePerm();
#if 0
  reportCnt();
  reportACnt();
  reportGCnt();
#endif
  return 0;
}
예제 #4
0
파일: pq.c 프로젝트: AIdrifter/DS
int pqInsert(struct pq_t *pThis, void *pKey, void *pObj){
    if(pThis->size == pThis->cap)
        return __DS__PQ__FULL__;
    if(hmKeyExist(pThis->pObjToIndex, pObj))
        return __DS__PQ__OBJ_EXIST__;

    putItem(pThis->keyArray, pThis->size, pKey, pThis->keySize);
    putItem(pThis->objArray, pThis->size, pObj, pThis->objSize);
    hmInsert(pThis->pObjToIndex, pObj, &(pThis->size));
    pThis->size++;
    return __DS__PQ__NORMAL__;
}
void ConfigStorage::addSession(TraceSession& session)
{
	setDirty();
	session.ses_id = (m_sharedMemory->getHeader()->session_number)++;
	session.ses_flags |= trs_active;
	time(&session.ses_start);

	const long pos1 = lseek(m_cfg_file, 0, SEEK_END);
	if (pos1 < 0)
	{
		const char* fn = m_sharedMemory->getHeader()->cfg_file_name;
		ERR_post(Arg::Gds(isc_io_error) << Arg::Str("lseek") << Arg::Str(fn) <<
			Arg::Gds(isc_io_read_err) << SYS_ERR(errno));
	}

	putItem(tagID, sizeof(session.ses_id), &session.ses_id);
	if (!session.ses_name.empty()) {
		putItem(tagName, session.ses_name.length(), session.ses_name.c_str());
	}
	putItem(tagUserName, session.ses_user.length(), session.ses_user.c_str());
	putItem(tagFlags, sizeof(session.ses_flags), &session.ses_flags);
	putItem(tagConfig, session.ses_config.length(), session.ses_config.c_str());
	putItem(tagStartTS, sizeof(session.ses_start), &session.ses_start);
	if (!session.ses_logfile.empty()) {
		putItem(tagLogFile, session.ses_logfile.length(), session.ses_logfile.c_str());
	}
	putItem(tagEnd, 0, NULL);

	// const long pos2 = lseek(m_cfg_file, 0, SEEK_END);
	// m_sharedMemory->getHeader()->used_space += pos2 - pos1;
}
예제 #6
0
void drawTile(struct tile *t, int x,int y){
	if(!t->saw) return;

	if(t->vis){
		if(t->ent){
			putChar(x, y, t->ent->c, t->ent->col);
		}else if (t->itm != NULL && darray_usize(t->itm) > 0){
			putItem(t, x, y);
		}else if(t->base == WALL){
			putChar(x, y, '#', CGRAY);
		}else if(t->base == FLOOR){
			putChar(x, y, '.', CGRAY);
		}else if(t->base == STAIR_UP){
			putChar(x, y, '<', CGRAY);
		}else if(t->base == STAIR_DOWN){
			putChar(x, y, '>', CGRAY);
		}else if(t->base == FOUNTAIN){
			putChar(x, y, '%', CBLUE);
		}
	}else{
		if(t->base == WALL){
			putChar(x, y, '#', CWHITE);
		}else if(t->base == FLOOR){
			putChar(x, y, '.', CWHITE);
		}else if(t->base == STAIR_UP){
			putChar(x, y, '<', CWHITE);
		}else if(t->base == STAIR_DOWN){
			putChar(x, y, '>', CWHITE);
		}else if(t->base == FOUNTAIN){
			putChar(x, y, '%', CBLUE);
		}
	}
}
예제 #7
0
void initPerm() {
	int i;
	Intstack p0, p1;
	if (permInit)
		return;
	permInit = 1;
	for (i = 0; i < RANKLIM; i++)
		perm[i] = NULL;
	perm[0] = newArraylist(1) ;
	perm[1] = newArraylist(1) ;
	p0 = newIntstack(0, NULL) ;
	putItem(p0, perm[0]) ;
	p1 = newIntstack(1, NULL) ;
	putint(0, p1) ;
	putItem(p1, perm[1]) ;
}
예제 #8
0
Arraylist getPerm(int rank) {
	int i, j, k;
	Intstack y, z;
	if (!permInit)
		initPerm() ;
	if (perm[rank] != NULL)
		return perm[rank];
	if (perm[rank-1] == NULL)
		getPerm(rank-1) ;
	perm[rank] = newArraylist(rank * perm[rank-1]->size) ;
	for (i = 0; i < perm[rank-1]->size; i++) {
		y = perm[rank-1]->it[i];
		for (j = 0; j < rank; j++) {
			z = newIntstack(rank, NULL);
			for (k = 0; k < j; k++)
				z->it[k] = y->it[k];
			z->it[j] = rank - 1;
			for (k = j; k < y->size; k++)
				z->it[k+1] = y->it[k];
			z->size = rank;
			putItem(z, perm[rank]) ;
		}
	}
	return perm[rank];
}
예제 #9
0
파일: classGraph.c 프로젝트: germuth/Kekule
Arraylist allGraphs(int rank) {
  Arraylist result = newArraylist(rank);
  Intstack cand = newIntstack(0, NULL), 
    fg = fullgraph(rank);
  unsigned long int x, y, ulim = 1 << fg->size;
  int i;
  setRank(rank);
  for (x = 0L; x < ulim; x++) {
    cand->size = 0;
    y = x;
    i = 0;
    while (y > 0) {
      if (y % 2 == 1) putint(fg->it[i], cand);
      y /= 2;
      i++;
    }
    if (portHistDescending(cand)) {
      putItem((void*) newIntstack(0, cand), result);
    } 
  }
  freestack(cand);
  freestack(fg);
  sortAndWeedForGraphs(rank, result);
  return result;
}
예제 #10
0
파일: sparselib.c 프로젝트: bremond/siconos
void fillVector(sparseVector *sparse, int count, REAL value)
{
  int i;

  if(sparse->count > 0) 
    clearVector(sparse, 0, 0);
  for(i = 1; i<=count; i++)
    putItem(sparse, i, value);
}
예제 #11
0
파일: sparselib.c 프로젝트: bremond/siconos
MYBOOL putDiagonal(sparseVector *sparse, REAL value)
{
  if(sparse->index[0]>0) {
    putItem(sparse, sparse->index[0], value); 
    return(TRUE);
  }
  else
    return(FALSE);
}
예제 #12
0
파일: sparselib.c 프로젝트: bremond/siconos
REAL addtoItem(sparseVector *sparse, int targetIndex, REAL value)
{
  int idx;

  if(targetIndex > 0) 
    idx = findIndex(targetIndex, sparse->index, sparse->count, BLAS_BASE);
  else {
    idx = -targetIndex;
    if(idx > sparse->count)
      /* Index error; ignore item */
      return(0.0);
  }

  if(idx <=0 )
    value = putItem(sparse, targetIndex, value);
  else {
    value += sparse->value[idx];
    putItem(sparse, -idx, value);
  }
  return(value);
}
예제 #13
0
Arraylist rawPermVariants(int rank, Intstack cell) {
	int i, h[RANKLIM];
	Arraylist perms;
	Arraylist result;
	portHisto(cell, h) ;
	perms = specPerm(rank, h) ;
	result = newArraylist(perms->size) ;
	for (i = 0; i < perms->size; i++) {
		putItem(permuteCell(cell, perms->it[i]), result) ;
		freestack(perms->it[i]) ;
	}
	freeArraylist(perms) ;
	return result;
}
예제 #14
0
void ColumnEditorModel::setColumns(std::vector<DatabaseColumn *> const &oColumns)
{
	clear();
	insertRows(0, oColumns.size()+1);
	std::vector<DatabaseColumn *> cols;
	for(DatabaseColumn * const col : cols)
		cols.push_back(col->duplicate());

	int i = 0;
	for(DatabaseColumn * const &col : oColumns)
	{
		putItem(i, col);
		i++;
	}
}
예제 #15
0
int main(void) {
  int i;
  int readValue;
  circularQueue_t myQueue;

  initializeQueue(&myQueue);
  for (i = 0; i < MAX_ITEMS + 1; i++) {
    putItem(&myQueue, i);
  }
  printQueue(&myQueue);

  for (i = 0; i < MAX_ITEMS/2; i++) {
    getItem(&myQueue, &readValue);
    printf("readValue = %d\n", readValue);
  }
  printQueue(&myQueue);

  return 0;
}
예제 #16
0
파일: sparselib.c 프로젝트: bremond/siconos
void putVector(sparseVector *sparse, REAL *dense, int indexStart, int indexEnd)
{
  int i,n;

  n = sparse->count;
  if(indexStart<=0)
    indexStart=sparse->index[1];
  if(indexEnd<=0)
    indexEnd=sparse->index[n];

  if(n==0 || sparse->index[n]<indexStart) {
    i = sparse->index[0];
    if(i>=indexStart && i<=indexEnd)
      sparse->value[0] = 0;
    for(i = indexStart; i<=indexEnd; i++) {
      if(dense[i] == 0) continue;
      if(sparse->size == sparse->count)
        resizeVector(sparse, sparse->size + RESIZEDELTA);
      sparse->count++;
      sparse->value[sparse->count] = dense[i];
      sparse->index[sparse->count] = i;
      if(i == sparse->index[0]) 
        sparse->value[0] = dense[i];
    }
  }
  else {
    while(indexStart <= indexEnd) {
      putItem(sparse, indexStart, dense[indexStart]);
      indexStart++;
    }
  }

#ifdef DEBUG_SPARSELIB
  verifyVector(sparse);
#endif

}
예제 #17
0
STDMETHODIMP CBDictionary::putref_Item(VARIANT VarKey, VARIANT pvar)
{
	return putItem(&VarKey, &pvar);
}
예제 #18
0
STDMETHODIMP CBDictionary::Add(VARIANT VarKey, VARIANT var)
{
	return putItem(&VarKey, &var);
}
예제 #19
0
파일: sparselib.c 프로젝트: bremond/siconos
void daxpyVector3(sparseVector *sparse1, REAL scalar, sparseVector *sparse2, int indexStart, int indexEnd)
{
  int i1, i2, k, p1, p2, c1, c2;
  sparseVector *hold;

  if(sparse1->count == 0) return;

 /* Spool to start positions */
  i1 = 1;
  c1 = sparse1->count;
  while(i1 <= c1 && sparse1->index[i1] < indexStart) i1++;
  if(i1 <= c1)
    p1 = sparse1->index[i1];
  else
    p1 = indexEnd+1;

  i2 = 1;
  c2 = sparse2->count;
  while(i2 <= c2 && sparse2->index[i2] < indexStart) i2++;
  if(i2 <= c2)
    p2 = sparse2->index[i2];
  else
    p2 = indexEnd+1;

 /* Create a temporary vector */
  k = c1+c2;
  if(k > 0) {
    hold = createVector(MAX(sparse1->limit, sparse2->limit), k);
    putDiagonalIndex(hold, getDiagonalIndex(sparse2));
  }
  else
    hold = sparse2;

 /* Loop over all items in both vectors */
  while((i1 <= c1 && p1 <= indexEnd) || 
        (i2 <= c2 && p2 <= indexEnd)) {

    k = 0;

   /* Add/spool exclusive right-vector items */
    while(i2 <= c2 && p2 < p1) {
      if(hold != sparse2) {
        putItem(hold, p2, sparse2->value[i2]);
      }
      i2++;
      if(i2 <= c2)
        p2 = sparse2->index[i2];
      else
        p2 = indexEnd+1;
      k++;
    }
   /* Add equal-indexed items */
    while(i1 <= c1 && i2 <= c2 && p1 == p2) {
/*      if(hold != sparse2) */
        putItem(hold, p1, scalar*sparse1->value[i1]+sparse2->value[i2]);
/*      else
          addtoItem(sparse2, -i2, scalar*sparse1->value[i1]); */
      i1++;
      if(i1 <= c1)
        p1 = sparse1->index[i1];
      else
        p1 = indexEnd+1;
      i2++;
      if(i2 <= c2)
        p2 = sparse2->index[i2];
      else
        p2 = indexEnd+1;
      k++;
    }
   /* Add exclusive left-vector items */
    while(i1 <= c1 && p1 < p2) {
      putItem(hold, p1, scalar*sparse1->value[i1]);
/*      if(hold == sparse2) c2++; */
      i1++;
      if(i1 <= c1)
        p1 = sparse1->index[i1];
      else
        p1 = indexEnd+1;
      k++;
    }

    if(k == 0) break;
  }

/*  if(hold != sparse2) */
  {
    swapVector(hold, sparse2);
    freeVector(hold);
  }

#ifdef DEBUG_SPARSELIB
  verifyVector(sparse2);
#endif

}