7 #ifndef SPACE_HASH_NATIVE_H
8 #define SPACE_HASH_NATIVE_H
10 #include <argos3/core/simulator/space/space_hash.h>
18 template <
class Element,
class Updater>
74 SBucketData* ElementList;
97 inline bool Empty()
const {
98 return (ElementList == NULL);
105 inline void Clear() {
107 SBucketData* psCur = ElementList;
108 SBucketData* psNext = psCur->Next;
112 if(psCur) psNext = psCur->Next;
125 inline void Add(Element& c_element,
129 if(Empty()) ElementList =
new SBucketData(c_element, n_i, n_j, n_k);
130 else ElementList =
new SBucketData(c_element, n_i, n_j, n_k, ElementList);
140 bool Exists(
const Element& c_element,
144 SBucketData* psCur = ElementList;
146 if(psCur->Elem == &c_element &&
149 psCur->K == n_k)
return true;
168 m_unCurrentStoreTimestamp(0) {}
175 delete[] m_psBuckets;
182 for(
size_t i = 0; i < CSpaceHash<Element,Updater>::GetSize(); ++i) {
183 m_psBuckets[i].Clear();
205 m_unCurrentStoreTimestamp++;
220 Element& c_element) {
224 SBucket& sBucket = m_psBuckets[nHash];
226 if(sBucket.StoreTimestamp == m_unCurrentStoreTimestamp) {
228 if(! sBucket.Exists(c_element, n_i, n_j, n_k)) {
229 sBucket.Add(c_element, n_i, n_j, n_k);
236 sBucket.StoreTimestamp = m_unCurrentStoreTimestamp;
238 sBucket.Add(c_element, n_i, n_j, n_k);
254 bool bNewElements =
false;
258 SBucket& sBucket = m_psBuckets[nHash];
263 if((sBucket.StoreTimestamp == m_unCurrentStoreTimestamp) &&
268 psCur = psCur->Next) {
270 if(n_i == psCur->I &&
275 t_elements.insert(psCur->Elem);
283 for(
size_t i = 0; i < CSpaceHash<Element,Updater>::GetSize(); ++i) {
284 if((m_psBuckets[i].StoreTimestamp == m_unCurrentStoreTimestamp) &&
285 !m_psBuckets[i].Empty()) {
286 c_os <<
"BUCKET " << i << std::endl;
289 psCur = psCur->Next) {
291 << psCur->Elem->GetId()
310 SBucket* m_psBuckets;
319 UInt64 m_unCurrentStoreTimestamp;
signed int SInt32
32-bit signed integer.
SBucketData(Element &c_element, SInt32 n_i, SInt32 n_j, SInt32 n_k, SBucketData *ps_next=NULL)
Struct constructor.
A space hash implementation that does not rely on std::map or std::tr1:unordered_map.
void Clear()
Empties all the buckets in the space hash.
virtual void Dump(CARGoSLog &c_os)
Element * Elem
The element indexed by this data item.
virtual void Update()
Updates the entire space hash.
virtual bool CheckCell(SInt32 n_i, SInt32 n_j, SInt32 n_k, typename CSpaceHash< Element, Updater >::TElementList &t_elements)
Looks for elements to process in a cell.
size_t GetSize()
Returns the size of the space hash.
virtual void SetSize(size_t un_size)
Sets the size of the space hash.
SInt32 I
The space hash cell coordinate corresponding to this data item.
CSpaceHashNative()
Class constructor.
~CSpaceHashNative()
Class destructor.
UInt32 CoordinateHash(SInt32 n_i, SInt32 n_j, SInt32 n_k)
Calculates the hash of a space hash coordinate.
An item of data held by each bucket.
unsigned long long UInt64
64-bit unsigned integer.
SBucketData * Next
Pointer to the next data item in the list, or NULL if this is the last.
Defines the basic space hash.
virtual void Update()
Updates the entire space hash.
The namespace containing all the ARGoS related code.
virtual void SetSize(size_t un_size)
Sets the size of the space hash.
virtual void UpdateCell(SInt32 n_i, SInt32 n_j, SInt32 n_k, Element &c_element)
Adds an element to a cell of the space hash.