Changeset 2989

Show
Ignore:
Timestamp:
07/02/08 06:37:47 (5 months ago)
Author:
dumas
Message:

ported LinBox::pair interface to std::pair interface

Location:
trunk/linbox/linbox/vector
Files:
3 modified

Legend:

Unmodified
Added
Removed
  • trunk/linbox/linbox/vector/pair.h

    r1404 r2989  
    11// ======================================================================= // (C) Linbox 2000 
    22// Pair of I and T : struct { column index, value } 
    3 // Time-stamp: <19 Sep 03 11:00:25 Jean-Guillaume.Dumas@imag.fr>  
     3// Time-stamp: <23 May 08 13:21:05 Jean-Guillaume.Dumas@imag.fr>  
    44// =======================================================================  
    55#ifndef _LIN_PAIR_H_ 
     
    1010// 
    1111/// Pair of I and T : struct { column index, value } 
    12 template<class T, class I = unsigned long> class Pair { 
     12template<class I, class T> class Pair { 
    1313public: 
    14     typedef Pair<T, I> Self_t; 
     14    typedef Pair<I, T> Self_t; 
    1515    typedef T                      Type_t; 
    16  
     16    typedef I                      first_type; 
     17    typedef T                      second_type; 
     18     
    1719//    ~Pair() {}; 
    1820    Pair() {}; 
    1921 
    20     Pair(const I jj, const T& val) :_j(jj),_value(val){}; 
    21     Pair(const Self_t& p) :_j(p._j),_value(p._value){}; 
     22    Pair(const I jj, const T& val) :first(jj),second(val){}; 
     23    Pair(const Self_t& p) :first(p.first),second(p.second){}; 
    2224 
    2325 
    24     T getvalue() const { return _value; }; 
     26    T getvalue() const { return second; }; 
    2527 
    26     I getindex() const { return _j; }; 
    27     I j() const { return _j; }; 
     28    I getindex() const { return first; }; 
     29    I j() const { return first; }; 
    2830     
    29     T affect(const T& val) { return _value = val; }; 
    30     T change_value(const T& val) { return _value = val; }; 
     31    T affect(const T& val) { return second = val; }; 
     32    T change_value(const T& val) { return second = val; }; 
    3133    
    32     I change_j(const I jj) { return _j = jj; };       
    33     I change_index(const I jj) { return _j = jj; };       
     34    I change_j(const I jj) { return first = jj; };       
     35    I change_index(const I jj) { return first = jj; };       
    3436             
    3537             
    3638    Self_t assign(const T& val) { 
    37         _value = val; 
     39        second = val; 
    3840        return *this; 
    3941    };       
    4042             
    4143    Self_t assign(const I jj, const T& val) { 
    42         _value = val; 
    43         _j = jj; 
     44        second = val; 
     45        first = jj; 
    4446        return *this; 
    4547    };       
    4648             
    47     I decr() { return --_j; };       
    48     I operator--() { return --_j; };       
    49     I operator--(int) { return _j--; };       
    50     I incr() { return ++_j; };       
    51     I operator++() { return ++_j; };       
    52     I operator++(int) { return _j++; };       
     49    I decr() { return --first; };       
     50    I operator--() { return --first; };       
     51    I operator--(int) { return first--; };       
     52    I incr() { return ++first; };       
     53    I operator++() { return ++first; };       
     54    I operator++(int) { return first++; };       
    5355             
    54     friend inline std::istream& operator>> (std::istream& is, Pair<T, I>& a) { 
    55         I jj; 
    56         T val; 
    57         is >> jj >> val; 
    58         a._value=val; a._j=jj; 
    59 //         a = Pair<T, I>(jj,val); 
     56    friend inline std::istream& operator>> (std::istream& is, Pair<I, T>& a) { 
     57        is >> a.first >> a.second; 
    6058        return is; 
    61 }; 
     59    } 
    6260     
    63     friend inline std::ostream& operator<< (std::ostream& o, const Pair<T, I> a){ 
    64 //         return o << a.j() << " " << a.getvalue()  ; 
    65         return o << a._j << " " << a._value ; 
    66 }; 
     61    friend inline std::ostream& operator<< (std::ostream& o, const Pair<I, T> a){ 
     62        return o << a.first << " " << a.second ; 
     63    } 
    6764     
    6865 
    69 private: 
    70     I _j; 
    71     T _value; 
     66public: 
     67    I first; 
     68    T second; 
    7269}; 
    7370 
  • trunk/linbox/linbox/vector/sparse.h

    r2371 r2989  
    11// ======================================================================= // (C) Linbox 2000 
    22// Sparse Vector      : vector< Pair<T> > and an additional actual size 
    3 // Time-stamp: <15 Jul 05 10:27:48 Jean-Guillaume.Dumas@imag.fr>  
     3// Time-stamp: <23 May 08 13:21:31 Jean-Guillaume.Dumas@imag.fr>  
    44// =======================================================================  
    55#ifndef _SPARSE_VECTOR_H_ 
     
    2323// --------------------------------------------------- 
    2424// 
    25 /** \brief vector< Pair<T> > and actualsize 
     25/** \brief vector< Pair<T,I> > and actualsize 
    2626\ingroup vector 
    2727*/ 
    28 template<class T, class I = unsigned long> 
    29 class Sparse_Vector : public _IBB_VECTOR_< Pair<T, I> > { 
     28template<class T, class I = unsigned int> 
     29class Sparse_Vector : public _IBB_VECTOR_< Pair<I, T> > { 
    3030public: 
    31     typedef Pair<T, I>             Element; 
     31    typedef Pair<I, T>             Element; 
    3232    typedef T                      Type_t; 
    3333    typedef Sparse_Vector<T, I>    Self_t; 
     
    3838 
    3939    Sparse_Vector() {}; 
    40     Sparse_Vector(size_t n) : _IBB_VECTOR_< Pair<T, I> >(n), _rsize(0) {}; 
    41     Sparse_Vector(size_t n, size_t rn) : _IBB_VECTOR_< Pair<T, I> >(n), _rsize(rn) {}; 
     40    Sparse_Vector(size_t n) : _IBB_VECTOR_< Pair<I, T> >(n), _rsize(0) {}; 
     41    Sparse_Vector(size_t n, size_t rn) : _IBB_VECTOR_< Pair<I, T> >(n), _rsize(rn) {}; 
    4242    ~Sparse_Vector() {}; 
    4343     
  • trunk/linbox/linbox/vector/vector-traits.h

    r2619 r2989  
    205205                { 
    206206                    public: 
    207                         inline bool operator () (const std::pair <size_t, T> &i, const size_t j) const 
     207                        template<typename PairType> 
     208                        inline bool operator () (const PairType &i, const size_t j) const 
    208209                                { return i.first < j; } 
    209210                };