Beispiel #1
0
typename List<T>::const_iterator List<T>::find(const T &x) const {
  typename List<T>::const_iterator temp(this->m_head.next); // começa pelo primeiro
  while(temp.ptr() != nullptr) { // e não para até achar
    if(*temp == x) return temp;
    else temp++;
  } // ou não achar
  throw std::runtime_error("Valor não encontrado"); // eue não encontrei então não posso retornar
}
Beispiel #2
0
typename List<T>::iterator List<T>::erase_after(typename List<T>::const_iterator itr) {
  Node *temp = (itr.ptr())->next; // apontando para o que vai ser deletado
  (itr.ptr())->next = temp->next;
  temp->next->last = itr.ptr();
  delete temp;
  this->m_size--;
  itr++;
  List<T>::iterator retorno = itr.ptr();
  return retorno;
}
Beispiel #3
0
void List<T>::CheckLinks(std::ostream& os) const
{
  typename List<T>::ConstIterator i,j,k;
  // bool ok = 1;
  size_t n = 0;
  for (i = this->Begin(), n = 0; i != this->End(); ++i, ++n)
  {
    j = i; --j; ++j;
    k = i; ++k; --k;
    if (!i.Valid() || !j.Valid() || !k.Valid() || i != j || i != k)
    {
      os << " ** forward reciprocity failure at position " << n << '\n';
      // ok = 0;
      break;
    }
  }
  // if (ok) os << " ** passed forward reciprocity check\n";
  
  for (i = this->rBegin(), n = Size(); i != this->rEnd(); --i, --n)
  {
    j = i; --j; ++j;
    k = i; ++k; --k;
    if (!i.Valid() || !j.Valid() || !k.Valid() || i != j || i != k)
    {
      os << " ** reverse reciprocity failure at position " << n << '\n';
      // ok = 0;
      break;
    }
  }     
  // if (ok) os << " ** passed reverse reciprocity check\n";
} // CheckLinks()
Beispiel #4
0
List<U> ListMapper<T,U>::map(List<T> l, U* (*f)(const T*)){
  ListElem<U> * sentinel= new ListElem<U>(NULL);
  ListElem<U> *last=sentinel;
  for(typename List<T>::iterator i=l.getIterator();!i.isAtEnd();i++){
    U* data=f(*i);
    ListElem<U> *act = new ListElem<U>(data);
    last->setNext(act);
    last=act;
  }
  return List<U>(sentinel);
}
Beispiel #5
0
typename List<T>::const_iterator List<T>::insert_after(typename List<T>::const_iterator itr, const T &x) {
  Node *temp = new Node(); // criando o novo nó
  temp->data = x;
  temp->next = (itr.ptr())->next; // esse novo nó aponta para o que vem depois do nó atraz dele
  temp->last = itr.ptr();
  (itr.ptr())->next->last = temp; // muito complexo, melhor não comentar
  (itr.ptr())->next = temp; // o que está atraz agora aponta pra ele
  this->m_size++;
  itr++;
  return itr;
}
Beispiel #6
0
List<U> ListMapper<T,U>::flatMap(List<T> l, List<U> (*f)(const T*)){
  ListElem<U> *s = new ListElem<U>(NULL);
  ListElem<U> *last=s;
  for(typename List<T>::iterator i=l.getIterator();!i.isAtEnd;i++){
    List<U> l2 = f(*i);
    for (typename List<U>::iterator j=l2.getIterator();!j.isAtEnd();j++){
      ListElem<U> *elem= new ListElem<U>(new U(**j));
      last->setNext(elem);
      last=elem;
    }
  }
  return List<U>(s);
}
Beispiel #7
0
inline typename List< FragmentT, ContainerT >::FSizeType
List< FragmentT, ContainerT >::insert(
    typename List< FragmentT, ContainerT >::Iterator where,
    const typename List< FragmentT, ContainerT >::FragmentType& insertFragment)
{
    Iterator tmp = where;
    CompareFragments< FragmentType > cmp;
    if( ( where == begin() || cmp( *--tmp, insertFragment ) )
        && ( where == end() || cmp( insertFragment, *where ) ) )
    {
        s_.insert( where, insertFragment );
        sumLength_ += insertFragment.length();
        return insertFragment.length();
    }
    else
    {
        return insert( insertFragment );
    }
}
Beispiel #8
0
inline typename List< FragmentT, ContainerT >::FSizeType
List< FragmentT, ContainerT >::erase(
    const typename List< FragmentT, ContainerT >::FragmentType& eraseFragment)
{
    if( eraseFragment.end() > limit() )
    {
//        throw BadRangeException( eraseFragment, limit() );
        CString errorMsg;
        errorMsg.Format(
            _T( "FF::SimpleFragmentList - invalid arg for erase - " )
            _T( "List - size: %u - limit: %I64u - sum: %I64u - " )
            _T( "Fragment - begin: %I64i - end: %I64u" ), size(), limit(), sumLength(),
            eraseFragment.begin(), eraseFragment.end() );
        theApp.Message( MSG_ERROR, errorMsg );
        return 0;
    }
    if( eraseFragment.length() == 0 ) return 0;
    ::std::pair< Iterator, Iterator > eraseRange =
        overlappingRange( eraseFragment );
    if( eraseRange.first == eraseRange.second ) return 0;
    const FragmentType& frontFragment
        = eraseRange.first->begin() < eraseFragment.begin()
            ? FragmentType( *eraseRange.first,
                 eraseRange.first->begin(), eraseFragment.begin() )
            : FragmentType( *eraseRange.first, 0,
                ::std::numeric_limits< FSizeType >::max() );
    --eraseRange.second;
    const FragmentType& backFragment
        = eraseRange.second->end() > eraseFragment.end()
        ? FragmentType( *eraseRange.second,
                eraseFragment.end(), eraseRange.second->end() )
        : FragmentType( *eraseRange.second, 0,
                ::std::numeric_limits< FSizeType >::max() );
    const FSizeType oldSum = sumLength();
    ++eraseRange.second;
    for( ; eraseRange.first != eraseRange.second; )
    {
        sumLength_ -= eraseRange.first->length();
        s_.erase( eraseRange.first++ );
    }
    if( frontFragment.end() < ::std::numeric_limits< FSizeType >::max() )
    {
        s_.insert( eraseRange.second, frontFragment );
        sumLength_ += frontFragment.length();
    }
    if( backFragment.end() < ::std::numeric_limits< FSizeType >::max() )
    {
        s_.insert( eraseRange.second, backFragment );
        sumLength_ += backFragment.length();
    }
    return oldSum - sumLength();
}
Beispiel #9
0
inline typename List< FragmentT, ContainerT >::FSizeType
List< FragmentT, ContainerT >::insert(
    const typename List< FragmentT, ContainerT >::FragmentType& insertFragment)
{
    if( insertFragment.end() > limit() )
    {
//        throw BadRangeException( insertFragment, limit() );
        CString errorMsg;
        errorMsg.Format(
            _T( "FF::SimpleFragmentList - invalid arg for insert - " )
            _T( "List - size: %u - limit: %I64u - sum: %I64u - " )
            _T( "Fragment - begin: %I64u - end: %I64u" ), size(), limit(), sumLength(),
            insertFragment.begin(), insertFragment.end() );
        theApp.Message( MSG_ERROR, errorMsg );
        return 0;
    }
    if( insertFragment.length() == 0 ) return 0;
    ::std::pair< Iterator, Iterator > insertRange =
        equalRange( insertFragment );
    if( insertRange.first != insertRange.second )
    {
        FSizeType chgSum =
            Traits::mergeAndReplace( s_, insertRange, insertFragment );
        sumLength_ += chgSum;
        return chgSum;
    }
    else
    {
        s_.insert( insertRange.second, insertFragment );
        sumLength_ += insertFragment.length();
        return insertFragment.length();
    }
}
Beispiel #10
0
typename RangeT::size_type List< RangeT, TraitsT, ContainerT >::insert(
	typename List< RangeT, TraitsT, ContainerT >::iterator where, const RangeT& value)
{
	if ( value.end() > Traits::limit() )
	{
		qDebug( qPrintable(QString("ListError - insert(h) - size: %1 - limit: %2 - sum: %3 - \nRange - begin: %4 - end: %5")
			.arg(size()).arg(Traits::limit()).arg(Traits::length_sum()).arg(value.begin()).arg(value.end())) );
		return 0;
	}
	if ( value.size() == 0 ) return 0;
	iterator tmp( where );
	return ( where == begin() || ( --tmp )->end() < value.begin() )
			&& ( where == end() || value.end() < where->begin() )
		? Traits::simple_merge( m_set, where, value )
		: insert( value );
}
Beispiel #11
0
typename List<T>::iterator List<T>::erase_after(typename List<T>::const_iterator first , typename List<T>::const_iterator last ) {
  Node *temp = (first.ptr())->next; // apontando para o que vai ser deletado
  (first.ptr())->next = last.ptr();
  (last.ptr())->last = first.ptr();
  first++;
  while(first != last) { // a sobrecarga de operador é util aqui
    first++;
    delete temp;
    temp = first.ptr();
    this->m_size--; // cada vez que deleta diminui um
  }
  first++; // andando um no
  List<T>::iterator retorno = first.ptr(); //convertendo de const para iterator
  return retorno;
}
Beispiel #12
0
typename RangeT::size_type List< RangeT, TraitsT, ContainerT >::insert(
	typename List< RangeT, TraitsT, ContainerT >::iterator where, const RangeT& value)
{
	if ( value.end() > limit() )
	{
//		throw ListException( value, limit() );
		CString msg;
		msg.Format( _T( "ListError - insert(h) - size: %u - limit: %I64u - sum: %I64u - " )
			_T( "Range - begin: %I64u - end: %I64u" ),
			size(), limit(), Traits::length_sum(), value.begin(), value.end() );
		theApp.Message( MSG_ERROR, msg );
		return 0;
	}
	if ( value.size() == 0 ) return 0;
	iterator tmp( where );
	return ( where == begin() || ( --tmp )->end() < value.begin() )
			&& ( where == end() || value.end() < where->begin() )
		? Traits::simple_merge( m_set, where, value )
		: insert( value );
}