Changeset 8b7b108 in git


Ignore:
Timestamp:
Aug 26, 2014, 12:13:44 PM (9 years ago)
Author:
Martin Lee <martinlee84@…>
Branches:
(u'spielwiese', '91e5db82acc17434e4062bcfa44e6efa7d41fd30')
Children:
ffb7320a1e69130b9af44765525d84eab07b5b94
Parents:
98abec57dad14f757407f31931b9555ceee6c4ad
git-author:
Martin Lee <martinlee84@web.de>2014-08-26 12:13:44+02:00
git-committer:
Martin Lee <martinlee84@web.de>2014-08-26 12:29:12+02:00
Message:
added operator== to lists
added Union, Difference, find which take an additional equality comparision function
instantiated templates with List<CanonicalForm> as typename
Location:
factory
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • factory/ftmpl_inst.cc

    r98abec r8b7b108  
    151151
    152152//
     153template int operator== (const List<CanonicalForm> &, const List<CanonicalForm> &);
    153154template List<CanonicalForm> Union ( const List<CanonicalForm> &, const List<CanonicalForm> & );
     155template List<List<CanonicalForm> > Union ( const List<List<CanonicalForm> >&, const List<List<CanonicalForm> >&, int operator== (const List<CanonicalForm> &, const List<CanonicalForm> &));
    154156template List<CanonicalForm> Difference ( const List<CanonicalForm> &, const List<CanonicalForm> & );
     157template List<List<CanonicalForm> > Difference ( const List<List<CanonicalForm> >&, const List<List<CanonicalForm> >&, int operator== (const List<CanonicalForm> &, const List<CanonicalForm> &));
     158template List<List<CanonicalForm> > Difference ( const List<List<CanonicalForm> >&, const List<CanonicalForm>&, int operator== (const List<CanonicalForm> &, const List<CanonicalForm> &));
    155159template CanonicalForm prod ( const List<CanonicalForm> & );
    156160template bool find ( const List<CanonicalForm> &, const CanonicalForm&);
     161template bool find ( const List<List<CanonicalForm> >&, const List<CanonicalForm>&, int operator== (const List<CanonicalForm> &, const List<CanonicalForm> &));
    157162// place here your own template stuff, not yet instantiated by factory
    158163//
  • factory/include/factory/templates/ftmpl_list.h

    r98abec r8b7b108  
    112112
    113113template <class T>
     114int operator== (const List<T>&, const List<T>& );
     115
     116template <class T>
    114117List<T> Union ( const List<T>&, const List<T>& );
    115118
    116119template <class T>
    117120List<T> Difference ( const List<T>&, const List<T>& );
     121
     122template <class T>
     123List<T> Union ( const List<T> &, const List<T> & , int (*ecmpf)( const T&, const T& ));
     124
     125template <class T>
     126List<T> Difference ( const List<T> &, const List<T> & , int (*ecmpf)( const T&, const T& ));
     127
     128template <class T>
     129List<T> Difference ( const List<T> & F, const T & G, int (*ecmpf)( const T&, const T& ));
    118130
    119131template <class T>
     
    126138bool find (const List<T>&, const T& t);
    127139
     140template <class T>
     141bool find (const List<T> & F, const T& t, int (*ecmpf)( const T&, const T& ));
    128142#endif /* ! INCL_LIST_H */
  • factory/templates/ftmpl_list.cc

    r98abec r8b7b108  
    101101        cur = cur->prev;
    102102        while ( cur )
    103         {
     103        {
    104104            first = new ListItem<T>( *(cur->item), first, 0 );
    105105            first->next->prev = first;
     
    144144        ListItem<T> *dummy;
    145145        while ( first )
    146         {
     146        {
    147147            dummy = first;
    148148            first = first->next;
     
    151151        ListItem<T>* cur = l.last;
    152152        if ( cur )
    153         {
     153        {
    154154            first = new ListItem<T>( *(cur->item), 0, 0 );
    155155            last = first;
    156156            cur = cur->prev;
    157157            while ( cur )
    158             {
     158            {
    159159                first = new ListItem<T>( *(cur->item), first, 0 );
    160160                first->next->prev = first;
     
    164164        }
    165165        else
    166         {
     166        {
    167167            first = last = 0;
    168168            _length = 0;
     
    171171    }
    172172    return *this;
     173}
     174
     175template <class T>
     176int operator== ( const List<T>& l1, const List<T>& l2 )
     177{
     178    if (l1.length() != l2.length())
     179      return 0;
     180    ListIterator<T> iter2= l2;
     181    for (ListIterator<T> iter1= l1; iter1.hasItem(); iter1++)
     182    {
     183      if (!(iter1.getItem() == iter2.getItem()))
     184        return 0;
     185      iter2++;
     186    }
     187
     188    return 1;
    173189}
    174190
     
    201217            *cursor->item = t;
    202218        else
    203         {
     219        {
    204220            cursor = cursor->prev;
    205221            cursor->next = new ListItem<T>( t, cursor->next, cursor );
     
    227243            insf( *cursor->item, t );
    228244        else
    229         {
     245        {
    230246            cursor = cursor->prev;
    231247            cursor->next = new ListItem<T>( t, cursor->next, cursor );
     
    275291        _length--;
    276292        if ( first == last )
    277         {
     293        {
    278294            delete first;
    279295            first = last = 0;
    280296        }
    281297        else
    282         {
     298        {
    283299            ListItem<T> *dummy = first;
    284300            first->next->prev = 0;
     
    305321        _length--;
    306322        if ( first == last )
    307         {
     323        {
    308324            delete last;
    309325            first = last = 0;
    310326        }
    311327        else
    312         {
     328        {
    313329            ListItem<T> *dummy = last;
    314330            last->prev->next = 0;
     
    327343        int swap;
    328344        do
    329         {
     345        {
    330346            swap = 0;
    331347            ListItem<T> *cur = first;
    332348            while ( cur->next )
    333             {
     349            {
    334350                if ( swapit( *(cur->item), *(cur->next->item) ) )
    335                 {
     351                {
    336352                    T* dummy = cur->item;
    337353                    cur->item = cur->next->item;
     
    481497            theList->insert( t );
    482498        else
    483         {
     499        {
    484500            current->prev = new ListItem<T>( t, current, current->prev );
    485501            current->prev->prev->next = current->prev;
     
    498514            theList->append( t );
    499515        else
    500         {
     516        {
    501517            current->next = new ListItem<T>( t, current->next, current );
    502518            current->next->next->prev = current->next;
     
    514530        ListItem <T>*dummynext = current->next, *dummyprev = current->prev;
    515531        if ( current->prev )
    516         {
     532        {
    517533            current->prev->next = current->next;
    518534            if ( current->next )
     
    524540        }
    525541        else
    526         {
     542        {
    527543            if ( current->next )
    528544                current->next->prev = 0;
     
    558574        j = G;
    559575        while ( ( ! iselt ) && j.hasItem() )
    560         {
     576        {
    561577            iselt =  f == j.getItem();
    562578            j++;
     
    576592    for ( i = F; i.hasItem(); ++i )
    577593        L.insert( i.getItem(), cmpf, insf );
     594    return L;
     595}
     596
     597template <class T>
     598List<T> Union ( const List<T> & F, const List<T> & G, int (*ecmpf)( const T&, const T& ))
     599{
     600    List<T> L = G;
     601    ListIterator<T> i, j;
     602    T f;
     603    bool iselt;
     604
     605    for ( i = F; i.hasItem(); i++ )
     606    {
     607        f = i.getItem();
     608        iselt = false;
     609        j = G;
     610        while ( ( ! iselt ) && j.hasItem() )
     611        {
     612            iselt =  ecmpf (f, j.getItem());
     613            j++;
     614        }
     615        if ( ! iselt )
     616            L.append( f );
     617    }
    578618    return L;
    579619}
     
    594634        if ( ! found )
    595635            L.append( f );
     636    }
     637    return L;
     638}
     639
     640template <class T>
     641List<T> Difference ( const List<T> & F, const List<T> & G, int (*ecmpf)( const T&, const T& ))
     642{
     643    List<T> L;
     644    ListIterator<T> i, j;
     645    T f;
     646    int found;
     647    for ( i = F; i.hasItem(); ++i )
     648    {
     649        f = i.getItem();
     650        found = 0;
     651        for ( j = G; j.hasItem() && (!found); ++j )
     652            found = ecmpf (f, j.getItem());
     653        if ( ! found )
     654            L.append( f );
     655    }
     656    return L;
     657}
     658
     659template <class T>
     660List<T> Difference ( const List<T> & F, const T & G, int (*ecmpf)( const T&, const T& ))
     661{
     662    List<T> L;
     663    ListIterator<T> i;
     664    int found;
     665    for ( i = F; i.hasItem(); ++i )
     666    {
     667        found = ecmpf (G, i.getItem());
     668        if ( ! found )
     669            L.append( i.getItem() );
    596670    }
    597671    return L;
     
    621695  return false;
    622696}
     697
     698template <class T>
     699bool find (const List<T> & F, const T& t, int (*ecmpf)( const T&, const T& ))
     700{
     701  if (F.length() == 0) return false;
     702  ListIterator<T> J= F;
     703  while (J.hasItem())
     704  {
     705    if (ecmpf (J.getItem(), t))
     706      return true;
     707    J++;
     708  }
     709  return false;
     710}
     711
Note: See TracChangeset for help on using the changeset viewer.