Esempio n. 1
0
/*----------------------------------------------------------------------------------------------
	Read an array of ITsTextProps from a byte array and return it. If cpttpMax == 0, return
	in cpttpRet the number of items present. Return S_FALSE if the array is not totally
	consumed, but at least one ITsTextProps is successfully read.

	For runs that have duplicate properties (ie, where the offsets into the properties stuff
	are identical), returns duplicate pointers in rgpttp.

	Also return the character counts for each run, so that we can reconstruct the
	run information later on.
----------------------------------------------------------------------------------------------*/
STDMETHODIMP TsPropsFact::DeserializeRgPropsRgb(int cpttpMax, const BYTE * prgb, int * pcb,
		int * pcpttpRet, ITsTextProps ** rgpttp, int * rgich)
{
	BEGIN_COM_METHOD;
	ChkComArgPtr(pcb);
	ChkComOutPtr(pcpttpRet);
	ChkComArrayArg(prgb, *pcb);
	ChkComArrayArg(rgpttp, cpttpMax);
	ChkComArrayArg(rgich, cpttpMax);

	DataReaderRgb drrHdr(prgb, *pcb);
	int crun;
	drrHdr.ReadInt(&crun);
	if (cpttpMax == 0)
	{
		*pcpttpRet = crun;
	}
	else
	{
		Vector<int> vcbOffsets;
		vcbOffsets.Resize(crun);

		const byte * pbRun0 = prgb + isizeof(int) + (crun * isizeof(int) * 2);

		for (int irun = 0; irun < min(cpttpMax, crun); irun++)
		{
			drrHdr.ReadInt(rgich + irun); // character min
			int cbOffsetThisRun;
			drrHdr.ReadInt(&cbOffsetThisRun);
			vcbOffsets[irun] = cbOffsetThisRun;

			// Check for a duplicate set of properties.
			int irunDup;
			for (irunDup = 0; irunDup < irun; irunDup++)
			{
				if (cbOffsetThisRun == vcbOffsets[irunDup])
				{
					// Duplicate offset: copy the previous ITsTextProps.
					rgpttp[irun] = rgpttp[irunDup];
					rgpttp[irun]->AddRef();
					break;
				}
			}
			if (irunDup >= irun) // didn't find duplicate
			{
				const byte * pbThisRun = pbRun0 + cbOffsetThisRun;
				// Note that the buffer size is provided below simply as a sanity check. The
				// data itself is structured so that the deserialize method knows how much
				// to read for each run.
				DataReaderRgb drr(pbThisRun, (*pcb - (pbThisRun - prgb)));
				TsTextProps::DeserializeDataReader(&drr, rgpttp + irun);
			}
		}
		*pcpttpRet = min(cpttpMax, crun);
	}

	END_COM_METHOD(g_factPropsFact, IID_ITsPropsFactory);
}
Esempio n. 2
0
/*----------------------------------------------------------------------------------------------
	Read an ITsTextProps from a byte array and return it.  Return S_FALSE if the array is not
	totally consumed, but an ITsTextProps is successfully read.
----------------------------------------------------------------------------------------------*/
STDMETHODIMP TsPropsFact::DeserializePropsRgb(const byte * prgb, int * pcb,
	ITsTextProps ** ppttp)
{
	BEGIN_COM_METHOD;
	ChkComArgPtr(pcb);
	ChkComOutPtr(ppttp);
	ChkComArrayArg(prgb, *pcb);

	DataReaderRgb drr(prgb, *pcb);
	TsTextProps::DeserializeDataReader(&drr, ppttp);
	return drr.IbCur() < drr.Size() ? S_FALSE : S_OK;

	END_COM_METHOD(g_factPropsFact, IID_ITsPropsFactory);
}
Esempio n. 3
0
// Inserting a node
void bstree::insert(int x,nodeptr &p)
{
	if (p == NULL)
	{
		p = new node;
		p->element = x;
		p->left=NULL;
		p->right = NULL;
		p->height=0;
		if (p==NULL)
			cout<<"\nOut of Space";
	}
	else
	{
		if (x<p->element)
		{
			insert(x,p->left);
			if ((bsheight(p->left) - bsheight(p->right))==2)
			{
				if (x < p->left->element)
					p=srl(p);
				else
					p = drl(p);
			}
		}
		else if (x>p->element)
		{
			insert(x,p->right);
			if ((bsheight(p->right) - bsheight(p->left))==2)
			{
				if (x > p->right->element)
					p=srr(p);
				else
					p = drr(p);
			}
		}
		else
			cout<<"\nElement Exists";
	}
	int m,n,d;
	m=bsheight(p->left);
	n=bsheight(p->right);
	d=max(m,n);
	p->height = d + 1;
}
Esempio n. 4
0
// Inserting a node
void IntervallTree_bed::insert(long start, long stop, Leaf *&p) {
	if (p == NULL) {
		p = new Leaf(start, stop);
		if (p == NULL) {
			std::cout << "Out of Space\n" << std::endl;
		}
	} else {

		long score = p->overlap(start, stop);

		if (score > 0) {
			insert(start, stop, p->left);
			if ((bsheight(p->left) - bsheight(p->right)) == 2) {
				score = p->left->overlap(start, stop);
				if (score > 0) {
					p = srl(p);
				} else {
					p = drl(p);
				}
			}
		} else if (score < 0) {
			insert(start, stop, p->right);
			if ((bsheight(p->right) - bsheight(p->left)) == 2) {
				score = p->right->overlap(start, stop);
				if (score < 0) {
					p = srr(p);
				} else {
					p = drr(p);
				}
			}
		} else { //overlaps!
			std::cerr << "Two regions overlap and are thus ignored:" << std::endl;
		}
	}
	int m, n, d;
	m = bsheight(p->left);
	n = bsheight(p->right);
	d = max(m, n);
	p->set_height(d + 1);
}
void
PorousFlowAqueousPreDisChemistry::computeQpProperties()
{
  _reaction_rate[_qp].resize(_num_reactions);
  _dreaction_rate_dvar[_qp].resize(_num_reactions);
  for (unsigned r = 0; r < _num_reactions; ++r)
    _dreaction_rate_dvar[_qp][r].assign(_num_var, 0.0);

  // Compute the reaction rates
  computeQpReactionRates();

  // Compute the derivatives of the reaction rates
  std::vector<std::vector<Real>> drr(_num_reactions);
  std::vector<Real> drr_dT(_num_reactions);
  for (unsigned r = 0; r < _num_reactions; ++r)
  {
    dQpReactionRate_dprimary(r, drr[r]);
    drr_dT[r] = dQpReactionRate_dT(r);
  }

  // compute _dreaction_rate_dvar[_qp]
  for (unsigned wrt = 0; wrt < _num_primary; ++wrt)
  {
    // derivative with respect to the "wrt"^th primary species concentration
    if (!_dictator.isPorousFlowVariable(_primary_var_num[wrt]))
      continue;
    const unsigned pf_wrt = _dictator.porousFlowVariableNum(_primary_var_num[wrt]);

    // run through the reactions, using drr in the appropriate places
    for (unsigned r = 0; r < _num_reactions; ++r)
      _dreaction_rate_dvar[_qp][r][pf_wrt] = drr[r][wrt];
  }

  // use the derivative wrt temperature
  for (unsigned r = 0; r < _num_reactions; ++r)
    for (unsigned v = 0; v < _num_var; ++v)
      _dreaction_rate_dvar[_qp][r][v] += drr_dT[r] * _dtemperature_dvar[_qp][v];
}