예제 #1
0
void get(int k){
	termStack.sort(std::greater<node>());
	for(int i=0; i<k; i++){
		cout<<termStack.front().t<<endl;
		termStack.pop_front();
	}
}
예제 #2
0
std::forward_list<B> map (std::function<B(A)> f, const std::forward_list<A>& L) 
{
  std::forward_list<B> H;
  std::transform(L.begin(), L.end(), std::front_inserter(H), f);
  H.reverse();
  return H;
}
예제 #3
0
파일: fold.cpp 프로젝트: fons/presentations
U foldr_dest(std::function< U (U, T)>& op, const U& val, std::forward_list<T>& L)
{
  if (L.empty()) return U(val);
  T h = L.front();
  L.pop_front();
  return op (foldr(op, val, L),  h);
}
예제 #4
0
    static void extract(const jsonpack::value &v, char* json_ptr, std::forward_list<T> &value)
    {
        array_t arr = *v._arr;

        value.clear();

        for(const auto &it : arr)
        {
#ifndef _MSC_VER
            // Initialize before use
            T val = {};
#else
            T val;
#endif  
            if( json_traits<T&>::match_token_type(it) )
            {
                json_traits<T&>::extract(it, json_ptr, val);
                // forward_list not support insert operation
                value.push_front(val);
            }
            else
            {
                throw type_error( "Forward_list item type mismatch" );
            }

        }
    }
예제 #5
0
파일: main.cpp 프로젝트: YuryChebiryak/CCI
void removeDupsNoBuffer(std::forward_list<int>& l) {
    if (l.empty())
        return;
    auto backtrack = l.before_begin();
    while (std::next(backtrack) != l.end()) {
        // Iterate and print values of the list
        for (int n : l)
            std::cout << n << '\t';
        std::cout << std::endl;

        auto prev = std::next(backtrack);
        auto iter = std::next(prev);
        //std::cout << " prev =" << *prev << ", iter=" << *iter << std::endl;
        while (iter != l.end()) {
            if (*iter == *std::next(backtrack))
                iter = l.erase_after(prev);
            else {
                ++prev;
                ++iter;
            }
                
        }
        ++backtrack;
    }
}
예제 #6
0
파일: main.cpp 프로젝트: YuryChebiryak/CCI
void removeDups(std::forward_list<int>& l) {
    l.sort();
    for (int n : l)
        std::cout << n << '\t';
    std::cout << std::endl;
    l.unique();
}
예제 #7
0
typename boost::disable_if<
    typename detail::is_default_constructible<
        typename std::forward_list<T, Allocator>::value_type
    >,
    void
>::type
collection_load_impl(
    Archive & ar,
    std::forward_list<T, Allocator> &t,
    collection_size_type count,
    item_version_type item_version
){
    t.clear();
    boost::serialization::detail::stack_construct<Archive, T> u(ar, item_version);
    ar >> boost::serialization::make_nvp("item", u.reference());
    t.push_front(u.reference());
    typename std::forward_list<T, Allocator>::iterator last;
    last = t.begin();
    ar.reset_object_address(&(*t.begin()) , & u.reference());
    while(--count > 0){
        detail::stack_construct<Archive, T> u(ar, item_version);
        ar >> boost::serialization::make_nvp("item", u.reference());
        last = t.insert_after(last, u.reference());
        ar.reset_object_address(&(*last) , & u.reference());
    }
}
예제 #8
0
		void runDeferred(DeferredHandler f) {
			__EVENTEMITTER_LOCK_GUARD(mutex);
			auto it = deferredQueue.cbegin();
			auto prevIt = deferredQueue.cbefore_begin();
			for(; it != deferredQueue.cend(); prevIt = it, ++it);
			deferredQueue.emplace_after(prevIt, std::move(f));
		}
예제 #9
0
파일: signal.hpp 프로젝트: ftk/niceamx
  inline int operator () (EArgs&&... args) // O(n)
  {
    if(slots.empty())
      return default_return_value;
    auto it = slots.cbegin(), end = slots.cend();
    auto prev = slots.cbefore_begin();
    while(it != end)
    {
      try
      {
        (it->second)(std::forward<EArgs>(args)...);
        prev = it;
        ++it;
      }
      catch(slot_remove)
      {
        it = slots.erase_after(prev);
      }
      catch(signal_return e)
      {
        return e.get();
      }
    }

    return default_return_value;
  }
예제 #10
0
void AudioStreamingServer::SendMediaList(const std::shared_ptr<ISocket>& clientSocket, const std::string& keyword, const std::string& hostName) const {
    
    const std::forward_list<const std::string*> files = audioLibrary->Search(keyword);
    std::vector<std::string> urls;
    urls.reserve(std::distance(files.begin(), files.end()));
    
    int responseSize = 0;
    for(const std::string* file : files) {
        std::string encodedFile = urlCodec->EncodeURL(*file);
        std::string url;
        url.reserve(hostName.length() + encodedFile.length() + 9); //account 2 for '/', '\n' and 7 for 'http://'
        url += "http://";
        url += hostName;
        url += '/';
        url += encodedFile;
        url += '\n';
        responseSize += url.length();
        urls.push_back(std::move(url));
    }

    HttpResponse response(HTTP_1_1, OK, M3U, responseSize, keyword + ".m3u");
    SendResponseHeader(clientSocket, response);
    for(const std::string& url : urls) {
        clientSocket->Send(url.c_str(), url.size());
    }
}
예제 #11
0
std::forward_list<std::tuple<A,B>> zip (const std::forward_list<A>& L, const std::forward_list<B>& M) 
{
  std::forward_list<std::tuple<A,B>> H;
  auto zipper = [] (const A& a, const B& b) {return std::make_tuple(a,b);};
  std::transform(L.begin(), L.end(), M.begin(), std::front_inserter(H), zipper);
  H.reverse();
  return H;
}
예제 #12
0
void
TraialPool::return_traials(std::forward_list< Reference< Traial > >& list)
{
	for (auto it = list.begin() ; it != list.end() ; it = list.begin()) {
		available_traials_.push_front(*it);
		list.pop_front();  // 'it' got invalidated
	}
}
예제 #13
0
static int
fbsd_is_vfork_done_pending (pid_t pid)
{
  for (auto it = fbsd_pending_vfork_done.begin ();
       it != fbsd_pending_vfork_done.end (); it++)
    if (it->pid () == pid)
      return 1;
  return 0;
}
예제 #14
0
 StackTrieNode *createTrieNode(uint32_t ThreadId, int32_t FuncId,
                               StackTrieNode *Parent) {
   NodeStore.push_front(StackTrieNode{FuncId, Parent, {}, {{}, {}}});
   auto I = NodeStore.begin();
   auto *Node = &*I;
   if (!Parent)
     Roots[ThreadId].push_back(Node);
   return Node;
 }
예제 #15
0
파일: Nnode.cpp 프로젝트: rand0wn/ask-dsa
int iReturn(std::forward_list<int> l, int n){

	int k = 0;

	for(auto i = l.begin(); i != l.end(); ++i){
		if(++k == std::distance(l.begin(), l.end()) - n + 1)
			return *i;
	}
}
예제 #16
0
		bool runDeferred() {
			__EVENTEMITTER_LOCK_GUARD(mutex);
			if(deferredQueue.empty()) {
				return false;
			}
			(deferredQueue.front())();
			deferredQueue.pop_front();
			return true;
		}
예제 #17
0
void Creature::startAutoWalk(const std::forward_list<Direction>& listDir)
{
	listWalkDir = listDir;

	size_t size = 0;
	for (auto it = listDir.begin(); it != listDir.end() && size <= 1; ++it) {
		size++;
	}
	addEventWalk(size == 1);
}
예제 #18
0
TEST(std_forward_list, clear) {
  std::forward_list<int> l1{0, 0, 0, 0};
  const std::forward_list<int> l2{1, 2, 3};

  l1.clear();
  ASSERT_TRUE(l1.begin() == l1.end());

  l1.insert_after(l1.before_begin(), l2.begin(), l2.end());
  ASSERT_TRUE(l1 == l2);
}
예제 #19
0
//Iterative
void iReverse(std::forward_list<int> &l){

	std::forward_list<int> s = l, r;
	
	for(auto i = l.begin(); i != l.end(); ++i) //Iterate, pop  and push into r
	{
		r.push_front(s.front());
		s.pop_front();	
	}
	l = r; //Assign s to l
}
예제 #20
0
void
throw_exception_sjlj (const struct gdb_exception &exception)
{
  /* Jump to the nearest CATCH_SJLJ block, communicating REASON to
     that call via setjmp's return value.  Note that REASON can't be
     zero, by definition in common-exceptions.h.  */
  exceptions_state_mc (CATCH_THROWING);
  enum return_reason reason = exception.reason;
  catchers.front ().exception = exception;
  longjmp (catchers.front ().buf, reason);
}
예제 #21
0
static ptid_t
fbsd_next_vfork_done (void)
{
  if (!fbsd_pending_vfork_done.empty ())
    {
      ptid_t ptid = fbsd_pending_vfork_done.front ();
      fbsd_pending_vfork_done.pop_front ();
      return ptid;
    }
  return null_ptid;
}
예제 #22
0
inline void save(
    Archive & ar,
    const std::forward_list<U, Allocator> &t,
    const unsigned int file_version
){
    const collection_size_type count(std::distance(t.cbegin(), t.cend()));
    boost::serialization::stl::save_collection<
        Archive,
        std::forward_list<U, Allocator>
    >(ar, t, count);
}
void f_forward_list() {
  std::forward_list<int> C;
  std::forward_list<int>::iterator FListI1 = C.begin();
  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use auto when declaring iterators
  // CHECK-FIXES: auto FListI1 = C.begin();

  const std::forward_list<int> D;
  std::forward_list<int>::const_iterator FListI2 = D.begin();
  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use auto when declaring iterators
  // CHECK-FIXES: auto FListI2 = D.begin();
}
예제 #24
0
파일: humandesign.cpp 프로젝트: ny-c/ce
		void add_connected_gates(int gate, std::forward_list<int>& gates)
		{
			for(size_t i = 0; i < channels.size(); ++i) {

				if(channels[i][0] == gate)
					gates.push_front(channels[i][1]);

				if(channels[i][1] == gate)
					gates.push_front(channels[i][0]);
			}
		}
예제 #25
0
void InsertString(std::forward_list<std::string> &s, const std::string &s1, const std::string &s2)
{
    std::forward_list<std::string>::iterator a, prev = s.before_begin();

    for (a = s.begin(); a != s.end(); ++a, ++prev) {
        if (*a == s1) {
            s.insert_after(a, s2);
            return;
        }
    }
    s.insert_after(prev, s2);
}
예제 #26
0
void add(string term){
	if(terms.find(term) == terms.end()){
		node *n = new node;
		n->t=term;
		n->i=1;
		termStack.push_front(*n);
		terms[term]=&termStack.front();			
	}
	else{
		terms[term]->i++;
	}
}
예제 #27
0
int detectLoop(std::forward_list<int> l){

	auto p1 = l.begin(), p2 = l.begin();	 //Initialise two pointers to head

	while(p1 != l.end() && p2 != l.end() && std::next(p2, 1) != l.end()){ //Move p1 by 1 and p2 by 2 positions
		
		if(*(++p1) == *(++(++p2))){ //Element p1 and p2 are equal -> loop
			return 1;
		}
	}
	return 0;
} 
예제 #28
0
파일: Nnode.cpp 프로젝트: rand0wn/ask-dsa
//Using two pointers
int pReturn(std::forward_list<int> l, int n){

	auto i1 = l.begin(), i2 = l.begin();

	std::advance(i1, n); //Move iterator to n places
	
	while(i1 != l.end()){
		++i1;
		++i2;
	}

	return *i2; 
}
예제 #29
0
    inline
    void CEREAL_SAVE_FUNCTION_NAME(Archive &ar, std::forward_list<T, A> const &forward_list) {
        // write the size - note that this is slow because we need to traverse
        // the entire list. there are ways we could avoid this but this was chosen
        // since it works in the most general fashion with any archive type
        size_type const size = std::distance(forward_list.begin(), forward_list.end());

        ar(make_size_tag(size));

        // write the list
        for (const auto &i : forward_list)
            ar(i);
    }
예제 #30
0
파일: main.cpp 프로젝트: YuryChebiryak/CCI
void removeDups2(std::forward_list<int>& l) {
    std::unordered_set<int> s;
    auto prev = l.before_begin();
    auto iter = l.begin();
    while (iter != l.end()) {
        if (s.find(*iter) != s.end()) {
            iter = l.erase_after(prev);
        } else {
            s.insert(*iter);
            ++iter;
            ++prev;
        }
    }
}