Index: src/Fragmentation/Summation/IndexSetContainer.hpp
===================================================================
--- src/Fragmentation/Summation/IndexSetContainer.hpp	(revision 063fab36c8b0361e5f0a8e75f076b674379ba00f)
+++ src/Fragmentation/Summation/IndexSetContainer.hpp	(revision 063fab36c8b0361e5f0a8e75f076b674379ba00f)
@@ -0,0 +1,70 @@
+/*
+ * IndexSetContainer.hpp
+ *
+ *  Created on: Jul 3, 2012
+ *      Author: heber
+ */
+
+#ifndef INDEXSETCONTAINER_HPP_
+#define INDEXSETCONTAINER_HPP_
+
+
+// include config.h
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <boost/shared_ptr.hpp>
+#include <vector>
+
+#include "IndexSet.hpp"
+#include "SortedVector.hpp"
+
+class IndexSetContainerTest;
+
+/**
+  * As the IndexSet is supposed to appear in many maps and Containers as it may
+  * be contained in other IndexSet's, we store it always as a shared_ptr. This
+  * Container is then responsible that the ordering within the container still
+  * allows for fast access due to sorted appearance not by order in memory but
+  * order defined by IndexSet comparison operators.
+  *
+  */
+
+//!> typedef for IndexSet instances stored in SortedVector
+class IndexSetContainer : public SortedVector<IndexSet> {
+  //!> grant unit test access to protected members of SortedVector
+  friend class IndexSetContainerTest;
+public:
+  //!> typedef for IndexSetContainer wrapped in shared_ptr
+  typedef boost::shared_ptr<IndexSetContainer> ptr;
+
+  /** Constructor from an unsorted vector of instances.
+   *
+   * @param _container unsorted vector of instances
+   */
+  IndexSetContainer(const SortedVector<IndexSet>::Container_t &_container) :
+    SortedVector<IndexSet>(_container)
+  {}
+
+  /** Constructor from an unsorted vector of instances.
+   *
+   * @param _container unsorted vector of instances
+   */
+  IndexSetContainer(const std::vector<IndexSet> &_container) :
+    SortedVector<IndexSet>(_container)
+  {}
+
+  /** Constructor from a single instance.
+   *
+   * @param _instance single instance
+   */
+  IndexSetContainer(IndexSet::ptr &_instance) :
+    SortedVector<IndexSet>(_instance)
+  {}
+};
+//!> typedef for IndexSet instance stored as shared_ptr in SortedVector
+typedef IndexSetContainer::T_ptr IndexSet_ptr;
+
+
+#endif /* INDEXSETCONTAINER_HPP_ */
Index: src/Fragmentation/Summation/Makefile.am
===================================================================
--- src/Fragmentation/Summation/Makefile.am	(revision 146c26d1db374118e51291a5034fccfd78aaee7d)
+++ src/Fragmentation/Summation/Makefile.am	(revision 063fab36c8b0361e5f0a8e75f076b674379ba00f)
@@ -14,5 +14,7 @@
 
 FRAGMENTATIONSUMMATIONHEADER = \
-	IndexSet.hpp
+	IndexSet.hpp \
+	IndexSetContainer.hpp \
+	SortedVector.hpp
 
 
Index: src/Fragmentation/Summation/SortedVector.hpp
===================================================================
--- src/Fragmentation/Summation/SortedVector.hpp	(revision 063fab36c8b0361e5f0a8e75f076b674379ba00f)
+++ src/Fragmentation/Summation/SortedVector.hpp	(revision 063fab36c8b0361e5f0a8e75f076b674379ba00f)
@@ -0,0 +1,164 @@
+/*
+ * SortedVector.hpp
+ *
+ *  Created on: Jul 3, 2012
+ *      Author: heber
+ */
+
+#ifndef SORTEDVECTOR_HPP_
+#define SORTEDVECTOR_HPP_
+
+
+// include config.h
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <algorithm>
+#include <boost/lambda/lambda.hpp>
+#include <boost/shared_ptr.hpp>
+#include <boost/bind.hpp>
+#include <vector>
+
+/** Functor for transforming instance of type T to copies contained in shared_ptr.
+ *
+ */
+template <typename T>
+struct SharedPtrAllocator {
+  boost::shared_ptr<T> operator()(const T& a) {
+    return boost::shared_ptr<T>( new T(a) );
+  }
+};
+
+
+/** This class represents a general sorted container of instances, stored as shared_ptr.
+ *
+ *  These instances are stored in order not by appearance memory due to shared_ptr but
+ *  by the comparison operators of the underlying type.
+ *
+ *  The sorted vector is truely a sorted vector. Hence, we must access often but change
+ *  only seldomly. This is due to item#23 in [Meyers, "Effective STL"].
+ *
+ */
+template <typename T>
+struct SortedVector
+{
+  typedef typename T::ptr T_ptr;
+  typedef std::vector<T_ptr> Container_t;
+public:
+  /** Constructor from an unsorted vector of instances.
+   *
+   * @param _container unsorted vector of instances
+   */
+  SortedVector(const Container_t &_container) :
+    ContainerSorted(false),
+    container(_container)
+  {
+    sort();
+  }
+
+  /** Constructor from an unsorted vector of instances.
+   *
+   * @param _container unsorted vector of instances
+   */
+  SortedVector(const std::vector<T> &_container) :
+    ContainerSorted(false)
+  {
+    container.resize(_container.size());
+    SharedPtrAllocator<T> allocator;
+    std::transform(_container.begin(), _container.end(),
+        container.begin(), allocator);
+    sort();
+  }
+
+  /** Constructor from a single instance.
+   *
+   * A single instance is automatically sorted.
+   *
+   * @param _instance single instance
+   */
+  SortedVector(T_ptr &_instance) :
+    ContainerSorted(true)
+  {
+    container.push_back(_instance);
+  }
+
+  /** Getter to sorted container.
+   *
+   * This getter is made const only through the virtue of making the member
+   * variables mutable. This is however the only sensible way as to the outside
+   * the container must be treatable as const despite "lazy" resorting on this
+   * read-only access in the background.
+   *
+   * @return const ref to internal sorted container
+   */
+  const Container_t &getContainer() const {
+    if (!ContainerSorted)
+      sort();
+    return container;
+  }
+
+  /** Insert a shared_ptr instance
+   *
+   * We lazily set the container to not sorted, it is sorted on next access.
+   *
+   * @param a instance to insert
+   */
+  void insert(T_ptr &a) {
+    // check if present via binary_search
+    if (!std::binary_search(container.begin(), container.end(), a, Comparator)) {
+      // only insert if not present
+      container.push_back(a);
+      ContainerSorted = false;
+    }
+  }
+
+  /** Insert an instance not wrapped in shared_ptr.
+   *
+   * We lazily set the container to not sorted, it is sorted on next access.
+   *
+   * @param a instance to copy and insert
+   */
+  void insert(const T &a) {
+    T_ptr ptr(new IndexSet(a));
+    // check if present via binary_search
+    if (!std::binary_search(container.begin(), container.end(), ptr, Comparator)) {
+      // only insert if not present
+      container.push_back(ptr);
+      ContainerSorted = false;
+    }
+  }
+
+  /** Internal static Comparator function, passing the check on to comparison
+   *  operator of underlying type.
+   * @param a First instance
+   * @param b Second instance
+   * @return pointee of a < pointee of b
+   */
+  struct Comparator_t {
+    bool operator()(const T_ptr &a, const T_ptr &b) const {
+      return *a < *b;
+    }
+  } Comparator;
+
+private:
+  /** Internal sort function.
+   *
+   */
+  void sort() const {
+    std::sort(container.begin(), container.end(), Comparator);
+    ContainerSorted = true;
+  }
+
+protected:
+  //!> internal flag that container is currently sorted, mutable to let getContainer() be const member function
+  mutable bool ContainerSorted;
+
+private:
+  //!> internal container that is always sorted, mutable to let getContainer() be const member function
+  mutable Container_t container;
+};
+
+
+
+#endif /* SORTEDVECTOR_HPP_ */
Index: src/Fragmentation/Summation/unittests/IndexSetContainerUnitTest.cpp
===================================================================
--- src/Fragmentation/Summation/unittests/IndexSetContainerUnitTest.cpp	(revision 063fab36c8b0361e5f0a8e75f076b674379ba00f)
+++ src/Fragmentation/Summation/unittests/IndexSetContainerUnitTest.cpp	(revision 063fab36c8b0361e5f0a8e75f076b674379ba00f)
@@ -0,0 +1,139 @@
+/*
+ * Project: MoleCuilder
+ * Description: creates and alters molecular systems
+ * Copyright (C) 2012 University of Bonn. All rights reserved.
+ * 
+ *
+ *   This file is part of MoleCuilder.
+ *
+ *    MoleCuilder is free software: you can redistribute it and/or modify
+ *    it under the terms of the GNU General Public License as published by
+ *    the Free Software Foundation, either version 2 of the License, or
+ *    (at your option) any later version.
+ *
+ *    MoleCuilder is distributed in the hope that it will be useful,
+ *    but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *    GNU General Public License for more details.
+ *
+ *    You should have received a copy of the GNU General Public License
+ *    along with MoleCuilder.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+/*
+ * IndexSetContainerUnitTest.cpp
+ *
+ *  Created on: Jul 3, 2012
+ *      Author: heber
+ */
+
+// include config.h
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+using namespace std;
+
+#include <cppunit/CompilerOutputter.h>
+#include <cppunit/extensions/TestFactoryRegistry.h>
+#include <cppunit/ui/text/TestRunner.h>
+
+#include "Fragmentation/Summation/IndexSetContainer.hpp"
+
+#include "IndexSetContainerUnitTest.hpp"
+
+#include <boost/assign.hpp>
+#include <boost/foreach.hpp>
+
+#ifdef HAVE_TESTRUNNER
+#include "UnitTestMain.hpp"
+#endif /*HAVE_TESTRUNNER*/
+
+using namespace boost::assign;
+
+/********************************************** Test classes **************************************/
+
+// Registers the fixture into the 'registry'
+CPPUNIT_TEST_SUITE_REGISTRATION( IndexSetContainerTest );
+
+
+void IndexSetContainerTest::setUp()
+{
+  allsets.reserve(5);
+  IndexSet tempset;
+  tempset += 1;
+  allsets += tempset;
+  tempset += 2;
+  allsets += tempset;
+  tempset.clear();
+  tempset += 3;
+  allsets += tempset;
+  tempset += 2;
+  allsets += tempset;
+  tempset += 4;
+  allsets += tempset;
+  tempset += 1;
+  allsets += tempset;
+  CPPUNIT_ASSERT_EQUAL( (size_t)6, allsets.size() );
+
+  SV = NULL;
+}
+
+
+void IndexSetContainerTest::tearDown()
+{
+  allsets.clear();
+  delete SV;
+}
+
+/** UnitTest for constructor
+ */
+void IndexSetContainerTest::constructorTest()
+{
+  SV = new IndexSetContainer(allsets);
+  // check that container is sorted
+  const IndexSetContainer::Container_t &container = SV->getContainer();
+//  BOOST_FOREACH( IndexSet_ptr a, container) {
+//    std::cout << *a << "\t";
+//  }
+//  std::cout << endl;
+  CPPUNIT_ASSERT_EQUAL( (size_t)6, container.size() );
+}
+
+
+/** UnitTest for operator==,!=,<,>()
+ */
+void IndexSetContainerTest::comparatorTest()
+{
+  SV = new IndexSetContainer(allsets);
+  // check that container is sorted
+  typedef IndexSetContainer::Container_t::const_iterator iterator;
+  const IndexSetContainer::Container_t &container = SV->getContainer();
+  iterator frontiter = ++(container.begin());
+  for (iterator backiter = container.begin();
+      frontiter != container.end(); ++backiter, ++frontiter) {
+    //std::cout << **backiter << " < " << **frontiter << std::endl;
+    CPPUNIT_ASSERT( **backiter < **frontiter );
+  }
+}
+
+/** Unit tests for insert()
+ *
+ */
+void IndexSetContainerTest::insertTest()
+{
+  SV = new IndexSetContainer(allsets);
+  IndexSet_ptr tempset(new IndexSet);
+  (*tempset) += 1,2,3,4;
+
+  // insert present set and check that it is still sorted
+  CPPUNIT_ASSERT( SV->ContainerSorted );
+  SV->insert(tempset);
+  CPPUNIT_ASSERT( SV->ContainerSorted );
+
+  // insert new set and check that it is now unsorted
+  (*tempset) += 5;
+  CPPUNIT_ASSERT( SV->ContainerSorted );
+  SV->insert(tempset);
+  CPPUNIT_ASSERT( !SV->ContainerSorted );
+}
Index: src/Fragmentation/Summation/unittests/IndexSetContainerUnitTest.hpp
===================================================================
--- src/Fragmentation/Summation/unittests/IndexSetContainerUnitTest.hpp	(revision 063fab36c8b0361e5f0a8e75f076b674379ba00f)
+++ src/Fragmentation/Summation/unittests/IndexSetContainerUnitTest.hpp	(revision 063fab36c8b0361e5f0a8e75f076b674379ba00f)
@@ -0,0 +1,46 @@
+/*
+ * IndexSetContainerUnitTest.hpp
+ *
+ *  Created on: Jul 3, 2012
+ *      Author: heber
+ */
+
+#ifndef INDEXSETCONTAINERUNITTEST_HPP_
+#define INDEXSETCONTAINERUNITTEST_HPP_
+
+// include config.h
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+
+#include <cppunit/extensions/HelperMacros.h>
+
+#include <vector>
+
+#include "IndexSet.hpp"
+#include "IndexSetContainer.hpp"
+
+/********************************************** Test classes **************************************/
+
+class IndexSetContainerTest : public CppUnit::TestFixture
+{
+    CPPUNIT_TEST_SUITE( IndexSetContainerTest) ;
+    CPPUNIT_TEST ( constructorTest );
+    CPPUNIT_TEST ( comparatorTest );
+    CPPUNIT_TEST ( insertTest );
+    CPPUNIT_TEST_SUITE_END();
+
+public:
+      void setUp();
+      void tearDown();
+      void constructorTest();
+      void comparatorTest();
+      void insertTest();
+
+private:
+      IndexSetContainer *SV;
+      std::vector<IndexSet> allsets;
+};
+
+#endif /* INDEXSETCONTAINERUNITTEST_HPP_ */
Index: src/Fragmentation/Summation/unittests/Makefile.am
===================================================================
--- src/Fragmentation/Summation/unittests/Makefile.am	(revision 146c26d1db374118e51291a5034fccfd78aaee7d)
+++ src/Fragmentation/Summation/unittests/Makefile.am	(revision 063fab36c8b0361e5f0a8e75f076b674379ba00f)
@@ -8,11 +8,14 @@
 
 FRAGMENTATIONSUMMATIONTESTSSOURCES = \
-	../Fragmentation/unittests/IndexSetUnitTest.cpp
+	../Fragmentation/unittests/IndexSetUnitTest.cpp \
+	../Fragmentation/unittests/IndexSetContainerUnitTest.cpp
 
 FRAGMENTATIONSUMMATIONTESTSHEADERS = \
-	../Fragmentation/unittests/IndexSetUnitTest.hpp
+	../Fragmentation/unittests/IndexSetUnitTest.hpp \
+	../Fragmentation/unittests/IndexSetContainerUnitTest.cpp
 
 FRAGMENTATIONSUMMATIONTESTS = \
-  IndexSetUnitTest
+  IndexSetUnitTest \
+  IndexSetContainerUnitTest
 
 TESTS += $(FRAGMENTATIONSUMMATIONTESTS)
@@ -31,4 +34,12 @@
 IndexSetUnitTest_LDADD = ${FRAGMENTATIONSUMMATIONLIBS}
 
+IndexSetContainerUnitTest_SOURCES = $(top_srcdir)/src/unittests/UnitTestMain.cpp \
+	unittests/IndexSetContainerUnitTest.cpp \
+	unittests/IndexSetContainerUnitTest.hpp \
+	IndexSet.cpp \
+	IndexSet.hpp \
+	IndexSetContainer.hpp \
+	SortedVector.hpp
+IndexSetContainerUnitTest_LDADD = ${FRAGMENTATIONSUMMATIONLIBS}
 
 
