Changeset 1088 for trunk/yat/utility


Ignore:
Timestamp:
Feb 14, 2008, 3:26:19 PM (14 years ago)
Author:
Peter
Message:

Closes #247. Removed IteratorWeighted? iterators over weighted container instead can use Iterator with a special Policy.

Location:
trunk/yat/utility
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/yat/utility/Iterator.h

    r1083 r1088  
    261261    //Iterator& operator=(const Iterator&);
    262262  };
     263
     264  /**
     265     Whether Iterator is weighted is desiced by Policy.
     266   */
     267  template<typename A, typename B, typename C, typename D, typename Policy>
     268  struct weighted_iterator_traits<Iterator<A, B, C, D, Policy> > {
     269    typedef typename Policy::weighted_iterator_type type;
     270  };
     271
     272  template<typename A, typename B, typename C, typename D, typename E>
     273  struct iterator_traits<Iterator<A, B, C, D, E> > {
     274    /**
     275       \return data
     276    */
     277    double data(Iterator<A, B, C, D, E> iter) const
     278    { return iter.data(); }
     279
     280    /**
     281       \return weight
     282    */
     283    double weight(Iterator<A, B, C, D, E> iter) const
     284    { return iter.weight(); }
     285
     286  };
     287
     288
    263289}}} // of namespace utility, yat, and theplu
    264290
  • trunk/yat/utility/Makefile.am

    r1081 r1088  
    3737  Alignment.h ColumnStream.h CommandLine.h \
    3838  Exception.h FileUtil.h Iterator.h IteratorPolicy.h iterator_traits.h \
    39   IteratorWeighted.h kNNI.h matrix.h NNI.h \
     39  kNNI.h matrix.h NNI.h \
    4040  Option.h OptionArg.h OptionFile.h OptionInFile.h OptionOutFile.h \
    4141  OptionHelp.h OptionSwitch.h \
  • trunk/yat/utility/StrideIterator.h

    r1066 r1088  
    4444  struct weighted_iterator_traits<StrideIterator<Iter> > {
    4545    typedef typename weighted_iterator_traits<Iter>::type type;
     46  };
     47
     48  template <class Iter>
     49  struct iterator_traits<StrideIterator<Iter> > {
     50    /**
     51       \return data that is *iter
     52    */
     53    double data(StrideIterator<Iter> iter) const
     54    { iterator_traits<Iter> jojo;
     55      return jojo.data(iter.base()); }
     56
     57    /**
     58       \return 1.0
     59    */
     60    double weight(StrideIterator<Iter> iter) const
     61    { return iterator_traits<Iter>().weight(iter.base()); }
     62
    4663  };
    4764
  • trunk/yat/utility/iterator_traits.h

    r1041 r1088  
    120120
    121121  /**
    122     Function to be used to make compile-time decision how to return
    123     data from an iterator separating two cases: weighted and
    124     unweighted.
     122     \brief traits to make unweighted iterator work in as a weighted
    125123
    126     In this way unweighted iterators can be used in a weighted context.
     124     This class must be implemented for every iterator that can be weighted.
     125
     126     \see StrideIterator and Iterator
    127127   */
    128   // Peter, perhaps these should be templatized, but for now return
    129   // type double is hard coded.
    130128  template <class Iter>
    131   double iterator_traits_data(Iter iter)
    132   { return iterator_traits_data(iter, typename
    133                                 weighted_iterator_traits<Iter>::type()); }
     129  struct iterator_traits {
     130    // Peter, perhaps these should be templatized, but for now return
     131    // type double is hard coded.
     132    /**
     133       \return data that is *iter
     134    */
     135    double data(Iter iter) const
     136    { check_iterator_is_unweighted(iter); return *iter; }
    134137
    135   /**
    136      \return data for weighted iterator
    137    */
    138   template <class Iter>
    139   double iterator_traits_data(Iter i, weighted_type)
    140   { return i.data(); }
     138    /**
     139       \return 1.0
     140    */
     141    double weight(Iter iter) const
     142    { check_iterator_is_unweighted(iter); return 1.0; }
    141143
    142   /**
    143      \return data for unweighted data
    144    */
    145   template <class Iter>
    146   double iterator_traits_data(Iter i, unweighted_type)
    147   { return *i; }
    148 
    149   /**
    150     Function to be used to make compile-time decision how to return
    151     data from an iterator separating two cases: weighted and
    152     unweighted.
    153 
    154     In this way unweighted iterators can be used in a weighted context
    155     and weight will be set to unity.
    156    */
    157   // Peter, perhaps these should be templatized, but for now return
    158   // type double is hard coded.
    159   template <class Iter>
    160   double iterator_traits_weight(Iter iter)
    161   { return iterator_traits_weight(iter, typename
    162                                   weighted_iterator_traits<Iter>::type()); }
    163 
    164   /**
    165      \return weight for weighted iterator
    166    */
    167   template <class Iter>
    168   double iterator_traits_weight(Iter i, weighted_type)
    169   { return i.weight(); }
    170 
    171   /**
    172      \return weight for unweighted iterator
    173    */
    174   template <class Iter>
    175   double iterator_traits_weight(Iter i, unweighted_type)
    176   { return 1.0; }
    177 
     144  };
    178145
    179146}}} // of namespace utility, yat, and theplu
Note: See TracChangeset for help on using the changeset viewer.