avoid map in PoolImpl
authorMichael Andres <ma@suse.de>
Fri, 8 Feb 2008 17:46:51 +0000 (17:46 +0000)
committerMichael Andres <ma@suse.de>
Fri, 8 Feb 2008 17:46:51 +0000 (17:46 +0000)
zypp/PoolItem.h
zypp/ResPool.cc
zypp/ResPool.h
zypp/pool/PoolImpl.cc
zypp/pool/PoolImpl.h
zypp/pool/PoolTraits.h

index a104c88..1480cce 100644 (file)
@@ -64,9 +64,9 @@ namespace zypp
       /** Returns the current status. */
       ResStatus & status() const;
 
-      /** Reset status (applies autoprotection). */
+      /** Reset status. */
       ResStatus & statusReset() const;
-      
+
       /** Returns the ResObject::constPtr.
        * \see \ref operator->
        */
index f2d41ff..d161b30 100644 (file)
@@ -16,6 +16,7 @@
 
 #include "zypp/ResPool.h"
 #include "zypp/pool/PoolImpl.h"
+#include "zypp/pool/PoolStats.h"
 
 using std::endl;
 
@@ -61,12 +62,6 @@ namespace zypp
   ResPool::size_type ResPool::size() const
   { return _pimpl->size(); }
 
-  ResPool::const_iterator ResPool::begin() const
-  { return _pimpl->begin(); }
-
-  ResPool::const_iterator ResPool::end() const
-  { return _pimpl->end(); }
-
 
   PoolItem ResPool::find( const sat::Solvable & slv_r ) const
   { return _pimpl->find( slv_r ); }
@@ -103,6 +98,9 @@ namespace zypp
   ResPool::AdditionalCapabilities & ResPool::additionaProvide() const
   { return _pimpl->additionaProvide(); }
 
+  const pool::PoolTraits::ItemContainerT & ResPool::store() const
+  { return _pimpl->store(); }
+
   /******************************************************************
   **
   **   FUNCTION NAME : operator<<
@@ -110,7 +108,8 @@ namespace zypp
   */
   std::ostream & operator<<( std::ostream & str, const ResPool & obj )
   {
-    return str << *obj._pimpl;
+    dumpPoolStats( str << "ResPool " << sat::Pool::instance() << endl << "  ",
+                            obj.begin(), obj.end() );
   }
 
   /////////////////////////////////////////////////////////////////
index 7881df2..680ea5f 100644 (file)
@@ -28,6 +28,8 @@ namespace zypp
   class SerialNumber;
   class ResPoolProxy;
 
+
+
   ///////////////////////////////////////////////////////////////////
   //
   //   CLASS NAME : ResPool
@@ -46,175 +48,192 @@ namespace zypp
   {
     friend std::ostream & operator<<( std::ostream & str, const ResPool & obj );
 
-  public:
-    /** \ref PoolItem */
-    typedef PoolItem                                    value_type;
-    typedef pool::PoolTraits::size_type                         size_type;
-    typedef pool::PoolTraits::const_iterator            const_iterator;
-
-    typedef pool::PoolTraits::byCapabilityIndex_iterator byCapabilityIndex_iterator;
-    typedef pool::PoolTraits::AdditionalCapabilities    AdditionalCapabilities;
-    typedef pool::PoolTraits::repository_iterator        repository_iterator;
-
-  public:
-    /** Singleton ctor. */
-    static ResPool instance();
-
-    /** preliminary */
-    ResPoolProxy proxy() const;
-
-  public:
-    /** The pools serial number. Changing whenever the
-     * whenever the content changes. (Resolvables or
-     * Dependencies).
-    */
-    const SerialNumber & serial() const;
-
-  public:
-    /**  */
-    bool empty() const;
-    /**  */
-    size_type size() const;
-
-    /** \name Iterate through all ResObjects (all kinds). */
-    //@{
-    /** */
-    const_iterator begin() const;
-    /** */
-    const_iterator end() const;
-    //@}
-
-  public:
-    /** Return the corresponding \ref PoolItem.
-     * Pool and sat pool should be in sync. Returns an empty
-     * \ref PoolItem if there is no corresponding \ref PoolItem.
-     * \see \ref PoolItem::satSolvable.
-    */
-    PoolItem find( const sat::Solvable & slv_r ) const;
-
-  public:
-    /** \name Iterate through all ResObjects of a certain kind. */
-    //@{
-    typedef zypp::resfilter::ByKind ByKind;
-    typedef filter_iterator<ByKind,const_iterator> byKind_iterator;
-
-    byKind_iterator byKindBegin( const ResKind & kind_r ) const
-    { return make_filter_begin( ByKind(kind_r), *this ); }
-
-    template<class _Res>
-    byKind_iterator byKindBegin() const
-    { return make_filter_begin( resfilter::byKind<_Res>(), *this ); }
-
-    byKind_iterator byKindEnd( const ResKind & kind_r ) const
-    { return make_filter_end( ByKind(kind_r), *this ); }
-
-    template<class _Res>
-    byKind_iterator byKindEnd() const
-    { return make_filter_end( resfilter::byKind<_Res>(), *this ); }
-    //@}
-
-  public:
-    /** \name Iterate through all ResObjects with a certain name (all kinds). */
-    //@{
-    typedef zypp::resfilter::ByName ByName;
-    typedef filter_iterator<ByName,const_iterator> byName_iterator;
-
-    byName_iterator byNameBegin( const std::string & name_r ) const
-    { return make_filter_begin( ByName(name_r), *this ); }
-
-    byName_iterator byNameEnd( const std::string & name_r ) const
-    { return make_filter_end( ByName(name_r), *this ); }
-    //@}
-
- public:
-   /** \name Iterate through all ResObjects which have at least
-    *  one Capability with index \a index_r in dependency \a depType_r.
-   */
-   //@{
-   byCapabilityIndex_iterator byCapabilityIndexBegin( const std::string & index_r, Dep depType_r ) const;
-
-   byCapabilityIndex_iterator byCapabilityIndexEnd( const std::string & index_r, Dep depType_r ) const;
-   //@}
-
- public:
-   /** \name Iterate through all Repositories that contribute ResObjects.
-   */
-   //@{
-   size_type knownRepositoriesSize() const;
-
-   repository_iterator knownRepositoriesBegin() const;
-
-   repository_iterator knownRepositoriesEnd() const;
-   //@}
-
- public:
-   /** \name Handling addition capabilities in the pool in order for solving it in
-    *  a solver run. This is used for tasks like needing a package with the name "foo".
-    *  The solver has to evaluate a proper package by his own.
-    *
-    *  CAUTION: This has another semantic in the solver. The required resolvable has
-    *  been set for installation (in the pool) only AFTER a solver run.
-   */
-
-   /**
-    *  Handling additional requirement. E.G. need package "foo" and package
-    *  "foo1" which has a greater version than 1.0:
-    *
-    *  \code
-    *  Capabilities capset;
-    *  capset.insert (CapFactory().parse( ResTraits<Package>::kind, "foo"));
-    *  capset.insert (CapFactory().parse( ResTraits<Package>::kind, "foo1 > 1.0"));
-    *
-    *  // The user is setting this capablility
-    *  ResPool::AdditionalCapabilities aCapabilities;
-    *  aCapabilities[ResStatus::USER] = capset;
-    *
-    *  setAdditionalRequire( aCapabilities );
-    *  \endcode
-    */
-   void setAdditionalRequire( const AdditionalCapabilities & capset ) const;
-   AdditionalCapabilities & additionalRequire() const;
-
-   /**
-    *  Handling additional conflicts. E.G. do not install anything which provides "foo":
-    *
-    *  \code75
-    *  Capabilities capset;
-    *  capset.insert (CapFactory().parse( ResTraits<Package>::kind, "foo"));
-    *
-    *  // The user is setting this capablility
-    *  ResPool::AdditionalCapabilities aCapabilities;
-    *  aCapabilities[ResStatus::USER] = capset;
-    *
-    *  setAdditionalConflict( aCapabilities );
-    *  \endcode
-    */
-   void setAdditionalConflict( const AdditionalCapabilities & capset ) const;
-   AdditionalCapabilities & additionaConflict() const;
-
-   /**
-    *  Handling additional provides. This is used for ignoring a requirement.
-    *  e.G. Do ignore the requirement "foo":
-    *
-    *  \code
-    *  Capabilities capset;
-    *  capset.insert (CapFactory().parse( ResTraits<Package>::kind, "foo"));
-    *
-    *  // The user is setting this capablility
-    *  ResPool::AdditionalCapabilities aCapabilities;
-    *  aCapabilities[ResStatus::USER] = capset;
-    *
-    *  setAdditionalProvide( aCapabilities );
-    *  \endcode
-    */
-   void setAdditionalProvide( const AdditionalCapabilities & capset ) const;
-   AdditionalCapabilities & additionaProvide() const;
-
-  private:
-    /** Ctor */
-    ResPool( pool::PoolTraits::Impl_constPtr impl_r );
-    /** Const access to implementation. */
-    pool::PoolTraits::Impl_constPtr _pimpl;
+    public:
+      /** \ref PoolItem */
+      typedef PoolItem                                  value_type;
+      typedef pool::PoolTraits::size_type                       size_type;
+      typedef pool::PoolTraits::const_iterator          const_iterator;
+
+      typedef pool::PoolTraits::byCapabilityIndex_iterator byCapabilityIndex_iterator;
+      typedef pool::PoolTraits::AdditionalCapabilities  AdditionalCapabilities;
+      typedef pool::PoolTraits::repository_iterator        repository_iterator;
+
+    public:
+      /** Singleton ctor. */
+      static ResPool instance();
+
+      /** preliminary */
+      ResPoolProxy proxy() const;
+
+    public:
+      /** The pools serial number. Changing whenever the
+       * whenever the content changes. (Resolvables or
+       * Dependencies).
+       */
+      const SerialNumber & serial() const;
+
+    public:
+      /**  */
+      bool empty() const;
+      /**  */
+      size_type size() const;
+
+      /** \name Iterate through all ResObjects (all kinds). */
+      //@{
+      /** */
+      const_iterator begin() const
+      { return make_filter_begin( pool::ByPoolItem(), store() ); }
+      /** */
+      const_iterator end() const
+      { return make_filter_end( pool::ByPoolItem(), store() ); }
+      //@}
+
+    public:
+      /** Return the corresponding \ref PoolItem.
+       * Pool and sat pool should be in sync. Returns an empty
+       * \ref PoolItem if there is no corresponding \ref PoolItem.
+       * \see \ref PoolItem::satSolvable.
+       */
+      PoolItem find( const sat::Solvable & slv_r ) const;
+
+    public:
+      /** \name Iterate through all ResObjects of a certain name and kind. */
+      //@{
+      template<class _Filter>
+          filter_iterator<_Filter,const_iterator> filterBegin( const _Filter & filter_r ) const
+      { return make_filter_begin( filter_r, *this ); }
+
+      template<class _Filter>
+          filter_iterator<_Filter,const_iterator> filterEnd( const _Filter & filter_r ) const
+      { return make_filter_end( filter_r, *this ); }
+      //@}
+
+    public:
+      /** \name Iterate through all ResObjects of a certain kind. */
+      //@{
+      typedef zypp::resfilter::ByKind ByKind;
+      typedef filter_iterator<ByKind,const_iterator> byKind_iterator;
+
+      byKind_iterator byKindBegin( const ResKind & kind_r ) const
+      { return make_filter_begin( ByKind(kind_r), *this ); }
+
+      template<class _Res>
+          byKind_iterator byKindBegin() const
+      { return make_filter_begin( resfilter::byKind<_Res>(), *this ); }
+
+      byKind_iterator byKindEnd( const ResKind & kind_r ) const
+      { return make_filter_end( ByKind(kind_r), *this ); }
+
+      template<class _Res>
+          byKind_iterator byKindEnd() const
+      { return make_filter_end( resfilter::byKind<_Res>(), *this ); }
+      //@}
+
+    public:
+      /** \name Iterate through all ResObjects with a certain name (all kinds). */
+      //@{
+      typedef zypp::resfilter::ByName ByName;
+      typedef filter_iterator<ByName,const_iterator> byName_iterator;
+
+      byName_iterator byNameBegin( const std::string & name_r ) const
+      { return make_filter_begin( ByName(name_r), *this ); }
+
+      byName_iterator byNameEnd( const std::string & name_r ) const
+      { return make_filter_end( ByName(name_r), *this ); }
+      //@}
+
+    public:
+      /** \name Iterate through all ResObjects which have at least
+       *  one Capability with index \a index_r in dependency \a depType_r.
+       */
+      //@{
+      byCapabilityIndex_iterator byCapabilityIndexBegin( const std::string & index_r, Dep depType_r ) const;
+
+      byCapabilityIndex_iterator byCapabilityIndexEnd( const std::string & index_r, Dep depType_r ) const;
+      //@}
+
+    public:
+      /** \name Iterate through all Repositories that contribute ResObjects.
+       */
+      //@{
+      size_type knownRepositoriesSize() const;
+
+      repository_iterator knownRepositoriesBegin() const;
+
+      repository_iterator knownRepositoriesEnd() const;
+      //@}
+
+    public:
+      /** \name Handling addition capabilities in the pool in order for solving it in
+       *  a solver run. This is used for tasks like needing a package with the name "foo".
+       *  The solver has to evaluate a proper package by his own.
+       *
+       *  CAUTION: This has another semantic in the solver. The required resolvable has
+       *  been set for installation (in the pool) only AFTER a solver run.
+       */
+
+      /**
+       *  Handling additional requirement. E.G. need package "foo" and package
+       *  "foo1" which has a greater version than 1.0:
+       *
+       *  \code
+       *  Capabilities capset;
+       *  capset.insert (CapFactory().parse( ResTraits<Package>::kind, "foo"));
+       *  capset.insert (CapFactory().parse( ResTraits<Package>::kind, "foo1 > 1.0"));
+       *
+       *  // The user is setting this capablility
+       *  ResPool::AdditionalCapabilities aCapabilities;
+       *  aCapabilities[ResStatus::USER] = capset;
+       *
+       *  setAdditionalRequire( aCapabilities );
+       *  \endcode
+       */
+      void setAdditionalRequire( const AdditionalCapabilities & capset ) const;
+      AdditionalCapabilities & additionalRequire() const;
+
+     /**
+       *  Handling additional conflicts. E.G. do not install anything which provides "foo":
+       *
+       *  \code75
+       *  Capabilities capset;
+       *  capset.insert (CapFactory().parse( ResTraits<Package>::kind, "foo"));
+       *
+       *  // The user is setting this capablility
+       *  ResPool::AdditionalCapabilities aCapabilities;
+       *  aCapabilities[ResStatus::USER] = capset;
+       *
+       *  setAdditionalConflict( aCapabilities );
+       *  \endcode
+       */
+      void setAdditionalConflict( const AdditionalCapabilities & capset ) const;
+      AdditionalCapabilities & additionaConflict() const;
+
+     /**
+       *  Handling additional provides. This is used for ignoring a requirement.
+       *  e.G. Do ignore the requirement "foo":
+       *
+       *  \code
+       *  Capabilities capset;
+       *  capset.insert (CapFactory().parse( ResTraits<Package>::kind, "foo"));
+       *
+       *  // The user is setting this capablility
+       *  ResPool::AdditionalCapabilities aCapabilities;
+       *  aCapabilities[ResStatus::USER] = capset;
+       *
+       *  setAdditionalProvide( aCapabilities );
+       *  \endcode
+       */
+      void setAdditionalProvide( const AdditionalCapabilities & capset ) const;
+      AdditionalCapabilities & additionaProvide() const;
+
+    private:
+      const pool::PoolTraits::ItemContainerT & store() const;
+
+    private:
+      /** Ctor */
+      ResPool( pool::PoolTraits::Impl_constPtr impl_r );
+      /** Const access to implementation. */
+      pool::PoolTraits::Impl_constPtr _pimpl;
   };
   ///////////////////////////////////////////////////////////////////
 
index 1dab871..7224ef2 100644 (file)
@@ -13,7 +13,6 @@
 #include "zypp/base/LogTools.h"
 
 #include "zypp/pool/PoolImpl.h"
-#include "zypp/pool/PoolStats.h"
 #include "zypp/Package.h"
 #include "zypp/VendorAttr.h"
 
@@ -57,17 +56,6 @@ namespace zypp
     PoolImpl::~PoolImpl()
     {}
 
-    /******************************************************************
-    **
-    ** FUNCTION NAME : operator<<
-    ** FUNCTION TYPE : std::ostream &
-    */
-    std::ostream & operator<<( std::ostream & str, const PoolImpl & obj )
-    {
-      return dumpPoolStats( str << "ResPool " << obj.satpool() << endl << "  ",
-                            obj.begin(), obj.end() );
-    }
-
     /////////////////////////////////////////////////////////////////
   } // namespace pool
   ///////////////////////////////////////////////////////////////////
index c9b2f75..c3aef9a 100644 (file)
@@ -24,6 +24,8 @@
 
 #include "zypp/sat/Pool.h"
 
+using std::endl;
+
 ///////////////////////////////////////////////////////////////////
 namespace zypp
 { /////////////////////////////////////////////////////////////////
@@ -78,14 +80,6 @@ namespace zypp
         size_type size() const
         { return satpool().solvablesSize(); }
 
-        /** */
-        const_iterator begin() const
-        { return make_map_value_begin( store() ); }
-
-        /** */
-        const_iterator end() const
-        { return make_map_value_end( store() ); }
-
       public:
         /** Return the corresponding \ref PoolItem.
          * Pool and sat pool should be in sync. Returns an empty
@@ -94,11 +88,7 @@ namespace zypp
          */
         PoolItem find( const sat::Solvable & slv_r ) const
         {
-          const ContainerT & c( store() );
-          ContainerT::const_iterator it( c.find( slv_r ) );
-          if ( it != c.end() )
-            return it->second;
-          return PoolItem();
+          return store()[slv_r.id()];
         }
 
         ///////////////////////////////////////////////////////////////////
@@ -180,13 +170,11 @@ namespace zypp
           if ( ! _knownRepositoriesPtr )
           {
             _knownRepositoriesPtr.reset( new KnownRepositories );
-            const ContainerT & c( store() );
-            for_( it, c.begin(), c.end() )
+
+            sat::Pool pool( satpool() );
+            for_( it, pool.reposBegin(), pool.reposEnd() )
             {
-              if ( (*it).second->repository() != Repository::noRepository )
-              {
-                _knownRepositoriesPtr->insert( (*it).second->repository() );
-              }
+              _knownRepositoriesPtr->push_back( Repository( it->info() ) );
             }
           }
           return *_knownRepositoriesPtr;
@@ -195,12 +183,32 @@ namespace zypp
         ///////////////////////////////////////////////////////////////////
         //
         ///////////////////////////////////////////////////////////////////
-      private:
+      public:
         const ContainerT & store() const
         {
           checkSerial();
           if ( _storeDirty )
           {
+            sat::Pool pool( satpool() );
+
+            if ( pool.capacity() != _store.capacity() )
+            {
+              _store.resize( pool.capacity() );
+            }
+
+            if ( pool.capacity() )
+            {
+              for ( sat::detail::SolvableIdType i = pool.capacity()-1; i != 0; --i )
+              {
+                sat::Solvable s( i );
+                PoolItem & pi( _store[i] );
+                if ( ! s &&  pi )
+                  pi = PoolItem();
+                else if ( s && ! pi )
+                  pi = PoolItem( s );
+              }
+            }
+#if 0
             // pass 1: delete no longer existing solvables
             for ( ContainerT::iterator it = _store.begin(); it != _store.end(); /**/ )
             {
@@ -223,7 +231,7 @@ namespace zypp
                 }
               }
             }
-
+#endif
             _storeDirty = false;
           }
           return _store;
@@ -266,9 +274,6 @@ namespace zypp
     };
     ///////////////////////////////////////////////////////////////////
 
-    /** \relates PoolImpl Stream output */
-    std::ostream & operator<<( std::ostream & str, const PoolImpl & obj );
-
     /////////////////////////////////////////////////////////////////
   } // namespace pool
   ///////////////////////////////////////////////////////////////////
index 6d1a650..4f99546 100644 (file)
@@ -33,6 +33,12 @@ namespace zypp
 
     class PoolImpl;
 
+    struct ByPoolItem
+    {
+      bool operator()( const PoolItem & pi ) const
+      { return pi; }
+    };
+
     ///////////////////////////////////////////////////////////////////
     //
     // CLASS NAME : PoolTraits
@@ -43,9 +49,15 @@ namespace zypp
     public:
       typedef sat::detail::SolvableIdType              SolvableIdType;
       /** pure items  */
-      typedef std::map<sat::Solvable,PoolItem>         ItemContainerT;
-      typedef MapKVIteratorTraits<ItemContainerT>::Value_const_iterator
-                                                       const_iterator;
+#if 0
+       typedef std::map<sat::Solvable,PoolItem>                ItemContainerT;
+       typedef MapKVIteratorTraits<ItemContainerT>::Value_const_iterator
+                                                               const_iterator;
+#endif
+      typedef std::vector<PoolItem>                    ItemContainerT;
+      typedef ItemContainerT::const_iterator            item_iterator;
+      typedef filter_iterator<ByPoolItem,ItemContainerT::const_iterator>
+                                                       const_iterator;
       typedef ItemContainerT::size_type                        size_type;
 
       // internal organization
@@ -60,7 +72,7 @@ namespace zypp
       typedef const_capitemiterator                     byCapabilityIndex_iterator;
 
       /* list of known Repositories */
-      typedef std::set<Repository>                      RepoContainerT;
+      typedef std::list<Repository>                     RepoContainerT;
       typedef RepoContainerT::const_iterator           repository_iterator;
 
       typedef PoolImpl                   Impl;