9 #ifndef IndexOpenClosed_h
10 #define IndexOpenClosed_h
21 template<
typename state>
37 template<
typename state>
55 template <
class state>
67 template <
class state>
79 template<
typename state,
typename CmpKey = IndexCompareWithF<state>,
class dataStructure = IndexOpenClosedDataWithF<state> >
84 void Reset(
int maxID);
93 inline const dataStructure &
Lookat(uint64_t objKey)
const {
return elements[objKey]; }
95 uint64_t
Peek()
const;
97 void Reopen(uint64_t objKey);
114 template<
typename state,
typename CmpKey,
class dataStructure>
123 template<
typename state,
typename CmpKey,
class dataStructure>
131 template<
typename state,
typename CmpKey,
class dataStructure>
135 if (elements.size() != maxID)
137 elements.resize(maxID);
138 for (
auto &x : elements)
139 x.round = currentRound;
147 template<
typename state,
typename CmpKey,
class dataStructure>
150 if (elements[hash].round == currentRound)
155 elements[hash] = dataStructure(val, g, h, parent, theHeap.size(),
kOpenList);
156 elements[hash].round = currentRound;
158 elements[hash].parentID = hash;
159 theHeap.push_back(hash);
160 HeapifyUp(theHeap.size()-1);
164 template<
typename state,
typename CmpKey,
class dataStructure>
167 if (elements[hash].round == currentRound)
172 elements[hash] = dataStructure(val, f, g, h, parent, theHeap.size(),
kOpenList);
173 elements[hash].round = currentRound;
175 elements[hash].parentID = hash;
176 theHeap.push_back(hash);
177 HeapifyUp(theHeap.size()-1);
184 template<
typename state,
typename CmpKey,
class dataStructure>
188 assert(elements[hash].round != currentRound);
189 elements[hash] = dataStructure(val, g, h, parent, 0,
kClosedList);
190 elements[hash].round = currentRound;
192 elements[hash].parentID = hash;
199 template<
typename state,
typename CmpKey,
class dataStructure>
203 assert(elements[hash].round != currentRound);
204 elements[hash] = dataStructure(val, f, g, h, parent, 0,
kClosedList);
205 elements[hash].round = currentRound;
207 elements[hash].parentID = hash;
214 template<
typename state,
typename CmpKey,
class dataStructure>
217 if (!HeapifyUp(elements[val].openLocation))
218 HeapifyDown(elements[val].openLocation);
224 template<
typename state,
typename CmpKey,
class dataStructure>
228 if (elements[hashKey].round == currentRound)
229 return elements[hashKey].where;
237 template<
typename state,
typename CmpKey,
class dataStructure>
240 assert(OpenSize() != 0);
248 template<
typename state,
typename CmpKey,
class dataStructure>
251 assert(OpenSize() != 0);
253 uint64_t ans = theHeap[0];
255 theHeap[0] = theHeap[theHeap.size()-1];
256 elements[theHeap[0]].openLocation = 0;
266 template<
typename state,
typename CmpKey,
class dataStructure>
270 elements[objKey].reopened =
true;
272 elements[objKey].openLocation = theHeap.size();
273 theHeap.push_back(objKey);
274 HeapifyUp(theHeap.size()-1);
281 template<
typename state,
typename CmpKey,
class dataStructure>
284 if (index == 0)
return false;
285 int parent = (index-1)/2;
288 if (compare(elements[theHeap[parent]], elements[theHeap[index]]))
290 unsigned int tmp = theHeap[parent];
291 theHeap[parent] = theHeap[index];
292 theHeap[index] = tmp;
293 elements[theHeap[parent]].openLocation = parent;
294 elements[theHeap[index]].openLocation = index;
301 template<
typename state,
typename CmpKey,
class dataStructure>
305 unsigned int child1 = index*2+1;
306 unsigned int child2 = index*2+2;
308 unsigned int count = theHeap.size();
312 else if (child2 >= count)
314 else if (!(compare(elements[theHeap[child1]], elements[theHeap[child2]])))
320 if (!(compare(elements[theHeap[which]], elements[theHeap[index]])))
322 unsigned int tmp = theHeap[which];
323 theHeap[which] = theHeap[index];
325 theHeap[index] = tmp;
326 elements[theHeap[which]].openLocation = which;
327 elements[theHeap[index]].openLocation = index;