Use ListOfLists in gmx_mtop_t and gmx_localtop_t
[alexxy/gromacs.git] / src / gromacs / gmxpreprocess / gpp_nextnb.cpp
index 19aa460d27637b7f6bf294e815b7d27a392f8fb9..b411d6a602b2cba8438b8f561059e2b3fa4e9af2 100644 (file)
@@ -172,14 +172,15 @@ void __print_nnb(t_nextnb* nnb, char* s)
 }
 #endif
 
-static void nnb2excl(t_nextnb* nnb, t_blocka* excl)
+static void nnb2excl(t_nextnb* nnb, gmx::ListOfLists<int>* excls)
 {
     int       i, j, j_index;
     int       nre, nrx, nrs, nr_of_sortables;
     sortable* s;
 
-    srenew(excl->index, nnb->nr + 1);
-    excl->index[0] = 0;
+    excls->clear();
+
+    std::vector<int> exclusionsForAtom;
     for (i = 0; (i < nnb->nr); i++)
     {
         /* calculate the total number of exclusions for atom i */
@@ -230,16 +231,13 @@ static void nnb2excl(t_nextnb* nnb, t_blocka* excl)
         nr_of_sortables = j_index;
         prints("after rm-double", j_index, s);
 
-        /* make space for arrays */
-        srenew(excl->a, excl->nra + nr_of_sortables);
-
         /* put the sorted exclusions in the target list */
+        exclusionsForAtom.clear();
         for (nrs = 0; (nrs < nr_of_sortables); nrs++)
         {
-            excl->a[excl->nra + nrs] = s[nrs].aj;
+            exclusionsForAtom.push_back(s[nrs].aj);
         }
-        excl->nra += nr_of_sortables;
-        excl->index[i + 1] = excl->nra;
+        excls->pushBack(exclusionsForAtom);
 
         /* cleanup temporary space */
         sfree(s);
@@ -432,7 +430,7 @@ static void sort_and_purge_nnb(t_nextnb* nnb)
 }
 
 
-void generate_excl(int nrexcl, int nratoms, gmx::ArrayRef<InteractionsOfType> plist, t_blocka* excl)
+void generate_excl(int nrexcl, int nratoms, gmx::ArrayRef<InteractionsOfType> plist, gmx::ListOfLists<int>* excls)
 {
     t_nextnb nnb;
     if (nrexcl < 0)
@@ -441,8 +439,7 @@ void generate_excl(int nrexcl, int nratoms, gmx::ArrayRef<InteractionsOfType> pl
     }
     init_nnb(&nnb, nratoms, nrexcl);
     gen_nnb(&nnb, plist);
-    excl->nr = nratoms;
     sort_and_purge_nnb(&nnb);
-    nnb2excl(&nnb, excl);
+    nnb2excl(&nnb, excls);
     done_nnb(&nnb);
 }