Beispiel #1
0
bool NBBST<T, Threads>::HelpDelete(Info* op){
    infos.publish(op->p->update, 0);
    infos.publish(op->pupdate, 1);
    infos.publish(op, 2);

    Update result = op->p->update;

    //If we succeed
    if(CASPTR(&op->p->update, op->pupdate, Mark(op, MARK))){
        if(op->pupdate){
            infos.releaseNode(Unmark(op->pupdate));
        }

        nodes.releaseNode(op->l);
        HelpMarked(Unmark(op));
        infos.releaseAll();
        
        return true;
    } 
    //if another has succeeded for us
    else if(getState(op->p->update) == MARK && Unmark(op->p->update) == Unmark(op)){
        HelpMarked(Unmark(op));
        infos.releaseAll();
        return true;
    } else {
        Help(result);

        infos.publish(op->gp->update, 0);
        infos.publish(op, 1);
        CASPTR(&op->gp->update, Mark(op, DFLAG), Mark(op, CLEAN));
        infos.releaseAll();

        return false;
    }
}
Beispiel #2
0
static void SamplesAlloc(cThis *t, Samples *samples)
{
#define FIRST -INT_MAX
#define MarkLast(x) (x | Marked(INT_MAX))

#include "KorobovCoeff.c"

  number nx, nf;

  if( samples->sampler == SampleKorobov ) {
    enum { max = Elements(prime) - 2 };
    cint n = IMin(2*samples->n - 1, MAXPRIME);
    int i = Hash(n), p;
    count shift = 2 + NegQ(n - 1000);

    while( i = IMin(IDim(i), max),
           n > (p = prime[i + 1]) || n <= prime[i] ) {
      cint d = (n - Unmark(p)) >> ++shift;
      i += Min1(d);
    }

    samples->coeff = coeff[i][t->ndim - KOROBOV_MINDIM];
    samples->neff = p = Unmark(p);
    samples->n = p/2 + 1;
  }

  nx = t->ndim*(samples->n + 1);		/* need 1 for extrapolation */
  nf = t->ncomp*(samples->n + 1);

  Alloc(samples->x, nx + nf + t->ncomp + t->ncomp);
  samples->f = samples->x + nx;
}
void RangeDrawer::TerrainCoordClicked(const float &tx, const float &ty, const bool &shift_down) {
    
    const int x = TerrainX2QuadX(tx), y = TerrainY2QuadY(ty);
    
    switch (markMode) {
    
        case MARK_CONTROL_POINT:
            if (!mouseIsDown) { // Mouse was recently pressed
                mouseDownIsMarking = !marked[y][x]; // if (x,y) was marked, only mark until mouse release
                markedWithShift->Reset();
            }
            mouseIsDown = true;
            
            if (!shift_down) {
                
                markedWithShift->Reset();
                mouseDownIsMarking ? Mark(x, y) : Unmark(x, y);
                
            } else {
                
                markedWithShift->Mark(x, y);
                for ( int y=markedWithShift->y_min; y<=markedWithShift->y_max; y++) {
                    for ( int x=markedWithShift->x_min; x<=markedWithShift->x_max; x++) {
                        mouseDownIsMarking ? Mark(x, y) : Unmark(x, y);
                    }
                }
            }
            break;
            
        case MARK_TEE:
            UnmarkAll();
            if (teeMarked) {
                // Mark and unmark previous tee position for change to be registered and vertex to be reset
                Mark(teeMarkPos.x, teeMarkPos.y);
                Unmark(teeMarkPos.x, teeMarkPos.y);
            }
            teeMarked = true;
            teeMarkPos = { x, y };
            teeTerrainPos = glm::vec2(tx, ty);
            SetMarkChanged();
            break;
        
        case MARK_TARGET:
            UnmarkAll();
            if (targetMarked) {
                // Mark and unmark previous tee position for change to be registered and vertex to be reset
                Mark(targetMarkPos.x, targetMarkPos.y);
                Unmark(targetMarkPos.x, targetMarkPos.y);
            }
            targetMarked = true;
            targetMarkPos = { x, y };
            targetTerrainPos = glm::vec2(tx, ty);
            SetMarkChanged();
            break;
        
        case NONE:
            // do nothing
            break;
    }
}
Beispiel #4
0
void NBBST<T, Threads>::Help(Update u){
    if(getState(u) == IFLAG){
        HelpInsert(Unmark(u));
    } else if(getState(u) == MARK){
        HelpMarked(Unmark(u));
    } else if(getState(u) == DFLAG){
        HelpDelete(Unmark(u));
    }
}
Beispiel #5
0
int EList::UnmarkAll() {
    NeedsRedraw = 1;
    for (int i = 0; i < Count; i++) {
        if (IsMarked(i))
            if (Unmark(i) != 1) return ErFAIL;
    }
    return ErOK;
}
Beispiel #6
0
int EList::ExecCommand(int Command, ExState &State) {
    int W = 1;
    int H = 1;

    if (View && View->MView && View->MView->Win) {
        View->MView->ConQuerySize(&W, &H);
        H--;
    }
    FixPos();
    switch (Command) {
    case ExMoveLeft:
        return MoveLeft();
    case ExMoveRight:
        return MoveRight();
    case ExMoveUp:
        return MoveUp();
    case ExMoveDown:
        return MoveDown();
    case ExMovePageUp:
        return MovePageUp();
    case ExMovePageDown:
        return MovePageDown();
    case ExScrollLeft:
        return ScrollLeft(8);
    case ExScrollRight:
        return ScrollRight(8);
    case ExMovePageStart:
        return MovePageStart();
    case ExMovePageEnd:
        return MovePageEnd();
    case ExMoveFileStart:
        return MoveFileStart();
    case ExMoveFileEnd:
        return MoveFileEnd();
    case ExMoveLineStart:
        return MoveLineStart();
    case ExMoveLineEnd:
        return MoveLineEnd();
    case ExRescan:
        RescanList();
        return ErOK;
    case ExActivate:
        return Activate();
    case ExListMark:
        return Mark();
    case ExListUnmark:
        return Unmark();
    case ExListToggleMark:
        return ToggleMark();
    case ExListMarkAll:
        return MarkAll();
    case ExListUnmarkAll:
        return UnmarkAll();
    case ExListToggleMarkAll:
        return ToggleMarkAll();
    }
    return EModel::ExecCommand(Command, State);
}
Beispiel #7
0
void scContUnit::Retabulate( TypeSpec ts )
{
	if ( GetContentSize() > 0 ) {

		fCharArray.Retabulate( fSpecRun, 0L, GetContentSize(), ts, GetContentSize() );
		Mark( scREBREAK );
	}
	Unmark( scRETABULATE );
}
Beispiel #8
0
void NBBST<T, Threads>::releaseNode(Node* node){
    if(node){
        if(node->update){
            infos.releaseNode(Unmark(node->update));
        }

        nodes.releaseNode(node);
    }
}
Beispiel #9
0
/* draw the line */
void scTextline::Draw( APPDrwCtx		appMat,
					   const scFlowDir& flowDir,
					   const scMuPoint& transpt )
{
	if ( !fPara->Marked( scREBREAK | scRETABULATE ) ) {
		if ( GetCharCount() || Marked( scLASTLINE ) ) {
			scDrawLine ld( *this, flowDir, appMat, transpt );
			ld.Draw();
		}
		Unmark( scREPAINT );  
	}
}
Beispiel #10
0
static void SamplesAlloc(Samples *samples)
{
#define FIRST -INT_MAX
#define MarkLast(x) (x | Marked(INT_MAX))

#include "KorobovCoeff.c"

  count nx, nf;

  if( samples->sampler == SampleKorobov ) {
    enum { max = Elements(prime) - 2 };
    cint n = IMin(2*samples->n - 1, MAXPRIME);
    int i = Hash(n), p;
    count shift = 2 + NegQ(n - 1000);

    while( i = IMin(IDim(i), max),
           n > (p = prime[i + 1]) || n <= prime[i] ) {
      cint d = (n - Unmark(p)) >> ++shift;
      i += Min1(d);
    }

    samples->coeff = coeff[i][ndim_ - KOROBOV_MINDIM];
    samples->neff = p = Unmark(p);
    samples->n = p/2 + 1;
  }

  nx = ndim_*(samples->n + 1);		/* need 1 for extrapolation */
  nf = ncomp_*(samples->n + 1);

  Allocate(samples->x, nx + nf + ncomp_ + ncomp_);
  samples->f = samples->x + nx;
  samples->avg = samples->f + nf;
  samples->err = samples->avg + ncomp_;
  ResClear(samples->err);

  samples->weight = 1./samples->neff;
}
Beispiel #11
0
bool NBBST<T, Threads>::remove(T value){
    int key = hash(value);

    SearchResult search;

    while(true){
        Search(key, &search);
        nodes.publish(search.l, 0);
        
        if(search.l->key != key){
            return false;
        }

        if(getState(search.gpupdate) != CLEAN){
            Help(search.gpupdate);
        } else if(getState(search.pupdate) != CLEAN){
            Help(search.pupdate);
        } else {
            infos.publish(search.gp->update, 0);
            infos.publish(search.gpupdate, 1);

            Info* op = newDInfo(search.gp, search.p, search.l, search.pupdate);
            infos.publish(op, 2);

            Update result = search.gp->update;
            if(CASPTR(&search.gp->update, search.gpupdate, Mark(op, DFLAG))){
                if(search.gpupdate){
                    infos.releaseNode(Unmark(search.gpupdate));
                }
                
                infos.releaseAll();

                if(HelpDelete(op)){
                    nodes.releaseAll();
                    
                    return true;
                }
            } else {
                infos.releaseNode(op);
                infos.releaseAll();

                Help(result);
            }
        }
        
        nodes.releaseAll();
    }
}
Beispiel #12
0
int EList::ToggleMark() {
    if (Count > 0) {
        if (IsMarked(Row)) {
            if (Unmark(Row) == 1) {
                NeedsRedraw = 1;
                return ErOK;
            }
        } else {
            if (Mark(Row) == 1) {
                NeedsRedraw = 1;
                return ErOK;
            }
        }
    }
    return ErFAIL;
}
Beispiel #13
0
void scTBObj::Read( scSet*		enumTable,
                    APPCtxPtr	ctxPtr,
                    IOFuncPtr	readFunc )
{
    uchar			abuf[FILE_SIZE_OBJECT];
    const uchar*	pbuf	= abuf;

    ReadBytes( abuf, ctxPtr, readFunc, FILE_SIZE_OBJECT );

    ulong	val;
    pbuf = BufGet_long( pbuf, val, kIntelOrder );
    fBits = val;

    pbuf = BufGet_long( pbuf, val, kIntelOrder );
    fNext = (scTBObj*)val;

    pbuf = BufGet_long( pbuf, val, kIntelOrder );
    fPrev = (scTBObj*)val;

    Unmark( scPTRRESTORED );
    scAssert ((size_t)(pbuf-abuf) == FILE_SIZE_OBJECT );
}
Beispiel #14
0
eRefEvent scContUnit::Reformat2( scCOLRefData&	cData,
								 PrevParaData&	prevParaData,
								 int			keepWNextControl,
								 int&			breakControl			
#if SCDEBUG > 1
								, int&			reformatEvent 
#endif
								)
{

	DCState	dcState;
	Bool	tryAgain;
	Bool	leadRetry		= false;	// a retry based upon a leading increase on the line
	Bool	overFlow		= false;
	Bool	testGetStrip	= true;


	SCDebugTrace( 1, scString( "scContUnit::Reformat IN 0x%08x %d\n" ), this, GetCount() );

	cData.PARAInit( this, breakControl, keepWNextControl, prevParaData );
 
	dcState.SetColumn( cData.GetActive()  );
	scFlowDir fd( cData.fCol->GetFlowdir() );
	
	if ( cData.fPData.fPrevline ) {
		if ( fd.IsHorizontal() )
			cData.fSavedPrevEnd.x = LONG_MAX;
		else {
			cData.fSavedPrevEnd.y = LONG_MAX;
		}
	}

	for ( tryAgain = true; tryAgain; ) {
		for ( overFlow = false; cData.fPData.fBreakType != eEndStreamBreak || overFlow; ) {
			
			if ( !overFlow )
				cData.fPData.SetLineData( leadRetry );		// set up initial line conditions
			
			if ( !overFlow && cData.AllocGeometry() ) {	  	// allocatate the geometry from
															// the parent column, if we overflow
															// the column, we go to the next column

				try {
					cData.AllocLine( leadRetry );	 		// allocate the memory, reuse scheme is used
				} 
				catch( ... ) {
					cData.fPData.PARAFini( );
					throw;
				} 

				cData.fPData.SetColumn( cData.fCol );
				leadRetry = cData.fPData.ComposeLine( dcState );  // compose the line
				
				if ( !leadRetry ) {
					// we are accepting the line as is 
					MicroPoint x, y;
					if ( fd.IsHorizontal() ) {
						x = cData.fPData.fComposedLine.fOrg.x + cData.fPData.fComposedLine.fMeasure;
						y = cData.fPData.fComposedLine.fOrg.y;
					}
					else {
						x = cData.fPData.fComposedLine.fOrg.x;
						y = cData.fPData.fComposedLine.fOrg.y + cData.fPData.fComposedLine.fMeasure;
					}
					cData.fSavedPrevEnd.Set( x, y );
				}
				else
					; // we are going to reposition the line and rebreak it
			}
			else {
					// No more room in column, let's try the next column
				overFlow	= false;

					// if we try and relead at the bottom of a container and we 
					// overflow we need to set "leadRetry" to false since at this
					// point it is not a retry any more but a whole new container
				leadRetry 	= false;

				if ( !cData.fPData.fPrevline )
					testGetStrip = false;

				if ( !breakControl && cData.ResetOrphan( testGetStrip ) ) {
					breakControl++;
					return eRebreak;
				}
				
				cData.fCol->DeleteExcessLines( this, cData.fPData.fPrevline, testGetStrip, cData );
				testGetStrip = true;

					// find the next column 
				if ( cData.FindNextCol( dcState ) )	{
						// the finding of the next column may reset the para spec
					scCachedStyle::SetParaStyle( this, defspec_ ); 
					continue;
				}
				else {
					overFlow = true;
					break;
				}
			}


		}

		tryAgain = ResetWidow( cData, testGetStrip );

	}

	if ( GetFirstline() )
		cData.PARADeleteExcessLines( );

#if SCDEBUG > 1
	SetReformatEvent( reformatEvent++ );
#endif

	Unmark( scREBREAK );

	if ( !overFlow )
		scAssert( GetLastline() != 0 );

	cData.fPData.PARAFini( );

	prevParaData.lastLineH	= cData.fPData.fTextline;
	prevParaData.lastSpec	= cData.fPData.fCurSpecRec->spec();

	SCDebugTrace( 1, scString( "scContUnit::Reformat OUT 0x%08x %d\n" ), this, GetCount() );

	return !overFlow ? eNormalReformat : eOverflowGeometry;
}
Beispiel #15
0
static int Integrate(creal epsrel, creal epsabs,
  cint flags, cnumber mineval, cnumber maxeval,
  int key1, int key2, int key3, ccount maxpass, 
  creal maxchisq, creal mindeviation,
  real *integral, real *error, real *prob)
{
  TYPEDEFREGION;

  Region anchor, *region;
  Totals totals[NCOMP];
  real nneed, weight;
  count dim, comp, iter, nregions, pass = 0, err;
  number nwant, nmin = INT_MAX;
  int fail = -1;

  if( VERBOSE > 1 ) {
    char s[512];
    sprintf(s, "Divonne input parameters:\n"
      "  ndim " COUNT "\n  ncomp " COUNT "\n"
      "  epsrel " REAL "\n  epsabs " REAL "\n"
      "  flags %d\n  mineval " NUMBER "\n  maxeval " NUMBER "\n"
      "  key1 %d\n  key2 %d\n  key3 %d\n  maxpass " COUNT "\n"
      "  border " REAL "\n  maxchisq " REAL "\n  mindeviation " REAL "\n"
      "  ngiven " NUMBER "\n  nextra " NUMBER "\n",
      ndim_, ncomp_,
      epsrel, epsabs,
      flags, mineval, maxeval,
      key1, key2, key3, maxpass,
      border_.lower, maxchisq, mindeviation,
      ngiven_, nextra_);
    Print(s);
  }

  anchor.next = NULL;
  for( dim = 0; dim < ndim_; ++dim ) {
    Bounds *b = &anchor.bounds[dim];
    b->lower = 0;
    b->upper = 1;
  }

  RuleIni(&rule7_);
  RuleIni(&rule9_);
  RuleIni(&rule11_);
  RuleIni(&rule13_);
  SamplesIni(&samples_[0]);
  SamplesIni(&samples_[1]);
  SamplesIni(&samples_[2]);

#ifdef MLVERSION
  if( setjmp(abort_) ) goto abort;
#endif

  /* Step 1: partition the integration region */

  if( VERBOSE ) Print("Partitioning phase:");

  if( IsSobol(key1) || IsSobol(key2) || IsSobol(key3) )
    IniRandom(2*maxeval, flags);

  SamplesLookup(&samples_[0], key1,
    (number)47, (number)INT_MAX, (number)0);
  SamplesAlloc(&samples_[0]);

  totals_ = totals;
  Zap(totals);
  phase_ = 1;

  Explore(&anchor, &samples_[0], INIDEPTH, 1);

  for( iter = 1; ; ++iter ) {
    Totals *maxtot;

    for( comp = 0; comp < ncomp_; ++comp ) {
      Totals *tot = &totals[comp];
      tot->avg = tot->spreadsq = 0;
      tot->spread = tot->secondspread = -INFTY;
    }

    nregions = 0;
    for( region = anchor.next; region; region = region->next ) {
      ++nregions;
      for( comp = 0; comp < ncomp_; ++comp ) {
        cResult *r = &region->result[comp];
        Totals *tot = &totals[comp];
        tot->avg += r->avg;
        tot->spreadsq += Sq(r->spread);
        if( r->spread > tot->spread ) {
          tot->secondspread = tot->spread;
          tot->spread = r->spread;
          tot->region = region;
        }
        else if( r->spread > tot->secondspread )
          tot->secondspread = r->spread;
      }
    }

    maxtot = totals;
    for( comp = 0; comp < ncomp_; ++comp ) {
      Totals *tot = &totals[comp];
      integral[comp] = tot->avg;
      if( tot->spreadsq > maxtot->spreadsq ) maxtot = tot;
      tot->spread = sqrt(tot->spreadsq);
      error[comp] = tot->spread*samples_[0].weight;
    }

    if( VERBOSE ) {
      char s[128 + 64*NCOMP], *p = s;

      p += sprintf(p, "\n"
        "Iteration " COUNT " (pass " COUNT "):  " COUNT " regions\n"
        NUMBER7 " integrand evaluations so far,\n"
        NUMBER7 " in optimizing regions,\n"
        NUMBER7 " in finding cuts",
        iter, pass, nregions, neval_, neval_opt_, neval_cut_);

      for( comp = 0; comp < ncomp_; ++comp )
        p += sprintf(p, "\n[" COUNT "] "
          REAL " +- " REAL,
          comp + 1, integral[comp], error[comp]);

      Print(s);
    }

    if( neval_ > maxeval ) break;

    nneed = maxtot->spread/MaxErr(maxtot->avg);
    if( nneed < MAXPRIME ) {
      cnumber n = neval_ + nregions*(number)ceil(nneed);
      if( n < nmin ) {
        nmin = n;
        pass = 0;
      }
      else if( ++pass > maxpass && n >= mineval ) break;
    }

    Split(maxtot->region, DEPTH);
  }

  /* Step 2: do a "full" integration on each region */

/* nneed = samples_[0].neff + 1; */
  nneed = 2*samples_[0].neff;
  for( comp = 0; comp < ncomp_; ++comp ) {
    Totals *tot = &totals[comp];
    creal maxerr = MaxErr(tot->avg);
    tot->nneed = tot->spread/maxerr;
    nneed = Max(nneed, tot->nneed);
    tot->maxerrsq = Sq(maxerr);
    tot->mindevsq = tot->maxerrsq*Sq(mindeviation);
  }
  nwant = (number)Min(ceil(nneed), MARKMASK/40.);

  err = SamplesLookup(&samples_[1], key2, nwant,
    (maxeval - neval_)/nregions + 1, samples_[0].n + 1);

  /* the number of points needed to reach the desired accuracy */
  fail = Unmark(err)*nregions;

  if( Marked(err) ) {
    if( VERBOSE ) Print("\nNot enough samples left for main integration.");
    for( comp = 0; comp < ncomp_; ++comp )
      prob[comp] = -999;
    weight = samples_[0].weight;
    nregions_ = nregions;
  }
  else {
    bool can_adjust = (key3 == 1 && samples_[1].sampler != SampleRule &&
      (key2 < 0 || samples_[1].neff < MAXPRIME));
    count df, nlimit;

    SamplesAlloc(&samples_[1]);

    if( VERBOSE ) {
      char s[128];
      sprintf(s, "\nMain integration on " COUNT
        " regions with " NUMBER " samples per region.",
        nregions, samples_[1].neff);
      Print(s);
    }

    ResClear(integral);
    ResClear(error);
    ResClear(prob);

    nlimit = maxeval - nregions*samples_[1].n;
    df = nregions_ = 0;

    for( region = anchor.next; region; region = region->next ) {
      char s[64*NDIM + 256*NCOMP], *p = s;
      int todo;

refine:
      phase_ = 2;
      samples_[1].sampler(&samples_[1], region->bounds, region->vol);

      if( can_adjust ) {
        --nregions;
        for( comp = 0; comp < ncomp_; ++comp )
          totals[comp].spreadsq -= Sq(region->result[comp].spread);
      }

      nlimit += samples_[1].n;
      todo = 0;

      for( comp = 0; comp < ncomp_; ++comp ) {
        cResult *r = &region->result[comp];
        Totals *tot = &totals[comp];

        samples_[0].avg[comp] = r->avg;
        samples_[0].err[comp] = r->err;

        if( neval_ < nlimit ) {
          creal avg2 = samples_[1].avg[comp];
          creal err2 = samples_[1].err[comp];
          creal diffsq = Sq(avg2 - r->avg);

#define Var(s) Sq((s.err[comp] == 0) ? r->spread*s.weight : s.err[comp])

          if( err2*tot->nneed > r->spread ||
              diffsq > Max(maxchisq*(Var(samples_[0]) + Var(samples_[1])),
                           EPS*Sq(avg2)) ) {
            if( key3 && diffsq > tot->mindevsq ) {
              if( key3 == 1 ) {
                const Region *next = region->next;

                if( VERBOSE > 2 ) Print("\nSplit");

                phase_ = 1;
                Explore(region, &samples_[1], POSTDEPTH, 2);

                if( can_adjust ) {
                  number nnew;
                  Region *child;

                  for( child = region; child != next; child = child->next ) {
                    count c;
                    for( c = 0; c < ncomp_; ++c )
                      totals[c].spreadsq += Sq(child->result[c].spread);
                    ++nregions;
                  }

                  nnew = (tot->spreadsq/Sq(MARKMASK) > tot->maxerrsq) ?
                    MARKMASK :
                    (number)ceil(sqrt(tot->spreadsq/tot->maxerrsq));
                  if( nnew > nwant + nwant/64 ) {
                    ccount err = SamplesLookup(&samples_[1], key2, nnew,
                      (maxeval - neval_)/nregions + 1, samples_[1].n);
                    fail += Unmark(err)*nregions;
                    nwant = nnew;
                    SamplesFree(&samples_[1]);
                    SamplesAlloc(&samples_[1]);

                    if( key2 > 0 && samples_[1].neff >= MAXPRIME )
                      can_adjust = false;

                    if( VERBOSE > 2 ) {
                      char s[128];
                      sprintf(s, "Sampling remaining " COUNT
                        " regions with " NUMBER " points per region.",
                        nregions, samples_[1].neff);
                      Print(s);
                    }
                  }
                }

                goto refine;
              }
              todo |= 3;
            }
            todo |= 1;
          }
        }
      }

      if( can_adjust ) {
        for( comp = 0; comp < ncomp_; ++comp )
          totals[comp].maxerrsq -=
            Sq(region->result[comp].spread*samples_[1].weight);
      }

      switch( todo ) {
      case 1:	/* get spread right */
        Explore(region, &samples_[1], 0, 2);
        break;

      case 3:	/* sample region again with more points */
        if( MEM(&samples_[2]) == NULL ) {
          SamplesLookup(&samples_[2], key3,
            nwant, (number)INT_MAX, (number)0);
          SamplesAlloc(&samples_[2]);
        }
        phase_ = 3;
        samples_[2].sampler(&samples_[2], region->bounds, region->vol);
        Explore(region, &samples_[2], 0, 2);
        ++region->depth;	/* misused for df here */
        ++df;
      }

      ++region->depth;	/* misused for df here */
      ++nregions_;

      if( VERBOSE > 2 ) {
        for( dim = 0; dim < ndim_; ++dim ) {
          cBounds *b = &region->bounds[dim];
          p += sprintf(p,
            (dim == 0) ? "\nRegion (" REALF ") - (" REALF ")" :
                         "\n       (" REALF ") - (" REALF ")",
            b->lower, b->upper);
        }
      }

      for( comp = 0; comp < ncomp_; ++comp ) {
        Result *r = &region->result[comp];

        creal x1 = samples_[0].avg[comp];
        creal s1 = Var(samples_[0]);
        creal x2 = samples_[1].avg[comp];
        creal s2 = Var(samples_[1]);
        creal r2 = (s1 == 0) ? Sq(samples_[1].neff*samples_[0].weight) : s2/s1;

        real norm = 1 + r2;
        real avg = x2 + r2*x1;
        real sigsq = s2;
        real chisq = Sq(x2 - x1);
        real chiden = s1 + s2;

        if( todo == 3 ) {
          creal x3 = samples_[2].avg[comp];
          creal s3 = Var(samples_[2]);
          creal r3 = (s2 == 0) ? Sq(samples_[2].neff*samples_[1].weight) : s3/s2;

          norm = 1 + r3*norm;
          avg = x3 + r3*avg;
          sigsq = s3;
          chisq = s1*Sq(x3 - x2) + s2*Sq(x3 - x1) + s3*chisq;
          chiden = s1*s2 + s3*chiden;
        }

        avg = LAST ? r->avg : (sigsq *= norm = 1/norm, avg*norm);
        if( chisq > EPS ) chisq /= Max(chiden, NOTZERO);

#define Out(s) s.avg[comp], r->spread*s.weight, s.err[comp]

        if( VERBOSE > 2 ) {
          p += sprintf(p, "\n[" COUNT "] "
            REAL " +- " REAL "(" REAL ")\n    "
            REAL " +- " REAL "(" REAL ")",
            comp + 1, Out(samples_[0]), Out(samples_[1]));
          if( todo == 3 ) p += sprintf(p, "\n    "
            REAL " +- " REAL "(" REAL ")",
            Out(samples_[2]));
          p += sprintf(p, "  \tchisq " REAL, chisq);
        }

        integral[comp] += avg;
        error[comp] += sigsq;
        prob[comp] += chisq;

        r->avg = avg;
        r->spread = sqrt(sigsq);
        r->chisq = chisq;
      }

      if( VERBOSE > 2 ) Print(s);
    }

    for( comp = 0; comp < ncomp_; ++comp )
      error[comp] = sqrt(error[comp]);

    df += nregions_;

    if( VERBOSE > 2 ) {
      char s[16 + 128*NCOMP], *p = s;

      p += sprintf(p, "\nTotals:");

      for( comp = 0; comp < ncomp_; ++comp )
        p += sprintf(p, "\n[" COUNT "] "
          REAL " +- " REAL "  \tchisq " REAL " (" COUNT " df)",
          comp + 1, integral[comp], error[comp], prob[comp], df);

      Print(s);
    }

    for( comp = 0; comp < ncomp_; ++comp )
      prob[comp] = ChiSquare(prob[comp], df);

    weight = 1;
  }

#ifdef MLVERSION
  if( REGIONS ) {
    MLPutFunction(stdlink, "List", 2);
    MLPutFunction(stdlink, "List", nregions_);
    for( region = anchor.next; region; region = region->next ) {
      cBounds *b = region->bounds;
      real lower[NDIM], upper[NDIM];

      for( dim = 0; dim < ndim_; ++dim ) {
        lower[dim] = b[dim].lower;
        upper[dim] = b[dim].upper;
      }

      MLPutFunction(stdlink, "Cuba`Divonne`region", 4);

      MLPutRealList(stdlink, lower, ndim_);
      MLPutRealList(stdlink, upper, ndim_);

      MLPutFunction(stdlink, "List", ncomp_);
      for( comp = 0; comp < ncomp_; ++comp ) {
        cResult *r = &region->result[comp];
        real res[] = {r->avg, r->spread*weight, r->chisq};
        MLPutRealList(stdlink, res, Elements(res));
      }

      MLPutInteger(stdlink, region->depth);  /* misused for df */
    }
  }
#endif

#ifdef MLVERSION
abort:
#endif

  SamplesFree(&samples_[2]);
  SamplesFree(&samples_[1]);
  SamplesFree(&samples_[0]);
  RuleFree(&rule13_);
  RuleFree(&rule11_);
  RuleFree(&rule9_);
  RuleFree(&rule7_);

  for( region = anchor.next; region; ) {
    Region *next = region->next;
    free(region);
    region = next;
  }

  return fail;
}
Beispiel #16
0
bool NBBST<T, Threads>::add(T value){
    int key = hash(value);

    Node* newNode = newLeaf(key);

    SearchResult search;

    while(true){
        Search(key, &search);

        nodes.publish(search.l, 0);
            
        infos.publish(search.p->update, 0);
        infos.publish(search.pupdate, 1);

        if(search.l->key == key){
            nodes.releaseNode(newNode);
            nodes.releaseAll();
            
            infos.releaseAll();

            return false; //Key already in the set
        }

        if(getState(search.pupdate) != CLEAN){
            Help(search.pupdate);
        } else {
            Node* newSibling = newLeaf(search.l->key);
            Node* newInt = newInternal(std::max(key, search.l->key));
            newInt->update = Mark(nullptr, CLEAN);
            
            //Put the smaller child on the left
            if(newNode->key <= newSibling->key){
                newInt->left = newNode;
                newInt->right = newSibling;
            } else {
                newInt->left = newSibling;
                newInt->right = newNode;
            }

            Info* op = newIInfo(search.p, newInt, search.l);
            infos.publish(op, 2);

            Update result = search.p->update;
            if(CASPTR(&search.p->update, search.pupdate, Mark(op, IFLAG))){
                HelpInsert(op);

                if(search.pupdate){
                    infos.releaseNode(Unmark(search.pupdate));
                }
                
                nodes.releaseAll();
                infos.releaseAll();

                return true;
            } else {
                nodes.releaseNode(newInt);
                nodes.releaseNode(newSibling);
                nodes.releaseAll();
                
                infos.releaseNode(op);
                infos.releaseAll();

                Help(result);
            }
        }
    }
}
Beispiel #17
0
static int Integrate(This *t, real *integral, real *error, real *prob)
{
  TYPEDEFREGION;

  Totals totals[NCOMP];
  real nneed, weight;
  count dim, comp, iter, pass = 0, err, iregion;
  number nwant, nmin = INT_MAX;
  int fail;

  if( VERBOSE > 1 ) {
    char s[512];
    sprintf(s, "Divonne input parameters:\n"
      "  ndim " COUNT "\n  ncomp " COUNT "\n"
      "  epsrel " REAL "\n  epsabs " REAL "\n"
      "  flags %d\n  seed %d\n"
      "  mineval " NUMBER "\n  maxeval " NUMBER "\n"
      "  key1 %d\n  key2 %d\n  key3 %d\n  maxpass " COUNT "\n"
      "  border " REAL "\n  maxchisq " REAL "\n  mindeviation " REAL "\n"
      "  ngiven " NUMBER "\n  nextra " NUMBER,
      t->ndim, t->ncomp,
      t->epsrel, t->epsabs,
      t->flags, t->seed,
      t->mineval, t->maxeval,
      t->key1, t->key2, t->key3, t->maxpass,
      t->border.lower, t->maxchisq, t->mindeviation,
      t->ngiven, t->nextra);
    Print(s);
  }

  if( BadComponent(t) ) return -2;
  if( BadDimension(t, t->key1) ||
      BadDimension(t, t->key2) ||   
      ((t->key3 & -2) && BadDimension(t, t->key3)) ) return -1;

  t->neval_opt = t->neval_cut = 0;

  t->size = CHUNKSIZE;
  MemAlloc(t->voidregion, t->size*sizeof(Region));
  for( dim = 0; dim < t->ndim; ++dim ) {
    Bounds *b = &RegionPtr(0)->bounds[dim];
    b->lower = 0;
    b->upper = 1;
  }

  RuleIni(&t->rule7);
  RuleIni(&t->rule9);
  RuleIni(&t->rule11);
  RuleIni(&t->rule13);
  SamplesIni(&t->samples[0]);
  SamplesIni(&t->samples[1]);
  SamplesIni(&t->samples[2]);

  if( (fail = setjmp(t->abort)) ) goto abort;

  t->epsabs = Max(t->epsabs, NOTZERO);

  /* Step 1: partition the integration region */

  if( VERBOSE ) Print("Partitioning phase:");

  if( IsSobol(t->key1) || IsSobol(t->key2) || IsSobol(t->key3) )
    IniRandom(t);

  SamplesLookup(t, &t->samples[0], t->key1,
    (number)47, (number)INT_MAX, (number)0);
  SamplesAlloc(t, &t->samples[0]);

  t->totals = totals;
  Zap(totals);
  t->phase = 1;

  Explore(t, 0, &t->samples[0], INIDEPTH, 1);

  for( iter = 1; ; ++iter ) {
    Totals *maxtot;
    count valid;

    for( comp = 0; comp < t->ncomp; ++comp ) {
      Totals *tot = &totals[comp];
      tot->avg = tot->spreadsq = 0;
      tot->spread = tot->secondspread = -INFTY;
    }

    for( iregion = 0; iregion < t->nregions; ++iregion ) {
      Region *region = RegionPtr(iregion);
      for( comp = 0; comp < t->ncomp; ++comp ) {
        cResult *r = &region->result[comp];
        Totals *tot = &totals[comp];
        tot->avg += r->avg;
        tot->spreadsq += Sq(r->spread);
        if( r->spread > tot->spread ) {
          tot->secondspread = tot->spread;
          tot->spread = r->spread;
          tot->iregion = iregion;
        }
        else if( r->spread > tot->secondspread )
          tot->secondspread = r->spread;
      }
    }

    maxtot = totals;
    valid = 0;
    for( comp = 0; comp < t->ncomp; ++comp ) {
      Totals *tot = &totals[comp];
      integral[comp] = tot->avg;
      valid += tot->avg == tot->avg;
      if( tot->spreadsq > maxtot->spreadsq ) maxtot = tot;
      tot->spread = sqrt(tot->spreadsq);
      error[comp] = tot->spread*t->samples[0].weight;
    }

    if( VERBOSE ) {
      char s[128 + 64*NCOMP], *p = s;

      p += sprintf(p, "\n"
        "Iteration " COUNT " (pass " COUNT "):  " COUNT " regions\n"
        NUMBER7 " integrand evaluations so far,\n"
        NUMBER7 " in optimizing regions,\n"
        NUMBER7 " in finding cuts",
        iter, pass, t->nregions, t->neval, t->neval_opt, t->neval_cut);

      for( comp = 0; comp < t->ncomp; ++comp )
        p += sprintf(p, "\n[" COUNT "] "
          REAL " +- " REAL,
          comp + 1, integral[comp], error[comp]);

      Print(s);
    }

    if( valid == 0 ) goto abort;	/* all NaNs */

    if( t->neval > t->maxeval ) break;

    nneed = maxtot->spread/MaxErr(maxtot->avg);
    if( nneed < MAXPRIME ) {
      cnumber n = t->neval + t->nregions*(number)ceil(nneed);
      if( n < nmin ) {
        nmin = n;
        pass = 0;
      }
      else if( ++pass > t->maxpass && n >= t->mineval ) break;
    }

    Split(t, maxtot->iregion, DEPTH);
  }

  /* Step 2: do a "full" integration on each region */

/* nneed = t->samples[0].neff + 1; */
  nneed = 2*t->samples[0].neff;
  for( comp = 0; comp < t->ncomp; ++comp ) {
    Totals *tot = &totals[comp];
    creal maxerr = MaxErr(tot->avg);
    tot->nneed = tot->spread/maxerr;
    nneed = Max(nneed, tot->nneed);
    tot->maxerrsq = Sq(maxerr);
    tot->mindevsq = tot->maxerrsq*Sq(t->mindeviation);
  }
  nwant = (number)Min(ceil(nneed), MARKMASK/40.);

  err = SamplesLookup(t, &t->samples[1], t->key2, nwant,
    (t->maxeval - t->neval)/t->nregions + 1, t->samples[0].n + 1);

  /* the number of points needed to reach the desired accuracy */
  fail = Unmark(err)*t->nregions;

  if( Marked(err) ) {
    if( VERBOSE ) Print("\nNot enough samples left for main integration.");
    for( comp = 0; comp < t->ncomp; ++comp )
      prob[comp] = -999;
    weight = t->samples[0].weight;
  }
  else {
    bool can_adjust = (t->key3 == 1 && t->samples[1].sampler != SampleRule &&
      (t->key2 < 0 || t->samples[1].neff < MAXPRIME));
    count df, nlimit;

    SamplesAlloc(t, &t->samples[1]);

    if( VERBOSE ) {
      char s[128];
      sprintf(s, "\nMain integration on " COUNT
        " regions with " NUMBER " samples per region.",
        t->nregions, t->samples[1].neff);
      Print(s);
    }

    ResClear(integral);
    ResClear(error);
    ResClear(prob);

    nlimit = t->maxeval - t->nregions*t->samples[1].n;
    df = 0;

    for( iregion = 0; iregion < t->nregions; ++iregion ) {
      Region *region = RegionPtr(iregion);
      char s[64*NDIM + 256*NCOMP], *p = s;
      int todo;

refine:
      t->phase = 2;
      t->samples[1].sampler(t, &t->samples[1], region->bounds, region->vol);

      if( can_adjust )
        for( comp = 0; comp < t->ncomp; ++comp )
          totals[comp].spreadsq -= Sq(region->result[comp].spread);

      nlimit += t->samples[1].n;
      todo = 0;

      for( comp = 0; comp < t->ncomp; ++comp ) {
        cResult *r = &region->result[comp];
        Totals *tot = &totals[comp];

        t->samples[0].avg[comp] = r->avg;
        t->samples[0].err[comp] = r->err;

        if( t->neval < nlimit ) {
          creal avg2 = t->samples[1].avg[comp];
          creal err2 = t->samples[1].err[comp];
          creal diffsq = Sq(avg2 - r->avg);

#define Var(s) Sq((s.err[comp] == 0) ? r->spread*s.weight : s.err[comp])

          if( err2*tot->nneed > r->spread ||
              diffsq > Max(t->maxchisq*(Var(t->samples[0]) + Var(t->samples[1])),
                           EPS*Sq(avg2)) ) {
            if( t->key3 && diffsq > tot->mindevsq ) {
              if( t->key3 == 1 ) {
                ccount xregion = t->nregions;

                if( VERBOSE > 2 ) Print("\nSplit");

                t->phase = 1;
                Explore(t, iregion, &t->samples[1], POSTDEPTH, 2);

                if( can_adjust ) {
                  number nnew;
                  count ireg, xreg;

                  for( ireg = iregion, xreg = xregion;
                       ireg < t->nregions; ireg = xreg++ ) {
                    cResult *result = RegionPtr(ireg)->result;
                    count c;
                    for( c = 0; c < t->ncomp; ++c )
                      totals[c].spreadsq += Sq(result[c].spread);
                  }

                  nnew = (tot->spreadsq/Sq(MARKMASK) > tot->maxerrsq) ?
                    MARKMASK :
                    (number)ceil(sqrt(tot->spreadsq/tot->maxerrsq));
                  if( nnew > nwant + nwant/64 ) {
                    ccount err = SamplesLookup(t, &t->samples[1], t->key2, nnew,
                      (t->maxeval - t->neval)/t->nregions + 1, t->samples[1].n);
                    fail += Unmark(err)*t->nregions;
                    nwant = nnew;
                    SamplesFree(&t->samples[1]);
                    SamplesAlloc(t, &t->samples[1]);

                    if( t->key2 > 0 && t->samples[1].neff >= MAXPRIME )
                      can_adjust = false;

                    if( VERBOSE > 2 ) {
                      char s[128];
                      sprintf(s, "Sampling remaining " COUNT
                        " regions with " NUMBER " points per region.",
                        t->nregions, t->samples[1].neff);
                      Print(s);
                    }
                  }
                }

                goto refine;
              }
              todo |= 3;
            }
            todo |= 1;
          }
        }
      }

      if( can_adjust ) {
        for( comp = 0; comp < t->ncomp; ++comp )
          totals[comp].maxerrsq -=
            Sq(region->result[comp].spread*t->samples[1].weight);
      }

      switch( todo ) {
      case 1:	/* get spread right */
        Explore(t, iregion, &t->samples[1], 0, 2);
        break;

      case 3:	/* sample region again with more points */
        if( SamplesIniQ(&t->samples[2]) ) {
          SamplesLookup(t, &t->samples[2], t->key3,
            nwant, (number)INT_MAX, (number)0);
          SamplesAlloc(t, &t->samples[2]);
        }
        t->phase = 3;
        t->samples[2].sampler(t, &t->samples[2], region->bounds, region->vol);
        Explore(t, iregion, &t->samples[2], 0, 2);
        ++region->depth;	/* misused for df here */
        ++df;
      }

      ++region->depth;	/* misused for df here */

      if( VERBOSE > 2 ) {
        for( dim = 0; dim < t->ndim; ++dim ) {
          cBounds *b = &region->bounds[dim];
          p += sprintf(p,
            (dim == 0) ? "\nRegion (" REALF ") - (" REALF ")" :
                         "\n       (" REALF ") - (" REALF ")",
            b->lower, b->upper);
        }
      }

      for( comp = 0; comp < t->ncomp; ++comp ) {
        Result *r = &region->result[comp];

        creal x1 = t->samples[0].avg[comp];
        creal s1 = Var(t->samples[0]);
        creal x2 = t->samples[1].avg[comp];
        creal s2 = Var(t->samples[1]);
        creal r2 = (s1 == 0) ? Sq(t->samples[1].neff*t->samples[0].weight) : s2/s1;

        real norm = 1 + r2;
        real avg = x2 + r2*x1;
        real sigsq = s2;
        real chisq = Sq(x2 - x1);
        real chiden = s1 + s2;

        if( todo == 3 ) {
          creal x3 = t->samples[2].avg[comp];
          creal s3 = Var(t->samples[2]);
          creal r3 = (s2 == 0) ? Sq(t->samples[2].neff*t->samples[1].weight) : s3/s2;

          norm = 1 + r3*norm;
          avg = x3 + r3*avg;
          sigsq = s3;
          chisq = s1*Sq(x3 - x2) + s2*Sq(x3 - x1) + s3*chisq;
          chiden = s1*s2 + s3*chiden;
        }

        avg = LAST ? r->avg : (sigsq *= norm = 1/norm, avg*norm);
        if( chisq > EPS ) chisq /= Max(chiden, NOTZERO);

#define Out(s) s.avg[comp], r->spread*s.weight, s.err[comp]

        if( VERBOSE > 2 ) {
          p += sprintf(p, "\n[" COUNT "] "
            REAL " +- " REAL "(" REAL ")\n    "
            REAL " +- " REAL "(" REAL ")",
            comp + 1, Out(t->samples[0]), Out(t->samples[1]));
          if( todo == 3 ) p += sprintf(p, "\n    "
            REAL " +- " REAL "(" REAL ")",
            Out(t->samples[2]));
          p += sprintf(p, "  \tchisq " REAL, chisq);
        }

        integral[comp] += avg;
        error[comp] += sigsq;
        prob[comp] += chisq;

        r->avg = avg;
        r->spread = sqrt(sigsq);
        r->chisq = chisq;
      }

      if( VERBOSE > 2 ) Print(s);
    }

    for( comp = 0; comp < t->ncomp; ++comp )
      error[comp] = sqrt(error[comp]);

    df += t->nregions;

    if( VERBOSE > 2 ) {
      char s[16 + 128*NCOMP], *p = s;

      p += sprintf(p, "\nTotals:");

      for( comp = 0; comp < t->ncomp; ++comp )
        p += sprintf(p, "\n[" COUNT "] "
          REAL " +- " REAL "  \tchisq " REAL " (" COUNT " df)",
          comp + 1, integral[comp], error[comp], prob[comp], df);

      Print(s);
    }

    for( comp = 0; comp < t->ncomp; ++comp )
      prob[comp] = ChiSquare(prob[comp], df);

    weight = 1;
  }

#ifdef MLVERSION
  if( REGIONS ) {
    MLPutFunction(stdlink, "List", 2);
    MLPutFunction(stdlink, "List", t->nregions);
    for( iregion = 0; iregion < t->nregions; ++iregion ) {
      Region *region = RegionPtr(iregion);
      cBounds *b = region->bounds;
      real lower[NDIM], upper[NDIM];

      for( dim = 0; dim < t->ndim; ++dim ) {
        lower[dim] = b[dim].lower;
        upper[dim] = b[dim].upper;
      }

      MLPutFunction(stdlink, "Cuba`Divonne`region", 4);

      MLPutRealList(stdlink, lower, t->ndim);
      MLPutRealList(stdlink, upper, t->ndim);

      MLPutFunction(stdlink, "List", t->ncomp);
      for( comp = 0; comp < t->ncomp; ++comp ) {
        cResult *r = &region->result[comp];
        real res[] = {r->avg, r->spread*weight, r->chisq};
        MLPutRealList(stdlink, res, Elements(res));
      }

      MLPutInteger(stdlink, region->depth);  /* misused for df */
    }
  }
#endif

abort:
  SamplesFree(&t->samples[2]);
  SamplesFree(&t->samples[1]);
  SamplesFree(&t->samples[0]);
  RuleFree(&t->rule13);
  RuleFree(&t->rule11);
  RuleFree(&t->rule9);
  RuleFree(&t->rule7);

  free(t->voidregion);

  return fail;
}
Beispiel #18
0
int EList::Unmark() {
    if (Count > 0 && IsMarked(Row) && Unmark(Row) == 1) {
        NeedsRedraw = 1;
        return ErOK;
    } else return ErFAIL;
}
Beispiel #19
0
static AddError()
{
    a_sym *xsym, *sym;
    a_pro *xpro, *pro;
    a_state *x, **s, **t, *AddErrState();
    a_shift_action *tx, *ty, *trans;
    a_reduce_action *rx, *ry, *redun;
    int i;
    a_word *defined, *conflict, *rset;
    short int *at;

    trans = CALLOC( nsym, a_shift_action );
    rx = redun = CALLOC( npro + 1, a_reduce_action );
    rset = conflict = AllocSet( npro + 2 );
    for( i = 0; i <= npro; ++i ) {
        (rx++)->follow = rset;
        rset += GetSetSize( 1 );
    }
    defined = rset;
    s = CALLOC( nstate, a_state * );
    at = CALLOC( nstate, short int );
    s = t = CALLOC( nstate + 1, a_state * );
    for( x = statelist; x != NULL; x = x->next ) {
         Mark( *x );
         *t++ = x;
    }
    restart = AddErrState( &errsym->enter, s, t );
    for( x = restart; x != NULL; x = x->next ) {
        Clear( defined );
        Clear( conflict );
        xpro = NULL;
        for( i = 0; i < x->kersize; ++i ) {
            at[i] = 0;
            pro = x->name.state[i]->redun->pro;
            if( pro > xpro ) {
                xpro = pro;
            }
        }
        redun->pro = errpro;
        rx = redun + 1;
        if( x != restart )
            while( xpro ) {
                pro = xpro;
                xpro = NULL;
                Clear( rx->follow );
                for( i = 0; i < x->kersize; ++i ) {
                    ry = &x->name.state[i]->redun[at[i]];
                    if( ry->pro == pro ) {
                        Union( rx->follow, ry->follow );
                        ++(at[i]);
                        ++ry;
                    }
                    if( ry->pro > xpro ) {
                        xpro = ry->pro;
                    }
                }
                UnionAnd( conflict, rx->follow, defined );
                Union( defined, rx->follow );
                rx->pro = pro;
                ++rx;
            }
        xsym = NULL;
        for( i = 0; i < x->kersize; ++i ) {
            at[i] = 0;
            sym = x->name.state[i]->trans->sym;
            if( sym > xsym ) {
                xsym = sym;
            }
        }
        tx = trans;
        while( xsym ) {
            sym = xsym;
            xsym = NULL;
            t = s;
            for( i = 0; i < x->kersize; ++i ) {
                ty = &x->name.state[i]->trans[at[i]];
                if( ty->sym == sym ) {
                    if( !IsMarked( *ty->state ) ) {
                        Mark( *ty->state );
                        *t++ = ty->state;
                    }
                    ++(at[i]);
                    ++ty;
                }
                if( ty->sym > xsym ) {
                    xsym = ty->sym;
                }
            }
            tx->sym = sym;
            if( sym->pro != NULL ) {
                ++nvtrans;
            } else {
                if( IsBitSet( defined, sym->id ) ) {
                    SetBit( conflict, sym->id );
                    while( --t >= s ) {
                        Unmark( **t );
                    }
                    continue;
                } else {
                    SetBit( defined, sym->id );
                }
            }
            tx->state = AddErrState( &errsym->enter, s, t );
            ++tx;
        }
        x->trans = CALLOC( tx - trans + 1, a_shift_action );
        memcpy( x->trans, trans, ((char *) tx) - ((char *) trans) );
        if( Empty( conflict ) ) {
            redun->pro = NULL;
            i = 0;
        } else {
            i = 1;
        }
        while( --rx > redun ) {
            AndNot( rx->follow, conflict );
            if( Empty( rx->follow ) ) {
                rx->pro = NULL;
            } else {
                ++i;
            }
        }
        x->redun = CALLOC( i + 1, a_reduce_action );
        if( i ) {
            rset = AllocSet( i );
            rx = redun;
            while( i > 0 ) {
                if( rx->pro != NULL ) {
                    --i;
                    x->redun[i].pro = rx->pro;
                    x->redun[i].follow = rset;
                    Assign( rset, rx->follow );
                    rset += GetSetSize( 1 );
                }
                ++rx;
            }
        }
    }
    FREE( trans );
    FREE( redun );
    FREE( conflict );
    FREE( s );
    FREE( at );
}
Beispiel #20
0
// update the lines instance variables, determining if there have
// been any changes in the line
void scTextline::Set( short 			lineCount,
					  eBreakType		breakType,
					  scLINERefData&	lineData )
{
	BOOL	changed;
	scXRect exrect = lineData.fInkExtents;
	
	scAssert( lineData.fInkExtents.Valid() );
	
	TypeSpec ts = lineData.GetMaxLeadSpec();
	scCachedStyle& cs = scCachedStyle::GetCachedStyle( ts );

	if ( fOrigin == lineData.fOrg
			&& fLength					== lineData.fComputedLen
			&& GetCharCount()			== lineData.GetCharCount()
			&& fLineCount				== lineCount
			&& fLspAdjustment			== lineData.fLetterSpace
			&& fInkExtents				== lineData.fInkExtents
			&& Marked( scLASTLINE ) 	&& ( breakType == eEndStreamBreak ) 
			&& fMaxLead 				== lineData.fEndLead.GetLead()
			&& fMaxLeadSpec 			== lineData.GetMaxLeadSpec() ) {
				changed = false;
	}
	else
		changed = true;


	if ( !changed ) {
		if ( fColumn->GetFlowdir().IsVertical() ) {
			changed = ( fCursorY1 == lineData.fOrg.x + cs.GetCursorX1() )		&& 
						( fCursorY2 == lineData.fOrg.x + cs.GetCursorX2() );
		}
		else {
			changed = ( fCursorY1 == lineData.fOrg.y + cs.GetCursorY1() )		&& 
						( fCursorY2 == lineData.fOrg.y + cs.GetCursorY2() );
		}
	}

	SetOffsets( lineData.GetStartCharOffset(), lineData.GetEndCharOffset() );
	if ( changed ) {
		fOrigin 			= lineData.fOrg;
		fVJOffset			= 0;
		fLength 			= lineData.fComputedLen;
		fLineCount			= lineCount;
		if ( breakType == eEndStreamBreak )
			Mark( scLASTLINE );
		else
			Unmark( scLASTLINE );
		fLspAdjustment		= lineData.fLetterSpace;
		fInkExtents 		= lineData.fInkExtents;
		fMaxLead			= lineData.fEndLead.GetLead();
		fMaxLeadSpec		= lineData.GetMaxLeadSpec();		// fMaxLeadSpec
		
		
		if ( fColumn->GetFlowdir().IsVertical() ) {
			fCursorY1			= lineData.fOrg.x + cs.GetCursorX1();
			fCursorY2			= lineData.fOrg.x + cs.GetCursorX2();
			lineData.fInkExtents.x1 = fCursorY1;
			lineData.fInkExtents.x2 = fCursorY2;
			if ( !lineData.GetStartCharOffset() && scCachedStyle::GetParaStyle().GetNumbered() )
				lineData.fInkExtents.y1 -= scCachedStyle::GetParaStyle().GetBulletIndent();
		}
		else {
			fCursorY1			= lineData.fOrg.y + cs.GetCursorY1();
			fCursorY2			= lineData.fOrg.y + cs.GetCursorY2();
			lineData.fInkExtents.y1 = fCursorY1;
			lineData.fInkExtents.y2 = fCursorY2;
			if ( !lineData.GetStartCharOffset() && scCachedStyle::GetParaStyle().GetNumbered() )
				lineData.fInkExtents.x1 -= scCachedStyle::GetParaStyle().GetBulletIndent();

		}
		fInkExtents.Union( lineData.fInkExtents );
	}

	if ( fColumn->GetFlowdir().IsVertical() && lineData.fColShapeType & eVertFlex )
		SetFlexLineAdjustment( lineData.fRagSetting );		
	else if ( lineData.fColShapeType & eHorzFlex )
		SetFlexLineAdjustment( lineData.fRagSetting );
	else
		SetFlexLineAdjustment( eNoRag );

	lineData.fLastLineLen = lineData.fComputedLen;

	if ( changed )
		fColumn->Mark( scREPAINT );

	scAssertValid( false );
}
void RangeDrawer::ToggleMarked(const int &x, const int &y) {
    marked[y][x] ? Unmark(x, y) : Mark(x, y);
}
void RangeDrawer::UnmarkTerrainCoord(const float &tx, const float &ty) {
    Unmark( TerrainX2QuadX(tx), TerrainY2QuadY(ty) );
}