ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/branches/new_design/OOPSE-3.0/src/utils/LocalIndexManager.hpp
(Generate patch)

Comparing branches/new_design/OOPSE-3.0/src/utils/LocalIndexManager.hpp (file contents):
Revision 1802 by tim, Tue Nov 30 05:03:43 2004 UTC vs.
Revision 1803 by tim, Tue Nov 30 17:54:22 2004 UTC

# Line 47 | Line 47 | class IndexListContainer{
47   */
48   class IndexListContainer{
49      public:
50 <        static const unsigned int MAX_INTEGER = 2147483647;
51 <        typedef std::list<std::pair<unsigned int, unsigned int> >::iterator  IndexListContainerIterator;
50 >        static const int MAX_INTEGER = 2147483647;
51 >        typedef std::list<std::pair<int, int> >::iterator  IndexListContainerIterator;
52  
53          
54 <        IndexListContainer(unsigned int minIndex = 0, unsigned int maxIndex = MAX_INTEGER)
54 >        IndexListContainer(int minIndex = 0, int maxIndex = MAX_INTEGER)
55                                                   :minIndex_(minIndex), maxIndex_(maxIndex) {
56              
57              indexContainer_.push_back(std::make_pair(minIndex, maxIndex));
58          }
59          
60 <        unsigned int pop() {
60 >        int pop() {
61              
62              if (indexContainer_.empty()) {
63                  std::cerr << "" << std::endl;
64              }
65  
66              IndexListContainerIterator i = indexContainer_.begin();
67 <            unsigned int result;
67 >            int result;
68              
69              result = indexContainer_.front().first;
70              
# Line 83 | Line 83 | class IndexListContainer{
83          /**
84           *
85           */
86 <        void insert(unsigned int index) {
87 <            IndexListContainerIterator insertPos = internalInsert(index, index, indexContainer_.begin());            
86 >        void insert(int index) {
87 >            IndexListContainerIterator insertPos = internalInsert(index, index);            
88              merge(insertPos);
89          }
90  
# Line 93 | Line 93 | class IndexListContainer{
93           * @param beginIndex
94           * @param endIndex
95           */
96 <        void insert(unsigned int beginIndex, unsigned int endIndex) {
97 <             IndexListContainerIterator insertPos = internalInsert(beginIndex, endIndex, indexContainer_.begin());
96 >        void insert(int beginIndex, int endIndex) {
97 >             IndexListContainerIterator insertPos = internalInsert(beginIndex, endIndex);
98               merge(insertPos);            
99          }
100  
# Line 102 | Line 102 | class IndexListContainer{
102           * Reclaims an index array.
103           * @param indices
104           */
105 <        void insert(std::vector<unsigned int>& indices){
105 >        void insert(std::vector<int>& indices){
106  
107              if (indices.empty()) {
108                  return;
109              }
110              
111              std::sort(indices.begin(), indices.end());
112 <            std::unique(indices);
112 >            std::unique(indices.begin(), indices.end());
113  
114 <            std::vector<unsigned int>::iterator i;
114 >            std::vector<int>::iterator i;
115              IndexListContainerIterator insertPos;
116 <            unsigned int beginIndex;
117 <            unsigned int endIndex;
116 >            int beginIndex;
117 >            int endIndex;
118  
119              beginIndex = indices[0];
120          
121              for ( i = indices.begin() + 1 ; i != indices.end(); ++i) {
122                  if (*i != *(i -1) + 1) {
123 <                    insertPos = insert(beginIndex, *(i-1));
124 <                    merge(insertPos);
123 >                    insert(beginIndex, *(i-1));
124                      beginIndex = *i;
125                  }
126              }
128
129            insertPos = insert(beginIndex, *(i-1));
130            merge(insertPos);
127              
128              
129          }
130          
131 <        std::vector<unsigned int> getIndicesBefore(unsigned int index) {
132 <            std::vector<unsigned int> result;
131 >        std::vector<int> getIndicesBefore(int index) {
132 >            std::vector<int> result;
133              IndexListContainerIterator i;
134  
135              for(i = indexContainer_.begin(); i != indexContainer_.end(); ++i) {
136                  if ((*i).first > index) {
137 <                    indexContainer_.erase(indexContainer_, i);
137 >                    //we locate the node whose minimum index is greater that index
138 >                    indexContainer_.erase(indexContainer_.begin(), i);
139                      break;
140                  } else if ((*i).second < index) {
141 <
142 <                    for (unsigned int j = (*i).first; j <= (*i).second; ++j) {
141 >                    //The biggest index current node hold is less than the index we want
142 >                    for (int j = (*i).first; j <= (*i).second; ++j) {
143                          result.push_back(j);
144                      }
145                      continue;
146                  } else if ((*i).first == (*i).second) {
147 +                    //the index happen to equal to a node which only contains one index
148                      result.push_back((*i).first);
149                      indexContainer_.erase(indexContainer_.begin(), i);
150                      break;
151                  } else {
152  
153 <                    for (unsigned int j = (*i).first; j < index; ++j) {
153 >                    for (int j = (*i).first; j < index; ++j) {
154                          result.push_back(j);
155                      }
156                          
# Line 167 | Line 165 | class IndexListContainer{
165  
166          }
167          
168 <        unsigned int getMaxIndex() {
168 >        int getMaxIndex() {
169              return maxIndex_;
170          }
171                  
172      private:
173          
174 <        IndexListContainerIterator internalInsert(unsigned int beginIndex, unsigned int endIndex,
175 <                                               IndexListContainerIterator i) {
174 >        IndexListContainerIterator internalInsert(int beginIndex, int endIndex) {
175 >
176              if (beginIndex > endIndex) {
177                  std::swap(beginIndex, endIndex);
178                  std::cerr << "" << std::endl;
# Line 184 | Line 182 | class IndexListContainer{
182                  std::cerr << "" << std::endl;
183              }
184  
185 +                      
186              IndexListContainerIterator j;
187  
188 <            if (i == indexContainer_.end()) {
189 <                j = i;
190 <                --j;
191 <                if (j != indexContainer_.begin() && (*j).second >= beginIndex) {
192 <                     std::cerr << "" << std::endl;
193 <                }
195 <
196 <                indexContainer_.insert(i, make_pair(beginIndex, endIndex));
197 <                return --i;
198 <            }
199 <                
200 <
201 <            for (j = i; j != indexContainer_.end(); ++j) {
202 <                if ((*j).first > endIndex) {
203 <                    indexContainer_.insert(j, make_pair(beginIndex, endIndex));
204 <                    return --j;
205 <                } else if ((*j).second < beginIndex) {
188 >            IndexListContainerIterator i = indexContainer_.begin();  
189 >            for (; i != indexContainer_.end(); ++i) {
190 >                if ((*i).first > endIndex) {
191 >                    indexContainer_.insert(i, std::make_pair(beginIndex, endIndex));
192 >                    return --i;
193 >                } else if ((*i).second < beginIndex) {
194                      continue;
195                  } else {
196                      std::cerr << "" << std::endl;
197                  }
198              }
199  
200 <            
200 >            indexContainer_.push_back(std::make_pair(beginIndex, endIndex));
201 >            return --indexContainer_.end();
202  
203          }
204  
205          void merge(IndexListContainerIterator i) {
206              IndexListContainerIterator j;
207 <            
207 >
208 >            //check whether current node can be merged with its previous node            
209              if ( i != indexContainer_.begin()) {
210                  j = i;
211                  --j;
# Line 225 | Line 215 | class IndexListContainer{
215                  }
216              }
217  
218 +            //check whether current node can be merged with its next node            
219              if ( i != indexContainer_.end()) {
220                  j = i;
221                  ++j;
# Line 236 | Line 227 | class IndexListContainer{
227              }
228  
229          }
230 <        unsigned int minIndex_;
231 <        unsigned int maxIndex_;        
232 <        std::list<std::pair<unsigned int, unsigned int> > indexContainer_;
230 >        int minIndex_;
231 >        int maxIndex_;        
232 >        std::list<std::pair<int, int> > indexContainer_;
233   };
234  
235  
# Line 248 | Line 239 | class LocalIndexManager {
239   */
240   class LocalIndexManager {
241      public:
251        ~LocalIndexManager() {
252            delete instance_;
253        }
242          
243 <        unsigned int getNextAtomIndex() {
243 >        int getNextAtomIndex() {
244              return atomIndexContainer_.pop();
245          }
246  
247 <        std::vector<unsigned int> getAtomIndicesBefore(unsigned int index) {
247 >        std::vector<int> getAtomIndicesBefore(int index) {
248              return atomIndexContainer_.getIndicesBefore(index);
249          }
250          
251 <        void releaseAtomIndex(unsigned int index) {
251 >        void releaseAtomIndex(int index) {
252              atomIndexContainer_.insert(index);
253          }
254  
255 <        void releaseAtomIndex(unsigned int beginIndex, unsigned int endIndex) {
255 >        void releaseAtomIndex(int beginIndex, int endIndex) {
256              atomIndexContainer_.insert(beginIndex, endIndex);
257          }
258  
259 <        void releaseAtomIndex(std::vector<unsigned int> indices) {
259 >        void releaseAtomIndex(std::vector<int> indices) {
260              atomIndexContainer_.insert(indices);
261          }
262  
263 <       unsigned int getNextRigidBodyIndex() {
263 >       int getNextRigidBodyIndex() {
264              return rigidBodyIndexContainer_.pop();
265          }
266  
267 <        std::vector<unsigned int> getRigidBodyIndicesBefore(unsigned int index) {
267 >        std::vector<int> getRigidBodyIndicesBefore(int index) {
268              return rigidBodyIndexContainer_.getIndicesBefore(index);
269          }
270          
271 <        void releaseRigidBodyIndex(unsigned int index) {
271 >        void releaseRigidBodyIndex(int index) {
272              rigidBodyIndexContainer_.insert(index);
273          }
274  
275 <        void releaseRigidBodyIndex(unsigned int beginIndex, unsigned int endIndex) {
275 >        void releaseRigidBodyIndex(int beginIndex, int endIndex) {
276              rigidBodyIndexContainer_.insert(beginIndex, endIndex);
277          }
278  
279 <        void releaseRigidBodyIndex(std::vector<unsigned int> indices) {
279 >        void releaseRigidBodyIndex(std::vector<int> indices) {
280              rigidBodyIndexContainer_.insert(indices);
281          }
282  
295        static LocalIndexManager* getInstance() {
296            if (instance_ == NULL) {
297                instance_ = new LocalIndexManager();
298            } else {
299                return instance_;
300            }
301        }
302
283      private:
284 <        LocalIndexManager();
305 <        
306 <        static LocalIndexManager* instance_;
284 >
285          IndexListContainer atomIndexContainer_;
286          IndexListContainer rigidBodyIndexContainer_;
287   };

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines