SDRAngel  4.11.5
Developer docs for <a href="https://github.com/f4exb/sdrangel">SDRangel<\a>, an Open Source Qt5 / OpenGL 3.0+ SDR and signal analyzer frontend to various hardware.
Classes | Public Member Functions | Private Attributes | List of all members
qrtplib::RTPKeyHashTable< Key, Element, GetIndex, hashsize > Class Template Reference

#include <rtpkeyhashtable.h>

+ Collaboration diagram for qrtplib::RTPKeyHashTable< Key, Element, GetIndex, hashsize >:

Classes

class  HashElement
 

Public Member Functions

 RTPKeyHashTable ()
 
 ~RTPKeyHashTable ()
 
void GotoFirstElement ()
 
void GotoLastElement ()
 
bool HasCurrentElement ()
 
int DeleteCurrentElement ()
 
Element & GetCurrentElement ()
 
Key & GetCurrentKey ()
 
int GotoElement (const Key &k)
 
bool HasElement (const Key &k)
 
void GotoNextElement ()
 
void GotoPreviousElement ()
 
void Clear ()
 
int AddElement (const Key &k, const Element &elem)
 
int DeleteElement (const Key &k)
 

Private Attributes

HashElementtable [hashsize]
 
HashElementfirsthashelem
 
HashElementlasthashelem
 
HashElementcurhashelem
 

Detailed Description

template<class Key, class Element, class GetIndex, int hashsize>
class qrtplib::RTPKeyHashTable< Key, Element, GetIndex, hashsize >

Definition at line 48 of file rtpkeyhashtable.h.

Constructor & Destructor Documentation

◆ RTPKeyHashTable()

template<class Key , class Element , class GetIndex , int hashsize>
qrtplib::RTPKeyHashTable< Key, Element, GetIndex, hashsize >::RTPKeyHashTable ( )
inline

Definition at line 128 of file rtpkeyhashtable.h.

129 {
130  for (int i = 0; i < hashsize; i++)
131  table[i] = 0;
132  firsthashelem = 0;
133  lasthashelem = 0;
134 }
int32_t i
Definition: decimators.h:244
HashElement * table[hashsize]

◆ ~RTPKeyHashTable()

template<class Key, class Element, class GetIndex, int hashsize>
qrtplib::RTPKeyHashTable< Key, Element, GetIndex, hashsize >::~RTPKeyHashTable ( )
inline

Definition at line 52 of file rtpkeyhashtable.h.

53  {
54  Clear();
55  }

Member Function Documentation

◆ AddElement()

template<class Key, class Element, class GetIndex , int hashsize>
int qrtplib::RTPKeyHashTable< Key, Element, GetIndex, hashsize >::AddElement ( const Key &  k,
const Element &  elem 
)
inline

Definition at line 275 of file rtpkeyhashtable.h.

Referenced by qrtplib::RTPKeyHashTable< const uint32_t, qrtplib::RTPInternalSourceData *, qrtplib::RTPSources_GetHashIndex, RTPSOURCES_HASHSIZE >::GetCurrentKey().

276 {
277  int index;
278  bool found;
279  HashElement *e, *newelem;
280 
281  index = GetIndex::GetIndex(k);
282  if (index >= hashsize)
284 
285  e = table[index];
286  found = false;
287  while (!found && e != 0)
288  {
289  if (e->GetKey() == k)
290  found = true;
291  else
292  e = e->hashnext;
293  }
294  if (found)
296 
297  // Okay, the key doesn't exist, so we can add the new element in the hash table
298 
299  newelem = new HashElement(k, elem, index);
300 
301  e = table[index];
302  table[index] = newelem;
303  newelem->hashnext = e;
304  if (e != 0)
305  e->hashprev = newelem;
306 
307  // Now, we still got to add it to the linked list
308 
309  if (firsthashelem == 0)
310  {
311  firsthashelem = newelem;
312  lasthashelem = newelem;
313  }
314  else // there already are some elements in the list
315  {
316  lasthashelem->listnext = newelem;
317  newelem->listprev = lasthashelem;
318  lasthashelem = newelem;
319  }
320  return 0;
321 }
#define ERR_RTP_KEYHASHTABLE_KEYALREADYEXISTS
Definition: rtperrors.h:61
#define ERR_RTP_KEYHASHTABLE_FUNCTIONRETURNEDINVALIDHASHINDEX
Definition: rtperrors.h:60
HashElement * table[hashsize]
+ Here is the caller graph for this function:

◆ Clear()

template<class Key , class Element , class GetIndex , int hashsize>
void qrtplib::RTPKeyHashTable< Key, Element, GetIndex, hashsize >::Clear ( )
inline

Definition at line 256 of file rtpkeyhashtable.h.

Referenced by qrtplib::RTPKeyHashTable< const uint32_t, qrtplib::RTPInternalSourceData *, qrtplib::RTPSources_GetHashIndex, RTPSOURCES_HASHSIZE >::GetCurrentKey(), and qrtplib::RTPKeyHashTable< const uint32_t, qrtplib::RTPInternalSourceData *, qrtplib::RTPSources_GetHashIndex, RTPSOURCES_HASHSIZE >::~RTPKeyHashTable().

257 {
258  HashElement *tmp1, *tmp2;
259 
260  for (int i = 0; i < hashsize; i++)
261  table[i] = 0;
262 
263  tmp1 = firsthashelem;
264  while (tmp1 != 0)
265  {
266  tmp2 = tmp1->listnext;
267  delete tmp1;
268  tmp1 = tmp2;
269  }
270  firsthashelem = 0;
271  lasthashelem = 0;
272 }
int32_t i
Definition: decimators.h:244
HashElement * table[hashsize]
+ Here is the caller graph for this function:

◆ DeleteCurrentElement()

template<class Key , class Element , class GetIndex , int hashsize>
int qrtplib::RTPKeyHashTable< Key, Element, GetIndex, hashsize >::DeleteCurrentElement ( )
inline

Definition at line 137 of file rtpkeyhashtable.h.

Referenced by qrtplib::RTPKeyHashTable< const uint32_t, qrtplib::RTPInternalSourceData *, qrtplib::RTPSources_GetHashIndex, RTPSOURCES_HASHSIZE >::DeleteElement(), and qrtplib::RTPKeyHashTable< const uint32_t, qrtplib::RTPInternalSourceData *, qrtplib::RTPSources_GetHashIndex, RTPSOURCES_HASHSIZE >::HasCurrentElement().

138 {
139  if (curhashelem)
140  {
141  HashElement *tmp1, *tmp2;
142  int index;
143 
144  // First, relink elements in current hash bucket
145 
146  index = curhashelem->GetHashIndex();
147  tmp1 = curhashelem->hashprev;
148  tmp2 = curhashelem->hashnext;
149  if (tmp1 == 0) // no previous element in hash bucket
150  {
151  table[index] = tmp2;
152  if (tmp2 != 0)
153  tmp2->hashprev = 0;
154  }
155  else // there is a previous element in the hash bucket
156  {
157  tmp1->hashnext = tmp2;
158  if (tmp2 != 0)
159  tmp2->hashprev = tmp1;
160  }
161 
162  // Relink elements in list
163 
164  tmp1 = curhashelem->listprev;
165  tmp2 = curhashelem->listnext;
166  if (tmp1 == 0) // curhashelem is first in list
167  {
168  firsthashelem = tmp2;
169  if (tmp2 != 0)
170  tmp2->listprev = 0;
171  else
172  // curhashelem is also last in list
173  lasthashelem = 0;
174  }
175  else
176  {
177  tmp1->listnext = tmp2;
178  if (tmp2 != 0)
179  tmp2->listprev = tmp1;
180  else
181  // curhashelem is last in list
182  lasthashelem = tmp1;
183  }
184 
185  // finally, with everything being relinked, we can delete curhashelem
186  delete curhashelem;
187  curhashelem = tmp2; // Set to next element in list
188  }
189  else
191  return 0;
192 }
HashElement * table[hashsize]
#define ERR_RTP_KEYHASHTABLE_NOCURRENTELEMENT
Definition: rtperrors.h:63
+ Here is the caller graph for this function:

◆ DeleteElement()

template<class Key, class Element , class GetIndex , int hashsize>
int qrtplib::RTPKeyHashTable< Key, Element, GetIndex, hashsize >::DeleteElement ( const Key &  k)
inline

Definition at line 324 of file rtpkeyhashtable.h.

Referenced by qrtplib::RTPKeyHashTable< const uint32_t, qrtplib::RTPInternalSourceData *, qrtplib::RTPSources_GetHashIndex, RTPSOURCES_HASHSIZE >::GetCurrentKey().

325 {
326  int status;
327 
328  status = GotoElement(k);
329  if (status < 0)
330  return status;
331  return DeleteCurrentElement();
332 }
int GotoElement(const Key &k)
+ Here is the caller graph for this function:

◆ GetCurrentElement()

template<class Key, class Element, class GetIndex, int hashsize>
Element& qrtplib::RTPKeyHashTable< Key, Element, GetIndex, hashsize >::GetCurrentElement ( )
inline

Definition at line 70 of file rtpkeyhashtable.h.

71  {
72  return curhashelem->GetElement();
73  }

◆ GetCurrentKey()

template<class Key, class Element, class GetIndex, int hashsize>
Key& qrtplib::RTPKeyHashTable< Key, Element, GetIndex, hashsize >::GetCurrentKey ( )
inline

Definition at line 74 of file rtpkeyhashtable.h.

75  {
76  return curhashelem->GetKey();
77  }

◆ GotoElement()

template<class Key, class Element , class GetIndex , int hashsize>
int qrtplib::RTPKeyHashTable< Key, Element, GetIndex, hashsize >::GotoElement ( const Key &  k)
inline

Definition at line 195 of file rtpkeyhashtable.h.

Referenced by qrtplib::RTPKeyHashTable< const uint32_t, qrtplib::RTPInternalSourceData *, qrtplib::RTPSources_GetHashIndex, RTPSOURCES_HASHSIZE >::DeleteElement(), and qrtplib::RTPKeyHashTable< const uint32_t, qrtplib::RTPInternalSourceData *, qrtplib::RTPSources_GetHashIndex, RTPSOURCES_HASHSIZE >::GetCurrentKey().

196 {
197  int index;
198  bool found;
199 
200  index = GetIndex::GetIndex(k);
201  if (index >= hashsize)
203 
204  curhashelem = table[index];
205  found = false;
206  while (!found && curhashelem != 0)
207  {
208  if (curhashelem->GetKey() == k)
209  found = true;
210  else
212  }
213  if (!found)
215  return 0;
216 }
#define ERR_RTP_KEYHASHTABLE_FUNCTIONRETURNEDINVALIDHASHINDEX
Definition: rtperrors.h:60
HashElement * table[hashsize]
#define ERR_RTP_KEYHASHTABLE_KEYNOTFOUND
Definition: rtperrors.h:62
+ Here is the caller graph for this function:

◆ GotoFirstElement()

template<class Key, class Element, class GetIndex, int hashsize>
void qrtplib::RTPKeyHashTable< Key, Element, GetIndex, hashsize >::GotoFirstElement ( )
inline

Definition at line 57 of file rtpkeyhashtable.h.

58  {
60  }

◆ GotoLastElement()

template<class Key, class Element, class GetIndex, int hashsize>
void qrtplib::RTPKeyHashTable< Key, Element, GetIndex, hashsize >::GotoLastElement ( )
inline

Definition at line 61 of file rtpkeyhashtable.h.

62  {
64  }

◆ GotoNextElement()

template<class Key , class Element , class GetIndex , int hashsize>
void qrtplib::RTPKeyHashTable< Key, Element, GetIndex, hashsize >::GotoNextElement ( )
inline

◆ GotoPreviousElement()

template<class Key , class Element , class GetIndex , int hashsize>
void qrtplib::RTPKeyHashTable< Key, Element, GetIndex, hashsize >::GotoPreviousElement ( )
inline

◆ HasCurrentElement()

template<class Key, class Element, class GetIndex, int hashsize>
bool qrtplib::RTPKeyHashTable< Key, Element, GetIndex, hashsize >::HasCurrentElement ( )
inline

Definition at line 65 of file rtpkeyhashtable.h.

66  {
67  return (curhashelem == 0) ? false : true;
68  }

◆ HasElement()

template<class Key, class Element , class GetIndex , int hashsize>
bool qrtplib::RTPKeyHashTable< Key, Element, GetIndex, hashsize >::HasElement ( const Key &  k)
inline

Definition at line 219 of file rtpkeyhashtable.h.

Referenced by qrtplib::RTPKeyHashTable< const uint32_t, qrtplib::RTPInternalSourceData *, qrtplib::RTPSources_GetHashIndex, RTPSOURCES_HASHSIZE >::GetCurrentKey().

220 {
221  int index;
222  bool found;
223  HashElement *tmp;
224 
225  index = GetIndex::GetIndex(k);
226  if (index >= hashsize)
227  return false;
228 
229  tmp = table[index];
230  found = false;
231  while (!found && tmp != 0)
232  {
233  if (tmp->GetKey() == k)
234  found = true;
235  else
236  tmp = tmp->hashnext;
237  }
238  return found;
239 }
HashElement * table[hashsize]
+ Here is the caller graph for this function:

Member Data Documentation

◆ curhashelem

template<class Key, class Element, class GetIndex, int hashsize>
HashElement* qrtplib::RTPKeyHashTable< Key, Element, GetIndex, hashsize >::curhashelem
private

◆ firsthashelem

template<class Key, class Element, class GetIndex, int hashsize>
HashElement* qrtplib::RTPKeyHashTable< Key, Element, GetIndex, hashsize >::firsthashelem
private

◆ lasthashelem

template<class Key, class Element, class GetIndex, int hashsize>
HashElement * qrtplib::RTPKeyHashTable< Key, Element, GetIndex, hashsize >::lasthashelem
private

◆ table

template<class Key, class Element, class GetIndex, int hashsize>
HashElement* qrtplib::RTPKeyHashTable< Key, Element, GetIndex, hashsize >::table[hashsize]
private

The documentation for this class was generated from the following file: