Exemple #1
0
bool evaluate_unary_operator(const object& operator_object,bool expand = true)
{
    object result, arg;
    bool eval = true;

    if(optic_stack.size())
    {
        eval = evaluate_top();

        if(eval)
        {
            arg = optic_stack.back();
            optic_stack.pop_back();

            if(arg.type == ARRAY && expand)
            {
                object new_array = mem_alloc(ARRAY);

                for(int i = 0; i < arg.data.array->size(); ++i)
                {
//                    optic_stack.push_back(mem_copy(arg.data.array->at(i)));
                    optic_stack.push_back(arg.data.array->at(i));
                    optic_stack.push_back(operator_object);

                    if(evaluate_top())
                    {
                        new_array.data.array->push_back(mem_copy(optic_stack.back()));
                        optic_stack.pop_back();
                    }

                }

                result = new_array;
            }

            else
            {
                operator_object.data.unary_operator_func(result, arg);
            }

//            mem_free(arg);
            optic_stack.push_back(result);
            return true;
        }
    }

    else
    {
        eval = false;
    }

    if(!eval)
    {
        mem_free(arg);
        out() << "Missing argument for unary operator" << std::endl;
        clear_stack();
        return false;
    }
}
 static void unwindTokens(std::deque<int>& queue, int tok) {
   assert(!queue.empty() && "Token stack is empty!");
   while (queue.back() != tok) {
     queue.pop_back();
     assert(!queue.empty() && "Token stack is empty!");
   }
   queue.pop_back();
 }
 void push(int x) {
   while(!stackB.empty()){
     stackA.push_back(stackB.back());
     stackB.pop_back();
   }
   stackA.push_back(x);
   while(!stackA.empty()){
     stackB.push_back(stackA.back());
     stackA.pop_back();
   }
 }
Exemple #4
0
int main(){
	//freopen("sun.in","r",stdin);
	//freopen("sun.out","w",stdout);
	scanf("%d",&n);
	scanf("%s",s);
	for (int i = 0; i < n; ++i){
		q.push_back(s[i]);
	}
	while(!q.empty()){
		if(q.front()<q.back()){
			putchar(q.front());
			q.pop_front();
		}else if(q.front()>q.back()){
			putchar(q.back());
			q.pop_back();
		}else{
			if(q.size()==1){
				putchar(q.front());
				break;
			}
			while(q.front()==q.back() && q.size()!=1){
				lq.push_back(q.front());
				rq.push_back(q.front());
				if(q.front()>q.back()){
					while(!rq.empty()){
						putchar(rq.front());
						rq.pop_front();
					}
					putchar(q.back());
					q.pop_back();
					while(!lq.empty()){
						q.push_front(lq.back());
						lq.pop_back();
					}
				}else{
					while(!rq.empty()){
						putchar(rq.front());
						rq.pop_front();
					}
					putchar(q.back());
					q.pop_front();
					while(!lq.empty()){
						q.push_back(lq.back());
						lq.pop_back();
					}
				}
			}

			
		}
	}
	putchar('\n');
	return 0;
}
Exemple #5
0
static void align_back(const std::deque<timestamp_t> &reference,
                       std::deque<timestamp_t> &target,
                       std::deque<vec3_t> &data) {
  const auto back = reference.back();
  while (true) {
    if (target.back() > back) {
      target.pop_back();
      data.pop_back();
    } else {
      break;
    }
  }
}
JNIEXPORT jchar JNICALL
Java_link_kjr_SimpleTerminal_MainActivity_get_1char__(JNIEnv *env, jclass type) {
    char f=buffer.back();
    buffer.pop_back();
    return (jchar) f;

}
 int qread() {
   if (m_deq.empty())
     return super_t::read();
   unsigned char c = m_deq.back();
   m_deq.pop_back();
   return c;
 }
Exemple #8
0
int main() {
    while (~scanf("%d %d", &n, &m)) {
        init(n);
        for (int i = 1; i <= n; ++i) {
            scanf("%I64d", s + i);
            s[i] += s[i - 1];
        }
        dp[1] = s[1] * s[1] + m;
        q.push_back(0);
        for (int i = 1; i <= n; ++i) {
            while (q.size() >= 2 && Up(q[1], q.front()) <= s[i] * Down(q[1], q.front())) {
                // printf("  %d\n", q[1]);
                // printf("--- %I64d %d\n", dp[i], q.size());
                q.pop_front();
            }
            if (!q.empty())
                Dp(i, q.front());
            // printf("%I64d %d\n", dp[i], q.size());
            while (q.size() >= 2 /*&& 1, printf("--- %I64d %d\n *** %I64d %I64d\n", dp[i], q.back(), Up(i, q.back()) * Down(q.back(), q[q.size() - 2]), Up(q.back(), q[q.size() - 2]) * Down(i, q.back())) */&& Up(i, q.back()) * Down(q.back(), q[q.size() - 2]) <= Up(q.back(), q[q.size() - 2]) * Down(i, q.back())) {
                // ;
                // printf("  %d\n", q[1]);
                q.pop_back();
            }
            q.push_back(i);
                // printf("  %d\n", q.size());
        }
        printf("%I64d\n", dp[n]);
    }
}
void dijkstra_LIFO_thread(CSRGraph *g, int *dist, std::deque<int> &deq, int threadNum, int *onstack, std::mutex *dist_locks)
{
    while(!deq.empty())
    {
        queue_lock.lock();

        if(deq.empty()){
            queue_lock.unlock();
            break;
        }

        int u = deq.back();
        deq.pop_back();
	
    printf("Popped\n");
    for(int i=0; i< deq.size();i++){
	printf(" %d", deq[i]);
    }
    printf("\n");
        onstack[u]=0;

        int udist = dist[u];
        queue_lock.unlock();

        std::vector<int> neighbors = CSRGraph_getNeighbors(g, u);
        int neighbor;
        for(neighbor=0;neighbor < neighbors.size(); neighbor++)
        {
            int v = neighbors[neighbor];
            int uvdist = CSRGraph_getDistance(g, u, v);
            int alt = udist + uvdist;

            dist_locks[v].lock();
            if(alt < dist[v])
            {
                dist[v] = alt;
                dist_locks[v].unlock();

                queue_lock.lock();                
                if(onstack[v] == 0) 
                {
                    deq.push_back(v);
		    
    printf("Pushed\n");
    for(int i=0; i< deq.size();i++){
	printf(" %d", deq[i]);
    }
    printf("\n");
                    onstack[v]=1;
                }
                queue_lock.unlock();                    
            }
            else
            {
                dist_locks[v].unlock();
            }
        }
    }
    //printf("Thread %d ended.\n", threadNum);
}
Exemple #10
0
			value_type dequeBack()
			{
				libmaus2::parallel::ScopePosixSpinLock llock(lock);
				value_type const v = Q.back();
				Q.pop_back();
				return v;
			}
int maximumContiguousSum(std::deque<int> &numbers) {
  int max = 0;
  std::deque<int>::iterator boundary;
  std::deque<int>::iterator adder;
  while (numbers.size() > 0) {
    for (boundary = numbers.end(); boundary != numbers.begin(); boundary--) {
      int testSum = 0;
      for (adder = numbers.begin(); adder != boundary; adder++) {
        testSum += *adder; 
      }
      if (testSum > max) { max = testSum; }
    }
    for (boundary = numbers.begin(); boundary != numbers.end(); boundary++) {
      int testSum = 0;
      for (adder = boundary; adder != numbers.end(); adder++) {
        testSum += *adder;
      }
      if (testSum > max) { max = testSum; }
    }
    if (!numbers.empty()) { numbers.pop_back(); }
    if (!numbers.empty()) { numbers.pop_front(); }
    if (numbers.size() == 1) {
      if (numbers.at(0) > max) { max = numbers.at(0); }
    }
  }
  return max;
}
Exemple #12
0
static inline void propagate_age_update(Cfg& conf, std::deque<Cfg>& tmpres, std::size_t dst) {
	// here we propagate an age field update to all pointers that are equal
	// and thus experience the update too => only for age updates of next fields

	// split to find truly equal pointers
	auto shape_split = disambiguate(*conf.shape, dst);

	for (Shape* s : shape_split) {
		tmpres.emplace_back(Cfg(conf, s));
		Cfg& config = tmpres.back();

		// pointer equal to dst => experiences age update too
		for (std::size_t i = 0; i < s->size(); i++) {
			if (i == dst) continue;
			if (s->test(i, dst, EQ)) {
				#if CAS_OVERAPPROXIMATE_AGE_PROPAGATION
					// overapproximation: drop age relation of pointers that observe the age assignemnt
					for (std::size_t j = 0; j < s->size(); j++)
						for (bool b : {false, true})
							config.ages->set(j, b, i, true, AgeRel::BOT);
				#else
					mk_next_age_equal(config, i, dst, true);
				#endif
			}
		}
	}

	// the shape/ages from conf may no longer be valid => overwrite the shape/ages
	conf.shape = std::move(tmpres.back().shape);
	conf.ages = std::move(tmpres.back().ages);
	tmpres.pop_back();
}
Exemple #13
0
void hier_pop_mat()
{
    if (!matrix_stack.empty())
    {
        current_mat=matrix_stack.back();
        matrix_stack.pop_back();
    }
}
Exemple #14
0
 // set key and value
 size_t set(const Key& k, const Value&& v) {
   if( data_.count(k) ) return data_.size();
   cache_.push_back(k);
   while (!max_cache_.empty() && max_cache_.back() < k) max_cache_.pop_back();
   max_cache_.push_back(k);
   data_[k] = std::move(v);
   return data_.size();
 }
void LineRenderingSampleApp::mouseDrag(MouseEvent event)
{
    mMousePositions.push_front(vec3(event.getPos(), 0.0f));
    if (mMousePositions.size() > mMaxMousePositions)
    {
        mMousePositions.pop_back();
    }
}
Exemple #16
0
 // pop element out of the stack and return its value
 T pop () {
     if (c.empty()) {
         throw ReadEmptyStack();
     }
     T elem(c.back());
     c.pop_back();
     return elem;
 }
Exemple #17
0
std::shared_ptr<std::vector<unsigned char> > getbuffer() {
	if(free_buffers.empty()) return std::make_shared<std::vector<unsigned char> >();
	else {
		std::shared_ptr<std::vector<unsigned char> > buffer = std::move(free_buffers.back());
		free_buffers.pop_back();
		return std::move(buffer);
	}
}
Exemple #18
0
void FinishNow() {
	if (stack.empty()) {
		current = nullptr; // TODO: Exit
	} else {
		current = stack.back();
		stack.pop_back();
		current->showLayers();
	}
}
Exemple #19
0
 bool try_pop_tail(T &value) {
     std::lock_guard<std::mutex> _lk(_m);
     if (_data.empty()) {
         return false;
     }
     value = std::move(_data.back());
     _data.pop_back();
     return true;
 }
Exemple #20
0
void proc_pop_interactive()
{
    ASSERT_IS_MAIN_THREAD();
	int old = is_interactive;
	is_interactive= interactive_stack.back();
    interactive_stack.pop_back();
	if( is_interactive != old )
		signal_set_handlers();
}
Exemple #21
0
void clear_stack()
{
    while(optic_stack.size())
    {
        optic_stack.pop_back();
    }

    global_state.type = NIL;
    correct_parsing = false;
}
Exemple #22
0
void writeSystemLog( std::string text )
{
   if (text.size() > system_log_width)
      text.resize( system_log_width );
   system_log.push_front( text );
   system_log_scroll = 0;

   if (system_log.size() > system_log_memory)
      system_log.pop_back();
}
Exemple #23
0
int find_num_pairs()
{
	unsigned int highest_Local_Key=0;
	unsigned int sum1=0;
	unsigned int sum2=0;
	if (exhibits.size()<=1)
	{
		return num_pairs;
	}
	    unsigned int val_END = exhibits.back();
		exhibits.pop_back();
		unsigned int val_BEFORE_END = exhibits.back();
		exhibits.pop_back();
		
		reverse_occurences[val_END]++;
		//find number of keys in my_freq_map that are lesser than forward occurence of this value
		//iterate through them and find the number of pairs
		if ((forward_occurences[val_BEFORE_END] - reverse_occurences[val_BEFORE_END])>reverse_occurences[val_END])
		{
			num_pairs = num_pairs + 1;
		}

		typedef std::map<unsigned int,unsigned int>::iterator it_type;
			for(it_type iterator = my_freq_map.begin(); iterator != my_freq_map.end(); iterator++)
			{
				if ((forward_occurences[val_END]-reverse_occurences[val_END]+1)>iterator->first)
				{
					sum1 = sum1+iterator->second;
				}
				if ((forward_occurences[val_BEFORE_END]-reverse_occurences[val_BEFORE_END])>iterator->first)
				{
					sum2 = sum2+iterator->second;
				}
			}
			num_pairs = num_pairs+sum1+sum2;

			
			reverse_occurences[val_BEFORE_END]++;
			my_freq_map[reverse_occurences[val_END]]++;
			my_freq_map[reverse_occurences[val_BEFORE_END]]++;
			find_num_pairs();
			return num_pairs;
}
Exemple #24
0
		void PopState()
		{
			if (stateStack.empty())
			{
				std::cout << "[VFS] Error: attempted to pop with an empty stack" << std::endl;
				return;
			}
			mounts = stateStack.back();
			stateStack.pop_back();
		}
Exemple #25
0
 T get() {
   std::unique_lock<std::mutex> lck(_mutex);
   while (!done && _queue.empty())
     _cond.wait(lck);
   if (done)
     throw std::exception();
   T msg = _queue.back();
   _queue.pop_back();
   return msg;
 }
Exemple #26
0
int main()
{	
	int i=0,N=0;
	unsigned int value_End=0,value_BeforeEnd=0,input=0;
	std::string line;

	//parse the input N first
	getline(std::cin,line);
	std::istringstream iss(line); 
	iss>>N;

	///get the next line
	std::string line2;
	getline(std::cin,line2);
	std::istringstream iss2(line2);
	for (int i=0;i<N;i++)
	{ 
		iss2>>input;
		exhibits.push_back(input);
		//arrange these in a map to get the occurence of these exhibits when going from east to west.
		forward_occurences[input]++;
	}
		
		//pop two values out and perform the last pair before starting divide and conquer recursion
	    value_End = exhibits.back();
		exhibits.pop_back();
		value_BeforeEnd = exhibits.back();
		exhibits.pop_back();
		reverse_occurences[value_End]++;
		my_freq_map[reverse_occurences[value_End]]++;
		reverse_occurences[value_BeforeEnd]++;
		my_freq_map[reverse_occurences[value_BeforeEnd]]++;
		
		//std::cout<<reverse_occurences[value]<<std::endl;
		if (forward_occurences[value_BeforeEnd]>reverse_occurences[value_End])
		{
			num_pairs = num_pairs + 1;
		}
		num_pairs = find_num_pairs();

	std::cout<<num_pairs<<std::endl;
	return 0;
}
Exemple #27
0
void DispatchEvents() {
	lock_guard guard(mutex_);

	while (!g_dispatchQueue.empty()) {
		DispatchQueueItem item = g_dispatchQueue.back();
		g_dispatchQueue.pop_back();
		if (item.e) {
			item.e->Dispatch(item.params);
		}
	}
}
Exemple #28
0
void RequestHandler::event_dispatch_thread() {

	// register a name
	std::stringstream namestr;
	namestr << "windowserver:event-dispatcher";
	g_task_register_id(namestr.str().c_str());

	while (true) {
		// wait for events
		g_atomic_block(&event_dispatch_events_empty);

		// lock
		g_atomic_lock(&sending_locked);

		// call listener
		UIEventDispatchData ldata = event_dispatch_queue.back();
		event_dispatch_queue.pop_back();

		// write transaction id
		uint32_t idlen = sizeof(g_ui_transaction_id);
		uint8_t idbytes[idlen];
		*((g_ui_transaction_id*) idbytes) = 0;
		g_write(ldata.output, idbytes, idlen);

		// write length
		uint32_t lenlen = sizeof(uint32_t);
		uint8_t lenbytes[lenlen];
		*((uint32_t*) lenbytes) = ldata.length + 4;
		g_write(ldata.output, lenbytes, lenlen);

		// write listener id
		uint32_t lidlen = sizeof(uint32_t);
		uint8_t lidbytes[lidlen];
		*((uint32_t*) lidbytes) = ldata.listener;
		g_write(ldata.output, lidbytes, lidlen);

		// write data
		uint32_t written = 0;
		while (written < ldata.length) {
			written += g_write(ldata.output, &ldata.data[written], ldata.length - written);
		}

		// delete the data
		delete ldata.data;

		// check if empty
		if (event_dispatch_queue.empty()) {
			event_dispatch_events_empty = true;
		}

		// unlock
		sending_locked = false;
	}
}
Exemple #29
0
/** Return a queued buffer if there are enough
 * to spare
 */
AsynchIO::BufferBase* AsynchIO::getQueuedBuffer() {
    // Always keep at least one buffer (it might have data that was "unread" in it)
    if (bufferQueue.size()<=1)
        return 0;
    BufferBase* buff = bufferQueue.back();
    assert(buff);
    buff->dataStart = 0;
    buff->dataCount = 0;
    bufferQueue.pop_back();
    return buff;
}
Exemple #30
0
 virtual void visit(BinaryFunction* b)
 {
     if(!defined) return;
     long arg1 = results.back();
     results.pop_back();
     long arg2 = results.back();
     results.pop_back();
     if(b->isAdd())
     {
         results.push_back(arg1+arg2);
     }
     else if(b->isMultiply())
     {
         results.push_back(arg1*arg2);
     }
     else
     {
         defined = false;
     }
 }