Browse code

added lookup table for updating atom mass

Tom Sherman authored on 13/08/2018 15:18:30
Showing4 changed files

... ...
@@ -1,5 +1,5 @@
1 1
 Package: CoGAPS
2
-Version: 3.3.9
2
+Version: 3.3.10
3 3
 Date: 2018-04-24
4 4
 Title: Coordinated Gene Activity in Pattern Sets
5 5
 Author: Thomas Sherman, Wai-shing Lee, Conor Kelton, Ondrej Maxian, Jacob Carey,
... ...
@@ -1,4 +1,4 @@
1
-# CoGAPS Version: 3.3.9
1
+# CoGAPS Version: 3.3.10
2 2
 
3 3
 [![Bioc](https://bioconductor.org/images/logo_bioconductor.gif)](https://bioconductor.org/packages/CoGAPS)
4 4
 [![downloads](https://bioconductor.org/shields/downloads/CancerInSilico.svg)](https://bioconductor.org/packages/CoGAPS)
... ...
@@ -25,7 +25,7 @@ uint64_t AtomicDomain::randomFreePosition() const
25 25
     do
26 26
     {
27 27
         pos = gaps::random::uniform64(0, mDomainSize);
28
-    } while (mUsedPositions.count(pos) > 0); // hash map => count is O(l)
28
+    } while (mPositionLookup.count(pos) > 0);
29 29
     return pos;
30 30
 }
31 31
 
... ...
@@ -95,9 +95,9 @@ Atom AtomicDomain::insert(uint64_t pos, float mass)
95 95
         _right(atom).leftNdx = size() + 1;
96 96
     } 
97 97
 
98
-    // add atom to vector
98
+    // add atom to vector and lookup table
99
+    mPositionLookup.insert(std::pair<uint64_t, uint64_t>(pos, size()));
99 100
     mAtoms.push_back(atom);
100
-    mUsedPositions.insert(pos);
101 101
 
102 102
     return atom;
103 103
 }
... ...
@@ -108,7 +108,7 @@ Atom AtomicDomain::insert(uint64_t pos, float mass)
108 108
 void AtomicDomain::erase(uint64_t pos)
109 109
 {
110 110
     // get vector index of this atom
111
-    uint64_t index = mAtomPositions.at(pos);
111
+    uint64_t index = mPositionLookup.at(pos);
112 112
 
113 113
     // connect neighbors of atom to be deleted
114 114
     if (hasLeft(mAtoms[index]))
... ...
@@ -129,6 +129,10 @@ void AtomicDomain::erase(uint64_t pos)
129 129
         mAtomPositions.erase(mAtoms[index].pos);
130 130
         mAtomPositions.insert(std::pair<uint64_t, uint64_t>(mAtoms[index].pos,
131 131
             index));
132
+
133
+        mPositionLookup.erase(mAtoms[index].pos);
134
+        mPositionLookup.insert(std::pair<uint64_t, uint64_t>(mAtoms[index].pos,
135
+            index));
132 136
     
133 137
         // update moved atom's neighbors
134 138
         if (hasLeft(mAtoms[index]))
... ...
@@ -144,7 +148,7 @@ void AtomicDomain::erase(uint64_t pos)
144 148
     // delete atom from vector in O(1), map in O(logN)
145 149
     mAtomPositions.erase(pos);
146 150
     mAtoms.pop_back();
147
-    mUsedPositions.erase(pos);
151
+    mPositionLookup.erase(pos);
148 152
 }
149 153
 
150 154
 void AtomicDomain::cacheInsert(uint64_t pos, float mass) const
... ...
@@ -191,10 +195,10 @@ void AtomicDomain::flushCache()
191 195
     mEraseCache.clear();
192 196
 }
193 197
 
194
-// O(logN)
198
+// O(1)
195 199
 void AtomicDomain::updateMass(uint64_t pos, float newMass)
196 200
 {
197
-    mAtoms[mAtomPositions.at(pos)].mass = newMass; // TODO at() is C++11
201
+    mAtoms[mPositionLookup.at(pos)].mass = newMass;
198 202
 }
199 203
 
200 204
 Archive& operator<<(Archive &ar, Atom &a)
... ...
@@ -3,7 +3,7 @@
3 3
 
4 4
 #include "Archive.h"
5 5
 
6
-#include <boost/unordered_set.hpp>
6
+#include <boost/unordered_map.hpp>
7 7
 
8 8
 #include <cstddef>
9 9
 #include <map>
... ...
@@ -67,8 +67,7 @@ private:
67 67
     // domain storage
68 68
     std::vector<Atom> mAtoms;
69 69
     std::map<uint64_t, uint64_t> mAtomPositions;
70
-
71
-    boost::unordered_set<uint64_t> mUsedPositions;
70
+    boost::unordered_map<uint64_t, uint64_t> mPositionLookup;
72 71
 
73 72
     mutable std::vector<RawAtom> mInsertCache;
74 73
     mutable std::vector<uint64_t> mEraseCache;