← Back to team overview

zorba-coders team mailing list archive

[Merge] lp:~zorba-coders/zorba/abstract-collection-set into lp:zorba

 

Ghislain Fourny has proposed merging lp:~zorba-coders/zorba/abstract-collection-set into lp:zorba.

Requested reviews:
  Matthias Brantner (matthias-brantner)

For more details, see:
https://code.launchpad.net/~zorba-coders/zorba/abstract-collection-set/+merge/94384

Refactored CollectionSet class. zorba::store::CollectionSet is abstract, zorba::simplestore::SimpleCollectionSet is its implementation for the simple store.
-- 
https://code.launchpad.net/~zorba-coders/zorba/abstract-collection-set/+merge/94384
Your team Zorba Coders is subscribed to branch lp:zorba.
=== renamed file 'src/store/naive/collection_set.h' => 'src/store/api/collection_set.h'
--- src/store/naive/collection_set.h	2011-06-14 17:26:33 +0000
+++ src/store/api/collection_set.h	2012-02-23 14:28:19 +0000
@@ -23,88 +23,64 @@
 
 namespace zorba {
   
-  namespace simplestore {
+  namespace store {
 
     class CollectionIterator;
     
     /*******************************************************************************
       Collections container to ease the implementation of stores which contain 
-      a different kind of memory management. For the simplestore, the Collections
-      is only a wrapper class around an ItemPointerHashMap.
+      a different kind of memory management.
     ********************************************************************************/
     class CollectionSet
     {
     public:
-      typedef ItemPointerHashMap<store::Collection_t> Set;
-      static const ulong DEFAULT_COLLECTION_MAP_SIZE;
-    
-    protected:
-      Set  theCollections;
-    
-    public:
-      CollectionSet();
-    
-      // needs to be virtual to allow implementation of additional stores
+      virtual ~CollectionSet() {}
+      
       virtual void
-      clear();
+      clear() = 0;
     
-      // needs to be virtual to allow implementation of additional stores
       virtual bool
       insert(
-          const store::Item* aName,
-          store::Collection_t& aCollection);
+          const Item* aName,
+          Collection_t& aCollection) = 0;
     
-      // needs to be virtual to allow implementation of additional stores
       virtual bool
       get(
           const store::Item* aName,
-          store::Collection_t& aCollection,
-          bool aDynamicCollection = false);
+          Collection_t& aCollection,
+          bool aDynamicCollection = false) = 0;
     
-      // needs to be virtual to allow implementation of additional stores
       virtual bool
-      remove(const store::Item* aName, bool aDynamicCollection = false);
-    
-      // needs to be virtual to allow implementation of additional stores
-      virtual store::Iterator_t
-      names(bool aDynamicCollection = false);
-    
-      // needs to be virtual to allow implementation of additional stores
-      virtual CollectionIterator_t
-      collections(bool aDynamicCollection = false);
+      remove(const Item* aName, bool aDynamicCollection = false) = 0;
+    
+      virtual Iterator_t
+      names(bool aDynamicCollection = false) = 0;
+    
+      virtual CollectionSetIterator_t
+      collections(bool aDynamicCollection = false) = 0;
     
     }; /* class CollectionSet */
     
     /*******************************************************************************
-      Collection iterator
+      Collection set iterator
       Returned by the CollectionSet::collections function
     ********************************************************************************/
-    class CollectionIterator : public SimpleRCObject
+    class CollectionSetIterator : public SimpleRCObject
     {
-    protected:
-      CollectionSet::Set*          theCollections;
-      CollectionSet::Set::iterator theIterator;
-      bool                         theOpened;
-      bool                         theDynamicCollections;
-    
     public:
-      CollectionIterator(
-          CollectionSet::Set* aCollections,
-          bool aDynamicCollections);
-    
-      virtual ~CollectionIterator();
+      virtual ~CollectionSetIterator() {}
     
       virtual void
-      open();
+      open() = 0;
     
       virtual bool
-      next(store::Collection_t&);
-    
-      virtual void
-      reset();
-    
-      virtual void
-      close();
+      next(Collection_t&) = 0;
+    
+      virtual void
+      reset() = 0;
+    
+      virtual void
+      close() = 0;
     };
 
   } /* namespace simplestore */

=== modified file 'src/store/api/shared_types.h'
--- src/store/api/shared_types.h	2011-12-21 14:40:33 +0000
+++ src/store/api/shared_types.h	2012-02-23 14:28:19 +0000
@@ -68,6 +68,11 @@
 class Collection;
 typedef rchandle<Collection> Collection_t;
 
+class CollectionSet;
+
+class CollectionSetIterator;
+typedef rchandle<CollectionSetIterator> CollectionSetIterator_t;
+
 class Index;
 typedef rchandle<Index> Index_t;
 

=== modified file 'src/store/naive/CMakeLists.txt'
--- src/store/naive/CMakeLists.txt	2011-06-22 17:30:15 +0000
+++ src/store/naive/CMakeLists.txt	2012-02-23 14:28:19 +0000
@@ -31,7 +31,7 @@
     simple_store.cpp
     simple_iterator_factory.cpp
     simple_collection.cpp
-    collection_set.cpp
+    simple_collection_set.cpp
     simple_index.cpp
     simple_index_value.cpp
     simple_index_general.cpp

=== modified file 'src/store/naive/shared_types.h'
--- src/store/naive/shared_types.h	2011-10-06 20:55:03 +0000
+++ src/store/naive/shared_types.h	2012-02-23 14:28:19 +0000
@@ -33,10 +33,6 @@
 class AtomicItem;
 typedef store::ItemHandle<AtomicItem> AtomicItem_t;
 
-class CollectionSet;
-class CollectionIterator;
-typedef rchandle<CollectionIterator> CollectionIterator_t;
-
 class XmlTree;
 typedef rchandle<XmlTree> XmlTree_t;
 
@@ -46,7 +42,6 @@
 class IndexImpl;
 typedef rchandle<IndexImpl> IndexImpl_t;
 
-
 typedef rchandle<store::IndexEntryCreator> IndexEntryCreator_t;
 
 

=== renamed file 'src/store/naive/collection_set.cpp' => 'src/store/naive/simple_collection_set.cpp'
--- src/store/naive/collection_set.cpp	2012-02-15 10:25:02 +0000
+++ src/store/naive/simple_collection_set.cpp	2012-02-23 14:28:19 +0000
@@ -15,7 +15,7 @@
  */
 #include "stdafx.h"
 
-#include "collection_set.h"
+#include "simple_collection_set.h"
 #include "store/api/iterator.h"
 #include "name_iterator.h"
 
@@ -24,8 +24,8 @@
 /*******************************************************************************
 
 ********************************************************************************/
-CollectionIterator::CollectionIterator(
-    CollectionSet::Set* aCollections,
+SimpleCollectionSetIterator::SimpleCollectionSetIterator(
+    SimpleCollectionSet::Set* aCollections,
     bool aDynamicCollection) 
   : 
   theCollections(aCollections),
@@ -35,14 +35,14 @@
 }
 
 
-CollectionIterator::~CollectionIterator()
+SimpleCollectionSetIterator::~SimpleCollectionSetIterator()
 {
   close();
 }
 
 
 void
-CollectionIterator::open()
+SimpleCollectionSetIterator::open()
 {
   theIterator = theCollections->begin();
   theOpened = true;
@@ -50,7 +50,7 @@
 
 
 bool
-CollectionIterator::next(store::Collection_t& aResult) 
+SimpleCollectionSetIterator::next(zorba::store::Collection_t& aResult) 
 {
   while (theIterator != theCollections->end()) 
   {
@@ -69,14 +69,14 @@
 
 
 void
-CollectionIterator::reset()
+SimpleCollectionSetIterator::reset()
 {
   theIterator = theCollections->begin();
 }
 
 
 void
-CollectionIterator::close()
+SimpleCollectionSetIterator::close() throw()
 {
   if (!theOpened) {
     return;
@@ -88,23 +88,29 @@
 /*******************************************************************************
 
 ********************************************************************************/
-const ulong CollectionSet::DEFAULT_COLLECTION_MAP_SIZE = 32;
-
-
-CollectionSet::CollectionSet()
+const ulong SimpleCollectionSet::DEFAULT_COLLECTION_MAP_SIZE = 32;
+
+
+SimpleCollectionSet::SimpleCollectionSet()
   :
   theCollections(0, NULL, DEFAULT_COLLECTION_MAP_SIZE, true)
 {
 }
 
 
-void CollectionSet::clear() 
+SimpleCollectionSet::~SimpleCollectionSet()
+{
+}
+
+
+void SimpleCollectionSet::clear() 
 {
   theCollections.clear();
 }
 
 
-bool CollectionSet::insert(const store::Item* aName, store::Collection_t& aCollection)
+bool SimpleCollectionSet::insert(const zorba::store::Item* aName,
+                                 zorba::store::Collection_t& aCollection)
 {
   store::Item* qname = const_cast<store::Item*>(aName);
 
@@ -112,12 +118,12 @@
 }
 
 
-bool CollectionSet::get(
-    const store::Item* aName,
-    store::Collection_t& aCollection,
+bool SimpleCollectionSet::get(
+    const zorba::store::Item* aName,
+    zorba::store::Collection_t& aCollection,
     bool aDynamicCollection) 
 {
-  if (theCollections.get(const_cast<store::Item*>(aName), aCollection)) 
+  if (theCollections.get(const_cast<zorba::store::Item*>(aName), aCollection)) 
   {
     return aCollection->isDynamic() == aDynamicCollection;
   }
@@ -128,35 +134,36 @@
 }
 
 
-bool CollectionSet::remove(const store::Item* aName, bool aDynamicCollection) 
+bool SimpleCollectionSet::remove(const zorba::store::Item* aName, bool aDynamicCollection) 
 {
-  store::Collection_t lColl;
+  zorba::store::Collection_t lColl;
   if (!get(aName, lColl, aDynamicCollection))
   {
     return false;
   }
   else
   {
-    return theCollections.erase(const_cast<store::Item*>(aName));
+    return theCollections.erase(const_cast<zorba::store::Item*>(aName));
   }
 }
 
 
-store::Iterator_t CollectionSet::names(bool aDynamicCollections) 
+zorba::store::Iterator_t SimpleCollectionSet::names(bool aDynamicCollections) 
 {
   return new NameIterator<Set>(theCollections, aDynamicCollections);
 }
 
 
-CollectionIterator_t CollectionSet::collections(bool aDynamicCollections) 
+zorba::store::CollectionSetIterator_t SimpleCollectionSet::collections(bool aDynamicCollections) 
 {
-  return new CollectionIterator(&theCollections, aDynamicCollections);
+  return new SimpleCollectionSetIterator(&theCollections,
+                                         aDynamicCollections);
 }
 
 // specialize the next function of the NameIterator for
-// the CollectionSet in order to be able to handle dynamic collections
+// the SimpleCollectionSet in order to be able to handle dynamic collections
 template<> bool
-NameIterator<CollectionSet::Set>::next(store::Item_t& aResult)
+NameIterator<SimpleCollectionSet::Set>::next(zorba::store::Item_t& aResult)
 {
   while (theIterator != theItems.end())
   {

=== modified file 'src/store/naive/simple_store.cpp'
--- src/store/naive/simple_store.cpp	2012-02-15 10:25:02 +0000
+++ src/store/naive/simple_store.cpp	2012-02-23 14:28:19 +0000
@@ -37,7 +37,7 @@
 #include "simple_temp_seq.h"
 #include "simple_lazy_temp_seq.h"
 #include "simple_collection.h"
-#include "collection_set.h"
+#include "simple_collection_set.h"
 #include "simple_index.h"
 #include "simple_index_value.h"
 #include "simple_index_general.h"
@@ -79,6 +79,10 @@
   SimpleStore static data
 ********************************************************************************/
 const ulong SimpleStore::NAMESPACE_POOL_SIZE = 128;
+const ulong SimpleStore::DEFAULT_DOCUMENT_SET_SIZE = 32;
+const ulong SimpleStore::DEFAULT_URI_COLLECTION_SET_SIZE = 32;
+const ulong SimpleStore::DEFAULT_INDICES_SET_SIZE = 32;
+const ulong SimpleStore::DEFAULT_INTEGRITY_CONSTRAINT_SET_SIZE = 32;
 
 const char* SimpleStore::XS_URI = "http://www.w3.org/2001/XMLSchema";;
 const char* SimpleStore::XML_URI = "http://www.w3.org/2001/XML/1998/namespace";;
@@ -102,11 +106,11 @@
   theIteratorFactory(NULL),
   theNodeFactory(NULL),
   thePULFactory(NULL),
-  theDocuments(CollectionSet::DEFAULT_COLLECTION_MAP_SIZE, true),
+  theDocuments(DEFAULT_DOCUMENT_SET_SIZE, true),
   theCollections(0),
-  theIndices(0, NULL, CollectionSet::DEFAULT_COLLECTION_MAP_SIZE, true),
-  theICs(0, NULL, CollectionSet::DEFAULT_COLLECTION_MAP_SIZE, true),
-  theHashMaps(0, NULL, CollectionSet::DEFAULT_COLLECTION_MAP_SIZE, true),
+  theIndices(0, NULL, DEFAULT_INDICES_SET_SIZE, true),
+  theICs(0, NULL, DEFAULT_INTEGRITY_CONSTRAINT_SET_SIZE, true),
+  theHashMaps(0, NULL, DEFAULT_INDICES_SET_SIZE, true),
   theTraceLevel(0),
   theNodeToReferencesMap(128, true)
 #ifndef ZORBA_NO_FULL_TEXT
@@ -400,16 +404,16 @@
 /*******************************************************************************
 
 *******************************************************************************/
-CollectionSet* SimpleStore::createCollectionSet() const
+zorba::store::CollectionSet* SimpleStore::createCollectionSet() const
 {
-  return new CollectionSet();
+  return new SimpleCollectionSet();
 }
 
 
 /*******************************************************************************
 
 *******************************************************************************/
-void SimpleStore::destroyCollectionSet(CollectionSet* c) const
+void SimpleStore::destroyCollectionSet(zorba::store::CollectionSet* c) const
 {
   delete c;
 }

=== modified file 'src/store/naive/simple_store.h'
--- src/store/naive/simple_store.h	2012-01-10 10:52:15 +0000
+++ src/store/naive/simple_store.h	2012-02-23 14:28:19 +0000
@@ -143,6 +143,10 @@
 
 protected:
   static const ulong NAMESPACE_POOL_SIZE;
+  static const ulong DEFAULT_DOCUMENT_SET_SIZE;
+  static const ulong DEFAULT_URI_COLLECTION_SET_SIZE;
+  static const ulong DEFAULT_INDICES_SET_SIZE;
+  static const ulong DEFAULT_INTEGRITY_CONSTRAINT_SET_SIZE;
 
 public:
   zstring                       theEmptyNs;
@@ -175,7 +179,7 @@
   PULPrimitiveFactory         * thePULFactory;
 
   DocumentSet                   theDocuments;
-  CollectionSet*                theCollections;
+  zorba::store::CollectionSet*  theCollections;
   IndexSet                      theIndices;
   ICSet                         theICs;
   IndexSet                      theHashMaps;
@@ -415,9 +419,9 @@
 
   virtual void destroyPULPrimitiveFactory(PULPrimitiveFactory*) const;
 
-  virtual CollectionSet* createCollectionSet() const;
+  virtual zorba::store::CollectionSet* createCollectionSet() const;
 
-  virtual void destroyCollectionSet(CollectionSet*) const;
+  virtual void destroyCollectionSet(zorba::store::CollectionSet*) const;
 
 #ifndef ZORBA_NO_FULL_TEXT
   TokenizerProvider const* getTokenizerProvider() const;


Follow ups