void CBasicBlocksBuilder::SortBlocks()
{
	assert( blocks.size() > 0 );
	std::vector<bool> used( blocks.size(), false );
	CBasicBlock currBlock = blocks[labelToBlock[firstLabel->label]];
	used[labelToBlock[firstLabel->label]] = true;
	sortedBlocks.push_back( currBlock );
	const IIRStm* jump = currBlock.Last();
	size_t numOfFreeBlocks = used.size() - 1;
	while( numOfFreeBlocks > 0 ) {
		if( IsInstanceOf<CIRJump>( const_cast< IIRStm* >( jump ) ) ) {
			// За ним просто должен идти блок с меткой, куда прыгаем
			const Temp::CLabel* nextLabel = getNextLabel( jump );
			if( nextLabel->Name() == "done_label" || used[labelToBlock[nextLabel]] ) {
				// Если блок конца фрейма, или же след ведет в посещенный блок
				// Значит нужно взять непосещенный и с ним строить след
				int position = 0;
				if( getNextFreeBlock( used, currBlock, position ) ) {
					sortedBlocks.push_back( currBlock );
					used[position] = true;
					--numOfFreeBlocks;
					jump = currBlock.Last();
					continue;
				} else {
					// Свободных блоков не осталось
					break;
				}
			}
			currBlock = blocks[labelToBlock[nextLabel]];
			sortedBlocks.push_back( currBlock );
			used[labelToBlock[nextLabel]] = true;
			--numOfFreeBlocks;
		} else if( IsInstanceOf<CIRCJump>( const_cast< IIRStm* >( jump ) ) ) {
			// За ним должен идти блок с меткой на false
			const Temp::CLabel* nextLabel = getNextConditionalLabel( jump );
			if( nextLabel->Name() == "done_label" || used[labelToBlock[nextLabel]] ) {
				int position = 0;
				if( getNextFreeBlock( used, currBlock, position ) ) {
					sortedBlocks.push_back( currBlock );
					used[position] = true;
					--numOfFreeBlocks;
					jump = currBlock.Last();
					continue;
				} else {
					// Свободных блоков не осталось
					break;
				}
			}
			currBlock = blocks[labelToBlock[nextLabel]];
			sortedBlocks.push_back( currBlock );
			used[labelToBlock[nextLabel]] = true;
			--numOfFreeBlocks;
		} else {
			assert( false );
		}
		jump = currBlock.Last();
	}
}
Ejemplo n.º 2
0
void outrumor()
{
    int rn;
    int i;
    FILE *rumf;

    if(n_rumors <= n_used_rumors) {
        return;
    }
    else {
        rumf = fopen(RUMORFILE, "r");

        if(rumf == NULL) {
            return;
        }
    }

    if(n_used_rumors < 0) {
        init_rumors(rumf);
    }

    if(n_rumors == 0) {
        fclose(rumf);
        
        return;
    }

    rn = rn2(n_rumors - n_used_rumors);
    i = 0;

    while((rn != 0) || (used(i) != 0)) {
        skipline(rumf);
        
        if(used(i) == 0) {
            --rn;
        }

        ++i;
    }

    usedbits[i / CHARSZ] |= (1 << (i % CHARSZ));
    ++n_used_rumors;
    outline(rumf);
    fclose(rumf);
}
Ejemplo n.º 3
0
int hd_open(uint8_t minor, uint16_t flag)
{
    used(flag);
    if(minor != 0) {
        udata.u_error = ENODEV;
        return -1;
    }
    return 0;
}
Ejemplo n.º 4
0
vector<vector<int> > permuteUniqueSub(vector<int> &num) {
    sort(num.begin(),num.end());//sort the original array.
    vector<bool> used(num.size(),false);
    vector<int> subans;
    vector<vector<int>> ans;
    permuteUniqueHelper(num,subans,used,ans);
    return ans;
    
}
Ejemplo n.º 5
0
 bool canPartitionKSubsets(vector<int>& nums, int k) {
     int n = nums.size();
     vector<bool> used(n, false);
     int sum = accumulate(nums.begin(), nums.end(), 0);
     if (sum % k != 0) {
         return false;
     }
     return canPartition(nums, used, 0, n, 0, sum / k, k);
 }
Ejemplo n.º 6
0
void HeapRegion::par_clear() {
  assert(used() == 0, "the region should have been already cleared");
  assert(capacity() == HeapRegion::GrainBytes, "should be back to normal");
  HeapRegionRemSet* hrrs = rem_set();
  hrrs->clear();
  CardTableModRefBS* ct_bs =
                   (CardTableModRefBS*)G1CollectedHeap::heap()->barrier_set();
  ct_bs->clear(MemRegion(bottom(), end()));
}
Ejemplo n.º 7
0
void Generation::print_on(outputStream* st)  const {
    st->print(" %-20s", name());
    st->print(" total " SIZE_FORMAT "K, used " SIZE_FORMAT "K",
              capacity()/K, used()/K);
    st->print_cr(" [" INTPTR_FORMAT ", " INTPTR_FORMAT ", " INTPTR_FORMAT ")",
                 _virtual_space.low_boundary(),
                 _virtual_space.high(),
                 _virtual_space.high_boundary());
}
Ejemplo n.º 8
0
 int totalNQueens(int n) {
     if (n < 1)
     	return 0;
     vector<int> usedRows(n, -1);
     vector<vector<bool> > used(n, vector<bool>(n, false));
     int num = 0;
     findNQueens(0, n, usedRows, used, num);
     return num;
 }
Ejemplo n.º 9
0
	void addImage(const DL_ImageData& image)
	{
		if (used()) {
			ImageHandle handle;
			handle.handle = m_output->writeImage(m_writer, image, getAttributes());
			handle.data = image;
			m_images[image.ref] = handle;
		}
	}
Ejemplo n.º 10
0
void Graph::LFRColoring()
{
    list<int> *adjacentNodes = Graph::adjacentNodes; //inicjalizacja lokalnej listy wezlow
    int uncolored=V; //zmienna sluzaca do okreslenia ile wezlow zostalo do pokolorowania
    int node; //wezel
    for (int u = 0; u<V; u++) {
        tmp.push_back(adjacentNodes[u].size()); //lista przechowujaca ilosc sasiadow kazdego z wezlow do pozniejszego wybrania
    }

    //ustawienie wszystkich wezlow jako niepokolorowane
    for (int u = 0; u < V; u++) {
        color.push_back(-1);
    }

    // Tymczasowa tablica sluzaca do ustalenia czy dany kolor
    // zostal uzyty do pokolorowania sasiedniego wezla
    vector<bool> used(V);
    for (int cr = 0; cr < V; cr++)
        used[cr] = false;

    // glowna petla algorytmu
    while (uncolored>0) {

        node = getTmp(); //wybor wezla

        list<int>::iterator i;

        for (i = adjacentNodes[node].begin(); i != adjacentNodes[node].end(); ++i) //iteracja po sasiednich wezlach
            if (color[*i] != -1) // czy kolor jest uzyty
                used[color[*i]] = true; // zaznacz uzyty kolor

        //wybierz pierwszy dostepny kolor
        int cr;
        for (cr = 0; cr < V; cr++)
            if (used[cr] == false)
                break;

        //przypisz pierwszy wolny kolor do wezla
        color[node] = cr;
        uncolored--;

        // zresetuj wartosci dla kolejnej iteracji
        for (i = adjacentNodes[node].begin(); i != adjacentNodes[node].end(); ++i)
            if (color[*i] != -1)
                used[color[*i]] = false;
    }

    //wypisz wartosci
    for (int u = 0; u < V; u++)
        std::cout << "Vertex " << u << " --->  Color "
                  << color[u] << std::endl;

    //wyczysc listy
    tmp.clear();
    color.clear();

}
Ejemplo n.º 11
0
	void addBlock(const DL_BlockData& block)
	{
		m_inBlock = true;
		m_blockName = block.name;
		
		if (m_blockMode && used()) {
			m_output->writeBlock(m_writer, block);
		}
	}
Ejemplo n.º 12
0
int lpr_open(uint8_t minor, uint16_t flag)
{
    used(flag);
    if (ubee_parallel != UBEE_PARALLEL_LPR || minor) {
        udata.u_error = ENODEV;
        return -1;
    }
    return 0;
}
Ejemplo n.º 13
0
 vector<vector<int>> permute(vector<int>& nums) {
     vector<vector<int>> result;
     vector<bool> used(nums.size(), false);
     vector<int> current;
     
     dfs(nums, used, current, result);
     
     return result;
 }
Ejemplo n.º 14
0
    /**
     * @param nums: A list of integers.
     * @return: A list of unique permutations.
     */
    vector<vector<int>> permuteUnique(vector<int> &nums) {
        vector<vector<int>> result;
        vector<bool> used(nums.size(), false);
        vector<int> ans;

        sort(nums.begin(), nums.end());
        permuteUniqueHelper(nums, &used, &ans, &result);
        return result;
    }
Ejemplo n.º 15
0
vector<string> PermutationSquareNum(int n) 
{
	vector<string> res;
	vector<bool> used(n, false);
	PermutationSquareNumRe(n, used, -1, 0, "", res);
	if(res.empty())
		res.push_back("");
	return res;
}
void UBGraphicsMediaItemDelegate::buildButtons()
{
    if(!mPlayPauseButton){
        mPlayPauseButton = new DelegateButton(":/images/play.svg", mDelegated, mToolBarItem, Qt::TitleBarArea);
        connect(mPlayPauseButton, SIGNAL(clicked(bool)),
                this, SLOT(togglePlayPause()));

        mStopButton = new DelegateButton(":/images/stop.svg", mDelegated, mToolBarItem, Qt::TitleBarArea);
        connect(mStopButton, SIGNAL(clicked(bool)),
                delegated(), SLOT(stop()));

        mMediaControl = new DelegateMediaControl(delegated(), mToolBarItem);
        mMediaControl->setFlag(QGraphicsItem::ItemIsSelectable, true);
        UBGraphicsItem::assignZValue(mMediaControl, delegated()->zValue());

        if (delegated()->isMuted())
            mMuteButton = new DelegateButton(":/images/soundOff.svg", mDelegated, mToolBarItem, Qt::TitleBarArea);
        else
            mMuteButton = new DelegateButton(":/images/soundOn.svg", mDelegated, mToolBarItem, Qt::TitleBarArea);

        connect(mMuteButton, SIGNAL(clicked(bool)),
                delegated(), SLOT(toggleMute()));
        connect(mMuteButton, SIGNAL(clicked(bool)),
                this, SLOT(toggleMute())); // for changing button image

        mToolBarButtons << mPlayPauseButton << mStopButton << mMuteButton;

        mToolBarItem->setItemsOnToolBar(QList<QGraphicsItem*>() << mPlayPauseButton << mStopButton << mMediaControl  << mMuteButton );
        mToolBarItem->setVisibleOnBoard(true);
        mToolBarItem->setShifting(false);

        if (!mToolBarShowTimer) {
            if (delegated()->hasLinkedImage()) {
                mToolBarShowTimer = new QTimer();
                mToolBarShowTimer->setInterval(m_iToolBarShowingInterval);
                connect(mToolBarShowTimer, SIGNAL(timeout()), this, SLOT(hideToolBar()));
            }
        }

        else {
            connect(mPlayPauseButton, SIGNAL(clicked(bool)),
                    mToolBarShowTimer, SLOT(start()));

            connect(mStopButton, SIGNAL(clicked(bool)),
                    mToolBarShowTimer, SLOT(start()));

            connect(mMediaControl, SIGNAL(used()),
                    mToolBarShowTimer, SLOT(start()));

            connect(mMuteButton, SIGNAL(clicked(bool)),
                    mToolBarShowTimer, SLOT(start()));
        }


        positionHandles();
    }
Ejemplo n.º 17
0
arg_t net_write(struct socket *s, uint8_t flag)
{
  uint16_t n = 0;

  used(s);
  used(flag);

  while(n < udata.u_count) {
    if (sockets[0].s_state == SS_CLOSED) {
      udata.u_error = EPIPE;
      ssig(udata.u_ptab, SIGPIPE);
      return -1;
    }
    /* FIXME - screen +++ handling ! */
    netat_outbyte(ugetc(udata.u_base++));
    n++;
  }
  return udata.u_count;
}
Ejemplo n.º 18
0
 vector<vector<int>> combinationSum3(int k, int n) {
     vector<vector<int>> res;
     if(n<=0 || n>45)
         return res;
     vector<int> temp;
     vector<bool> used(10,false);
     int start = 1;
     dfs(k,n,start,temp,used,res);
     return res;
 }
Ejemplo n.º 19
0
 vector<vector<int> > permuteUnique(vector<int> &num) {
     vector<vector<int> > result;
     if (num.empty())
         return result;
     sort(num.begin(), num.end());
     vector<bool> used(num.size(), false);
     vector<int> comb;
     findPermuteUnique(num, used, comb, result, 0, num.size());
     return result;
 }
Ejemplo n.º 20
0
int BrfData::GetFirstUnusedLetter() const{
  vector<bool> used(255,false);

  for (unsigned int i=0; i<mesh.size(); i++) {
    char let = mesh[i].name[4];
    used[let]=true;
  }
  for (char i='A'; i<'Z'; i++) if (!used[i]) return i-'A';
  return -1;
}
Ejemplo n.º 21
0
/* Flags is not used yet but will be needed (eg for swap scans) */
void blkdev_scan(blkdev_t *blk, uint8_t flags)
{
    uint8_t letter = 'a' + (blk - blkdev_table);

    used(flags); /* not used */

    blk_op.blkdev = blk;
    mbr_parse(letter);
    kputchar('\n');
}
Ejemplo n.º 22
0
/*
 *	Swap out process. As we have them all the same size we ignore
 *	p for now. For a single memory image system most of this can go!
 */
static ptptr swapvictim(ptptr p, int notself)
{
#ifdef CONFIG_MULTI
    ptptr c;
    ptptr r = NULL;
    ptptr f = NULL;
    uint16_t sc = 0;
    uint16_t s;

    extern ptptr getproc_nextp;	/* Eww.. */

    c = getproc_nextp;

    do {
        if (c->p_page) {	/* No point swapping someone in swap! */
            /* Find the last entry before us */
            if (c->p_status == P_READY)
                r = c;
            if (c->p_status > P_READY
                    && p->p_status <= P_FORKING) {
                /* relative position in order of waits, bigger is longer, can wrap but
                   shouldn't really matter to us much if it does */
                s = (waitno - c->p_waitno);
                if (s >= sc) {
                    sc = s;
                    f = c;
                }
            }
        }
        c++;
        if (c == ptab_end)
            c = ptab;
    }
    while (c != getproc_nextp);

    /* Oldest waiter gets the boot */
    if (f) {
#ifdef DEBUG
        kprintf("swapvictim %x (page %d, state %d\n)", f,
                f->p_page, f->p_status);
#endif
        return f;
    }
    /* No waiters.. the scheduler cycles so we will be the last to run
       again, failing that the one before us that was ready */
    if (notself == 0)
        return udata.u_ptab;
    return r;
#else
    used(p);
    if (notself)
        panic(PANIC_NOTSELF);
    return udata.u_ptab;
#endif
}
Ejemplo n.º 23
0
Archivo: tty.c Proyecto: aralbrec/FUZIX
int tty_write(uint8_t minor, uint8_t rawflag, uint8_t flag)
{
	struct tty *t;
	usize_t written = 0;
	uint8_t c;

	used(rawflag);
	used(flag);

	t = &ttydata[minor];

	while (udata.u_count-- != 0) {
		for (;;) {	/* Wait on the ^S/^Q flag */
		        if (t->flag & TTYF_DEAD) {
		                udata.u_error = ENXIO;
		                return -1;
                        }
			if (!(t->flag & TTYF_STOP))
				break;
			if (psleep_flags_io(&t->flag, flag, &written))
				return written;
                        jobcontrol_out(minor, t);
		}
		if (!(t->flag & TTYF_DISCARD)) {
			if (udata.u_sysio)
				c = *udata.u_base;
			else
				c = ugetc(udata.u_base);

			if (t->termios.c_oflag & OPOST) {
				if (c == '\n' && (t->termios.c_oflag & ONLCR))
					tty_putc_wait(minor, '\r');
				else if (c == '\r' && (t->termios.c_oflag & OCRNL))
					c = '\n';
			}
			tty_putc_wait(minor, c);
		}
		++udata.u_base;
		++written;
	}
	return written;
}
Ejemplo n.º 24
0
	void addHatch(const DL_HatchData& hatch)
	{
		if (used()) {
			m_output->writeHatch1(m_writer, hatch, getAttributes());
			m_currentHatch = hatch;
			m_hatchLoopsRemaining = hatch.numLoops;
			if (m_hatchLoopsRemaining == 0) {
				m_output->writeHatch2(m_writer, m_currentHatch, getAttributes());
			}
		}
	}
Ejemplo n.º 25
0
void DirectedGraph<T, MASK>::top_sort_rec(std::vector<size_t>* vertex_order) const {
	std::vector<bool> used(this->vertices_count_, false);
	std::vector<size_t> order;
	for (const size_t v : this->vertices()) {
		if (!used[v]) {
			top_sort_rec_impl(v, order, used);
		}
	}
	std::reverse(order.begin(), order.end());
	vertex_order->swap(order);
}
Ejemplo n.º 26
0
bool DefNewGeneration::collection_attempt_is_safe() {
  if (!to()->is_empty()) {
    log_trace(gc)(":: to is not empty ::");
    return false;
  }
  if (_old_gen == NULL) {
    GenCollectedHeap* gch = GenCollectedHeap::heap();
    _old_gen = gch->old_gen();
  }
  return _old_gen->promotion_attempt_is_safe(used());
}
Ejemplo n.º 27
0
 vector<vector<int> > permute(vector<int> &num) {
     // Start typing your C/C++ solution below
     // DO NOT write int main() function
     ret.clear();
     if(num.size()==0) return ret;
     vector<bool> used(num.size(),false);
     vector<int> path;
     path.clear();
     dfs(num,used,0,num.size(),path);
     return ret;
 }
Ejemplo n.º 28
0
 vector<vector<int> > permute(vector<int> &num) {
     // Start typing your C/C++ solution below
     // DO NOT write int main() function
     ret.clear();
     int len = num.size();
     if(!len)
         return ret;
     vector<bool> used(len, false);
     vector<int> path;
     dfs(num, 0, len, used, path);
     return ret;
 }
Ejemplo n.º 29
0
	bool areIsomorphic(const unique_ptr<DFSM>& fsm1, const unique_ptr<DFSM>& fsm2) {
		if (!fsm1->isReduced()) {
			fsm1->minimize();
		}
		if (!fsm2->isReduced()) {
			fsm2->minimize();
		}
		if ((fsm1->getNumberOfStates() != fsm2->getNumberOfStates()) ||
			(fsm1->getNumberOfInputs() != fsm2->getNumberOfInputs()) ||
			(fsm1->getNumberOfOutputs() != fsm2->getNumberOfOutputs()) ||
			(fsm1->getType() != fsm2->getType()) ||
			(fsm1->isOutputState() != fsm2->isOutputState()) ||
			(fsm1->isOutputTransition() != fsm2->isOutputTransition())) {
			return false;
		}
		vector<state_t> stateEq(fsm1->getNumberOfStates());
		vector<bool> used(fsm1->getNumberOfStates(), false);
		queue<state_t> fifo;

		stateEq[0] = 0;
		used[0] = true;
		fifo.emplace(0);
		while (!fifo.empty()) {
			auto state = fifo.front();
			fifo.pop();
			if (fsm1->isOutputState() && 
				(fsm1->getOutput(state, STOUT_INPUT) != fsm2->getOutput(stateEq[state], STOUT_INPUT))) {
				return false;
			}
			for (input_t input = 0; input < fsm1->getNumberOfInputs(); input++) {
				if (fsm1->isOutputTransition() && 
					(fsm1->getOutput(state, input) != fsm2->getOutput(stateEq[state], input))) {
					return false;
				}
				auto nextState1 = fsm1->getNextState(state, input);
				auto nextState2 = fsm2->getNextState(stateEq[state], input);
				if ((nextState1 == WRONG_STATE) || (nextState2 == WRONG_STATE)) {
					return false;
				} else if ((nextState1 == NULL_STATE) || (nextState2 == NULL_STATE)) {
					if (nextState1 != nextState2) return false;
				} else if (used[nextState1]) {
					if (stateEq[nextState1] != nextState2) {
						return false;
					}
				} else {
					stateEq[nextState1] = nextState2;
					used[nextState1] = true;
					fifo.emplace(nextState1);
				}
			}
		}
		return true;
	}
Ejemplo n.º 30
0
/**
 * Retrieve data and build internal representation.
 *
 * Given a series of haplogenotypes, for a given individual, calculate
 * the prob of each haplotype involved.
 *
 * The class variable matrix will be correctly filled with only those haplotypes that
 * have greater than 0.05 global frequency.  It will have been rescaled.
 * 
 * RTG updated Oct 14, 2010 to change the thresholding from 0.05% global expression
 * to showing up in at least n chromosomes (2m chr for m people).  Default is 20.
 *
 * @param input vector of EMPersonalProbsResults note that the person index is 0 based.
 * @param numHaps total number of haplotypes.
 * @param reweight If true, reweight the kept haplotypes.
 */
void Zaykin::setup(const vector<EMPersonalProbsResults> &input, int numHaps, bool reweight){

	if(phenotype.size() == 0){
		RunOrderException e;
		e.message = "Zaykin: called setup without setting a phenotype.";
		throw e;
	}

	vector<vector<double> > matrixT; // temp used internally.
	vector<int> used(numHaps, 0);
	
	matrixT = vecops::getDblVec(phenotype.size() , numHaps);

	for(unsigned int i=0; i < input.size(); ++i){
		double t2 = input.at(i).prob;
		if(isnan(t2)) t2 = 0;
		// compute the actual haplotype number
		// place half the percentage in that element in this individual.
		int ti = input.at(i).leftHap;
		matrixT.at(input.at(i).personId).at(ti) += t2 / 2;
		used.at(ti)++;
		ti = input.at(i).rightHap;
		matrixT.at(input.at(i).personId).at(ti) += t2 / 2;
		used.at(ti)++;
	}

	vector<unsigned int> keepIndices;
	usedHaplotype.clear();
	usedHaplotype.reserve(used.size());
	for(unsigned int i=0; i < used.size(); i++){
		
		if(used.at(i) > keepThresh){
			
			usedHaplotype.push_back(true);
			keepIndices.push_back(i);
		}else{
			
			usedHaplotype.push_back(false);
		}
	}

	matrix = vecops::getDblVec(phenotype.size() , keepIndices.size());
	for(unsigned int i=0;i < phenotype.size(); i++){
		
		for(unsigned int j=0;j < keepIndices.size(); j++){
			matrix.at(i).at(j) = matrixT.at(i).at(keepIndices.at(j));
		}
		if(reweight){
			double cumSum = vecops::vecCumSum(matrix.at(i));
			vecops::vecDiv(matrix.at(i) , cumSum);
		}
	}
}