예제 #1
0
파일: string.hpp 프로젝트: nparse/nparse
	void accept (const typename range<M_>::type& C,
			const typename range<M_>::type& E, typename spectrum<M_>::type& S)
		const
	{
		if	(	(! m_partial)
			&&	(m_string. size() > static_cast<typename string_type::size_type>
					(C. second - E. second))
			)
		{
			return ;
		}

		typename iterator<M_>::type i = E. second;
		typename string_type::const_iterator j = m_string. begin();

		if (m_greedy)
		{
			while ((j != m_string. end()) && m_compare(*i, *j))
			{
				++ i;
				++ j;
			}

			if	(	(	m_partial
					&&	(	m_accept_empty
						||	(j != m_string. begin())
						)
					)
				||	(j == m_string. end())
				)
			{
				S. push(E. second, i);
			}
		}
		else
		{
			if (m_partial && m_accept_empty)
			{
				S. push(E. second, i);
			}

			while ((j != m_string. end()) && m_compare(*i, *j))
			{
				++ i;
				++ j;
				S. push(E. second, i);
			}
		}
	}
예제 #2
0
typename SkipList<T, Compare, Traits>::const_iterator
SkipList<T, Compare, Traits>::lower_bound(const T& x) const
{
  size_t nLevels = m_head->nexts.size();
  NodePointer p = m_head;
  NodePointer q = p->nexts.back();
  for (int i = nLevels - 1; i >= 0; --i) {
    typename std::list<SkipListNodePointer>::iterator it_p = p->nexts.begin();
    for (int j = 0; j < i; j++) {
      it_p++;
    }
    q = *it_p;
    if (q != m_head) {
      while (m_compare(q->data, x)) {
        p = *it_p;
        it_p = p->nexts.begin();
        for (int j = 0; j < i; j++) {
          it_p++;
        }
        q = *it_p;
        if (q == m_head) {
          break;
        }
      }
    }
  }
  return const_iterator(q);
}
예제 #3
0
 void examine_edge(Edge e, Graph& g) {
   // Comparison needs to be more complicated because distance and weight
   // types may not be the same; see bug 8398
   // (https://svn.boost.org/trac/boost/ticket/8398)
   D source_dist = get(m_distance, source(e, g));
   if (m_compare(m_combine(source_dist, get(m_weight, e)), source_dist))
       boost::throw_exception(negative_edge());
   m_vis.examine_edge(e, g);
 }
예제 #4
0
파일: heap.hpp 프로젝트: Lykos/libsquirrel
 inline typename Heap<T, Compare>::size_type Heap<T, Compare>::min_child(size_type index) const
 {
   size_type left = HeapArithmetic::left_child(index);
   size_type right = HeapArithmetic::right_child(index);
   assert(left < BaseList<T>::size());
   if (right >= BaseList<T>::size()) {
     return left;
   } else {
     return m_compare(BaseList<T>::at(left), BaseList<T>::at(right)) ? left : right;
   }
 }
예제 #5
0
파일: heap.hpp 프로젝트: Lykos/libsquirrel
 inline void Heap<T, Compare>::bubble_down(size_type index)
 {
   while (HeapArithmetic::left_child(index) < BaseList<T>::size()) {
     size_type new_index = min_child(index);
     if (m_compare(BaseList<T>::at(index), BaseList<T>::at(new_index))) {
       return;
     }
     BaseList<T>::swap(new_index, index);
     index = new_index;
   }
 }
예제 #6
0
파일: heap.hpp 프로젝트: Lykos/libsquirrel
 inline void Heap<T, Compare>::bubble_up(size_type index)
 {
   while (index > 0) {
     size_type new_index = HeapArithmetic::parent(index);
     if (m_compare(BaseList<T>::at(new_index), BaseList<T>::at(index))) {
       return;
     }
     BaseList<T>::swap(new_index, index);
     index = new_index;
   }
 }
예제 #7
0
 void examine_edge(Edge e, Graph& g) { 
   if (m_compare(get(m_weight, e), m_zero))
     throw negative_edge();
   m_vis.examine_edge(e, g);
 }
예제 #8
0
std::pair<typename SkipList<T, Compare, Traits>::const_iterator, bool>
SkipList<T, Compare, Traits>::insert(const T& x)
{
  size_t nLevels = m_head->nexts.size();
  // 1. find insert position
  std::vector<NodePointer> insertPositions(nLevels);
  NodePointer p = m_head;
  NodePointer q = p->nexts.back();
  for (int i = nLevels - 1; i >= 0; --i) {
    typename std::list<SkipListNodePointer>::iterator it_p = p->nexts.begin();
    for (int j = 0; j < i; j++) {
      it_p++;
    }
    q = *it_p;
    if (q != m_head) {
      while (m_compare(q->data, x)) {
        p = *it_p;
        it_p = p->nexts.begin();
        for (int j = 0; j < i; j++) {
          it_p++;
        }
        q = *it_p;
        if (q == m_head) {
          break;
        }
      }
    }
    insertPositions[i] = p;
  }
  // 2. whether q->data == x?
  if (q != m_head)
    if (!m_compare(q->data, x) && !m_compare(x, q->data)) {
      return std::pair<const_iterator, bool>(const_iterator(q), false);
    }
  // 3. construct new node;
  NodePointer newNode = createNode(x);
  // 4. pick random nLevels
  size_t newLevel = pickRandomLevel();
  // 5. insert the new node
  newNode->nexts.resize(newLevel + 1);
  newNode->prevs.resize(newLevel + 1);
  if (newLevel > nLevels - 1) {
    m_head->nexts.resize(newLevel + 1, m_head);
    m_head->prevs.resize(newLevel + 1, m_head);
    insertPositions.resize(newLevel + 1, m_head);
  }
  for (size_t i = 0; i <= newLevel; i++) {
    typename std::list<SkipListNodePointer>::iterator it_newNode_next = newNode->nexts.begin();
    for (int j = 0; j < i; j++) {
      it_newNode_next++;
    }
    typename std::list<SkipListNodePointer>::iterator it_insert_next = insertPositions[i]->nexts.begin();
    for (int j = 0; j < i; j++) {
      it_insert_next++;
    }
    *it_newNode_next = *it_insert_next;

    typename std::list<SkipListNodePointer>::iterator it_newNode_prev = newNode->prevs.begin();
    for (int j = 0; j < i; j++) {
      it_newNode_prev++;
    }
    *it_newNode_prev = insertPositions[i];

    it_insert_next = insertPositions[i]->nexts.begin();
    for (int j = 0; j < i; j++) {
      it_insert_next++;
    }
    *it_insert_next = newNode;
    it_newNode_next = newNode->nexts.begin();
    for (int j = 0; j < i; j++) {
      it_newNode_next++;
    }
    typename std::list<SkipListNodePointer>::iterator it_newNode_next_prev = (*it_newNode_next)->prevs.begin();
    for (int j = 0; j < i; j++) {
      it_newNode_next_prev++;
    }
    *it_newNode_next_prev = newNode;
  }

  ++m_size;
  return std::pair<const_iterator, bool>(const_iterator(newNode), true);
}
예제 #9
0
파일: astar_search.hpp 프로젝트: Bia10/clrn
 void examine_edge(Edge e, const Graph& g) {
   if (m_compare(get(m_weight, e), m_zero))
     BOOST_THROW_EXCEPTION(negative_edge());
   m_vis.examine_edge(e, g);
 }
 void examine_edge(Edge e, Graph& g) {
   if (m_compare(get(m_weight, e), m_zero))
       boost::throw_exception(negative_edge());
   m_vis.examine_edge(e, g);
 }