KSquare Utilities
KKQueue.h
Go to the documentation of this file.
1 /* KKQueue.h -- Double sided queue structure sub-classed from vector template.
2  * Copyright (C) 1994-2014 Kurt Kramer & Sergiy Fefilatyev
3  * For conditions of distribution and use, see copyright notice in KKB.h
4  *
5  * 2011-06 Sergiy Fefilatyev found a bug in my 'KKB::KKQueue::RandomizeOrder' method.
6  * 2011-10-21 Fixed bug in prev fix to 'KKB::KKQueue::RandomizeOrder'.
7  */
8 #ifndef _KKU_KKQUEUE_
9 #define _KKU_KKQUEUE_
10 
11 // Have to use _KKU_KKQUEUE_ because _QUEUE_ is used by #include <queue> from STL
12 
13 /**
14  *@file KKQueue.h
15  *@details
16  *@code
17  *************************************************************************************
18  ** *
19  ** Developed By: Kurt A. Kramer *
20  ** *
21  ** Date: Way back in history *
22  ** *
23  *************************************************************************************
24  ** A KKQueue template. Makes it quick and easy to create Container objects. *
25  ** *
26  ** Based off the vector<> template, but consists of only pointers to objects of *
27  ** type 'Entry'. *
28  ** *
29  ** Can act as a 'Array', 'Queue', or 'Stack'. *
30  ** *
31  ** 'owner' - When you create an instance of 'KKQueue' you specify weather it will *
32  ** own its contents or not. If 'KKQueue' owns its contents then it will delete *
33  ** them when it is deleted. That is 'KKQueue' will be responsible for calling *
34  ** the destructor for each 'entry' it contains. *
35  ** *
36  ** *
37  *************************************************************************************
38  *@endcode
39  */
40 
41 #include <assert.h>
42 #include <ctype.h>
43 #include <stdlib.h>
44 #include <memory>
45 #include <vector>
46 #include <algorithm>
47 #include <functional>
48 #include <iostream>
49 
50 
51 #include "KKBaseTypes.h"
53 
54 
55 namespace KKB
56 {
57  /**
58  *@brief A typed container class/template that keeps track of entries via pointers only.
59  *@details Will act as an Array, Queue or Stack structure. Items are added by the 'PushOnFront' and
60  * 'PushOnBack' methods. They are removed by the 'PopFromFront' and 'PopFromBack' methods.
61  * What is important to keep in mind is that it holds pointers to its contents, not the actual
62  * instances. It is important to keep track who owns the objects you put in an instance of
63  * KKQueue. KKQueue has a 'Owner' flag that you can set. If it is set to 'true' then it will
64  * call the destructor on all its contents when you call KKQueue's destructor or the
65  * 'DestroyContents' method. When you add an element to a KKQueue container you can not delete
66  * it separately until you either remove it from KKQueue or delete the KKQueue container.
67  * If the KKQueue derived container owned its contents and you call its destructor then there
68  * is no need to delete the contents separately.
69  *
70  * KKQueue is sub-classed from vector<Entry*> so you can use any method that is available for
71  * the vector<> template.
72  *
73  *@tparam Entry The type of objects that are to be held in this container. When you add new instances
74  * of 'Entry', you need to add a pointer to it not the actual entry.
75  */
76  template <class Entry>
77  class KKQueue: public std::vector<Entry*>
78  {
79  typedef Entry* EntryPtr;
80  typedef Entry const * EntryConstPtr;
81 
82  private:
83  bool owner; /**< if True the KKQueue structure owns the objects and is responsible for
84  * deleting them when the KKQueue structure is deleted.
85  */
86 
87  public:
88  typedef typename std::vector<Entry*>::iterator iterator;
90 
91 
92  KKQueue (bool _owner = true);
93 
94  protected:
95  /**
96  *@brief Copy Constructor creating new instance; including duplicating contents if owner set to true.
97  *@details If the parameter 'q' owns its contents then will create new instances of its contents.
98  * That is it will call the Copy Constructor for each one of the elements it contains. If 'q' does
99  * not own its contents it will just copy over the pointers from 'q', meaning that the new instance
100  * of KKQueue will point to the same locations as 'q' does.
101  */
102  KKQueue (const KKQueue& q);
103 
104  public:
105  /**
106  *@brief Constructor, similar to the Copy Constructor except that you can control whether it duplicates the contents.
107  *@details If the '_owner' parameter is set to true then it will create new instances of the contents otherwise it
108  will just point to the instances that already exist.
109  */
110  KKQueue (const KKQueue& q,
111  bool _owner
112  );
113 
114 
115  /** @brief Virtual destructor; if owns its contents will also call the destructor on each one entry that it contains. */
116  virtual ~KKQueue ();
117 
118  KKQueue* DuplicateListAndContents () const; /**< @brief Creates a new container including duplicating the contents, which
119  * also makes the new instance the owner of those contents.
120  */
121 
122  // Access Methods that do not update the instance.
123  EntryPtr BackOfQueue () const; /**< Returns pointer of last element in the container without removing it. If the container is empty will return NULL. */
124  EntryPtr FrontOfQueue () const; /**< Returns a pointer to the element that is at from of the queue with out removing it from the queue. */
125  EntryPtr GetFirst () const; /**< Same as FrontOfQueue. */
126  EntryPtr GetLast () const; /**< Same as BackOfQueue. */
127  EntryPtr LookAtBack () const; /**< Same as BackOfQueue. */
128  EntryPtr LookAtFront () const; /**< Same as FrontOfQueue. */
129  kkint32 QueueSize () const; /**< Same as calling vector<>::size(); returns the number of elements in KKQueue */
130  bool Owner () const;
131 
132  kkint32 LocateEntry (EntryConstPtr _entry) const; /**< Returns the index of the element who's address is '_entry'. If not found in container will return back -1. */
133  EntryPtr IdxToPtr (kkuint32 idx) const; /**< Returns back a pointer to the element who's index is 'idx'. If 'idx' is less than 0 or >= QueueSize() will return NULL. */
134  kkint32 PtrToIdx (EntryConstPtr _entry) const; /**< returns the index of the 'entry' that has the same pointer as '_entry', if none found returns -1 */
135 
136  // Basic Queue operators.
137  virtual void Add (EntryPtr _entry); /**< same as PushOnBack */
138  virtual void AddFirst (EntryPtr _entry); /**< same as PushOnFront */
139  virtual EntryPtr PopFromFront (); /**< Removes the first element in the container and returns its pointer. If the container is empty will return NULL. */
140  virtual EntryPtr PopFromBack (); /**< Removes the last element in the container and returns its pointer. If the container is empty will return NULL. */
141  virtual void PushOnFront (EntryPtr _entry); /**< Adds '_entry' to the Front of the container. */
142  virtual void PushOnBack (EntryPtr _entry); /**< Adds '_entry' to the End of the container. */
143  virtual EntryPtr RemoveFirst (); /**< same as PopFromFront */
144  virtual EntryPtr RemoveLast (); /**< same as PopFromBack */
145 
146 
147  /**
148  *@fn void AddQueue (KKQueue& q);
149  *@brief Add the contents of a separate KKQueue container to this container.
150  *@details Be careful how the Owner flags are set; this method adds the pointers of 'q' to the end of its own container; it does not concern itself
151  * with the state of the 'Owner' flags. If you are not careful you can have both containers thinking they own the same entries. I suggest
152  * that after you add the contents of 'q' to this container that the caller set the 'owner' flag of 'q' to false.
153  */
154  virtual void AddQueue (const KKQueue& q);
155 
156  void DeleteContents (); /**< Empties the container, if 'owner' is set to true will call the destructor on each element. */
157  void DeleteEntry (EntryPtr _entry); /**< Removes from KKQueue the entry who's pointer = '_entry' */
158  void DeleteEntry (kkuint32 _idx); /**< Removes from KKQueue the entry who's index = '_idx'. */
159 
160  void Owner (bool _owner); /**< You can specify who owns the contents of the container. '_owner' == true means when the container is deleted it will also call the destructor for each element it contains. */
161 
162  void RandomizeOrder ();
163  void RandomizeOrder (kkint64 seed);
164  void RandomizeOrder (RandomNumGenerator& randomVariable);
165 
166  void SetIdxToPtr (kkuint32 _idx,
167  Entry* _ptr
168  );
169 
170  void SwapIndexes (size_t idx1, size_t idx2);
171 
172  template<typename Functor>
174  Functor pred
175  );
176 
177 
178  //void Sort (QueueComparison<Entry>* comparison);
179 
180  Entry& operator[] (kkuint32 i) const; /**< Returns a reference to element indexed by 'i'; similar to IdxToPtr except tat it returns a reference rather than a pointer.0 */
181 
182 
183  /**
184  *@brief Assignment Operator
185  *@details
186  *@code
187  * 1) Destroy's its current contents by calling 'DeleteContents'.
188  * 2) If 'q' owns its contents
189  * create new instances of 'q's contents and add to its self then set 'owner' flag to true.
190  * else
191  * Copy over 'q's pointers to self and then set 'owner' flag to false.
192  *@endcode
193  */
194  KKQueue& operator= (const KKQueue& q);
195 
196  bool operator== (const KKQueue<Entry>& rightSide) const; /**< @brief Returns True if every entry in both containers point to the same elements */
197  bool operator!= (const KKQueue<Entry>& rightSide) const; /**< @brief returns False if NOT every entry in both containers point to the same elements */
198 
199  private:
200  template<typename Functor>
201  kkuint32 FindTheKthElement (kkuint32 k,
202  kkuint32 left,
203  kkuint32 right,
204  Functor pred
205  );
206 
207  template<typename Functor>
208  kkint32 Partition (kkuint32 left,
209  kkuint32 right,
210  Functor pred
211  );
212 
213  }; /* KKQueue */
214 
215 
216 
217 
218  template <class Entry>
219  KKQueue<Entry>::KKQueue (bool _owner):
220  owner (_owner)
221  {
222  }
223 
224 
225 
226  template <class Entry>
227  KKQueue<Entry>::KKQueue (const KKQueue& q):
228  owner (q.Owner ())
229 
230  {
231  //for (vector<Entry*>::const_iterator x = q.begin (); x != q.end (); x++)
232  for (const_iterator x = q.begin (); x != q.end (); x++)
233  {
234  if (owner)
235  PushOnBack (new Entry (*(*x)));
236  else
237  PushOnBack (*x);
238  }
239  }
240 
241 
242  template <class Entry>
243  KKQueue<Entry>::KKQueue (const KKQueue& q,
244  bool _owner
245  ):
246  owner (_owner)
247 
248  {
249  //for (vector<Entry*>::const_iterator x = q.begin
250  // owner (_owner) (); x != q.end (); x++)
251  for (const_iterator x = q.begin (); x != q.end (); ++x)
252  {
253  if (owner)
254  PushOnBack (new Entry (*(*x)));
255  else
256  PushOnBack (*x);
257  }
258  }
259 
260 
261 
262  template <class Entry>
263  KKQueue<Entry>* KKQueue<Entry>::DuplicateListAndContents () const
264  {
265  KKQueue<Entry>* duplicatedQueue = new KKQueue<Entry> (true, QueueSize ());
266 
267  for (const_iterator x = KKQueue<Entry>::begin (); x != KKQueue<Entry>::end (); x++)
268  {
269  const EntryPtr e = *x;
270  duplicatedQueue->PushOnBack (new Entry (*e));
271  }
272 
273  return duplicatedQueue;
274  } /* DuplicateListAndContents */
275 
276 
277 
278 
279  template <class Entry>
280  KKQueue<Entry>::~KKQueue ()
281  {
282  if (owner)
283  {
284  iterator i;
285 
286  for (i = KKQueue<Entry>::begin (); i != KKQueue<Entry>::end (); i++)
287  {
288  delete *i;
289  *i = NULL;
290  }
291  }
292  } /* ~KKQueue */
293 
294 
295 
296  template <class Entry>
297  void KKQueue<Entry>::Owner (bool _owner)
298  {
299  owner = _owner;
300  }
301 
302 
303 
304  template <class Entry>
305  bool KKQueue<Entry>::Owner () const
306  {
307  return (owner != 0);
308  }
309 
310 
311 
312  template <class Entry>
313  kkint32 KKQueue<Entry>::QueueSize () const
314  {
315  return (kkint32)this->size ();
316  }
317 
318 
319 
320  template <class Entry>
321  void KKQueue<Entry>::DeleteContents ()
322  {
323  if (owner)
324  {
325  iterator idx;
326 
327  for (idx = KKQueue<Entry>::begin (); idx != KKQueue<Entry>::end (); idx++)
328  {
329  delete (*idx);
330  }
331  }
332 
333  KKQueue<Entry>::clear ();
334  } /* DeleteContents */
335 
336 
337 
338  template <class Entry>
339  inline void KKQueue<Entry>::Add (EntryPtr _entry)
340  {
341  PushOnBack (_entry);
342  }
343 
344 
345 
346  template <class Entry>
347  inline void KKQueue<Entry>::AddFirst (EntryPtr _entry)
348  {
350  }
351 
352 
353 
354  template <class Entry>
355  void KKQueue<Entry>::AddQueue (const KKQueue& q)
356  {
357  for (const_iterator x = q.begin (); x != q.end (); x++)
358  PushOnBack (*x);
359  return;
360  } /* AddQueue */
361 
362 
363 
364 
365  template <class Entry>
366  inline typename KKQueue<Entry>::EntryPtr KKQueue<Entry>::GetFirst () const
367  {
368  return FrontOfQueue ();
369  }
370 
371 
372 
373  template <class Entry>
374  inline typename KKQueue<Entry>::EntryPtr KKQueue<Entry>::GetLast () const
375  {
376  return BackOfQueue ();
377  }
378 
379 
380 
381 
382  template <class Entry>
383  void KKQueue<Entry>::PushOnFront (EntryPtr _entry)
384  {
386 
387  Entry* e = *KKQueue<Entry>::begin ();
388 
389  if (e != _entry)
390  {
391  std::cout << "Error " << std::endl;
392  }
393 
394  }
395 
396 
397  template <class Entry>
398  void KKQueue<Entry>::PushOnBack (EntryPtr _entry)
399  {
400  this->push_back (_entry);
401 
402  EntryPtr e = KKQueue<Entry>::back ();
403 
404  if (e != _entry)
405  {
406  std::cerr << "KKQueue<Entry>::PushOnBack ***ERROR*** Operation Failed!!!" << std::endl;
407  }
408  //vector<Entry*> x;
409  }
410 
411 
412 
413 
414  template <class Entry>
415  KKQueue<Entry>& KKQueue<Entry>::operator= (const KKQueue& q)
416  {
417  DeleteContents ();
418 
419  if (q.Owner ())
420  {
421  for (const_iterator x = q.begin (); x < q.end (); x++)
422  push_back (new Entry (**x));
423  this->Owner (true);
424  }
425  else
426  {
427  for (const_iterator x = q.begin (); x < q.end (); x++)
428  push_back (*x);
429  this->Owner (false);
430  }
431  return *this;
432  } /* operator= */
433 
434 
435 
436 
437  template <class Entry>
438  bool KKQueue<Entry>::operator== (const KKQueue<Entry>& rightSide) const
439  {
440  if (QueueSize () != rightSide.QueueSize ())
441  return false;
442 
443  for (kkint32 x = 0; x < QueueSize (); x++)
444  {
445  Entry* left = IdxToPtr (x);
447  if (!((*left) == (*right)))
448  return false;
449  }
450 
451  return true;
452  } /* operator== */
453 
454 
455 
456  template <class Entry>
457  bool KKQueue<Entry>::operator!= (const KKQueue<Entry>& rightSide) const
458  {
459  return !((*this) == rightSide);
460  } /* operator!= */
461 
462 
463 
464  /**
465  *@brief Randomizes the order of the vector.
466  *@details Implements the "Fisher-Yates Uniform Random Sort"; this implementation was done by Sergiy Fefilatyev (2011-01-27)
467  */
468  template <class Entry>
469  void KKQueue<Entry>::RandomizeOrder ()
470  {
471  kkint32 i, j;
473  if (numEntries < 2)
474  return;
475 
476  i = numEntries - 1;
477  while (true)
478  {
479  j = LRand48() % (i + 1);
480  SwapIndexes (i, j );
481  if (i < 1)
482  break;
483  i--;
484  }
485  } /* RandomizeOrder */
486 
487 
488 
489  template <class Entry>
490  void KKQueue<Entry>::RandomizeOrder (kkint64 seed)
491  {
492  SRand48 (seed);
493  RandomizeOrder ();
494  } /* RandomizeOrder */
495 
496 
497 
498 
499  /**
500  *@brief Randomizes the order of the vector.
501  *@details Implements the "Fisher-Yates Uniform Random Sort"; this implementation was done by Sergiy Fefilatyev (2011-01-27)
502  */
503  template <class Entry>
504  void KKQueue<Entry>::RandomizeOrder (RandomNumGenerator& randomVariable)
505  {
506  kkint32 i, j;
508  if (numEntries < 2)
509  return;
510 
511  i = numEntries - 1;
512  while (true)
513  {
514  j = randomVariable.Next () % (i + 1);
515  SwapIndexes (i, j );
516  if (i < 1)
517  break;
518  i--;
519  }
520  } /* RandomizeOrder */
521 
522 
523 
524 
525  template <class Entry>
526  template <typename Functor>
528  Functor pred
529  )
530  {
531  if ((k < 0) || (K > = (kkint32)size ()))
532  return -1;
533  return FindTheKthElement (k, 0, size () - 1, pred);
534  } /* FindTheKthElement */
535 
536 
537 
538 
539  template <class Entry>
540  template <typename Functor>
541  kkuint32 KKQueue<Entry>::FindTheKthElement (kkuint32 k,
542  kkuint32 left,
543  kkuint32 right,
544  Functor pred
545  )
546  {
547  if (left == right)
548  return left;
549 
551  if (k <= m)
552  return Partition (left, m);
553 
554  else if (m < right)
555  return Partition (m + 1, right);
556 
557  else
558  {
559  // This should not be able to happen; but if it does then we have a flaw in the code or the logic somewhere,
560  cerr << "KKQueue<Entry>::FindTheKthElement ***ERROR*** An invalid situation just occurred." << endl
561  <<" k=" << k << ", left=" << left << ", right=" << right << ", m=" << m << endl;
562  return m - 1;
563  }
564  } /* FindTheKthElement */
565 
566 
567 
568  template <class Entry>
569  template <typename Functor>
570  kkint32 KKQueue<Entry>::Partition (kkuint32 left,
571  kkuint32 right,
572  Functor pred
573  )
574  {
575  kkuint32 width = 1 + right - left;
576  kkuint32 pivitIdx = left + (LRand48() % width);
578 
579  while (left < right)
580  {
581  while ((left < right) && (pred (*IdxToPtr(left), *pivitPtr)))
582  ++left;
583 
584  while ((left < right) && (pred (*pivitPtr, *IdxToPtr(right))))
585  --right;
586 
587  if (left < right)
589  }
590  }
591 
592 
593 
594 
595  template <class Entry>
596  typename KKQueue<Entry>::EntryPtr KKQueue<Entry>::PopFromFront ()
597  {
598  if (KKQueue<Entry>::size () <= 0)
599  {
600  return NULL;
601  }
602 
603  iterator beg = KKQueue<Entry>::begin ();
604  Entry* e = *beg;
605  KKQueue<Entry>::erase (beg);
606  return e;
607  }
608 
609 
610  template <class Entry>
611  inline typename KKQueue<Entry>::EntryPtr KKQueue<Entry>::RemoveFirst ()
612  {
613  return PopFromFront ();
614  }
615 
616 
617 
618  template <class Entry>
619  inline typename KKQueue<Entry>::EntryPtr KKQueue<Entry>::RemoveLast ()
620  {
621  return PopFromBack ();
622  }
623 
624 
625 
626  template <class Entry>
627  typename KKQueue<Entry>::EntryPtr KKQueue<Entry>::LookAtBack () const
628  {
629  if (this->size () <= 0)
630  return NULL;
631 
632  return KKQueue<Entry>::back ();
633  }
634 
635 
636 
637  template <class Entry>
638  typename KKQueue<Entry>::EntryPtr KKQueue<Entry>::LookAtFront () const
639  {
640  if (this->size () <= 0)
641  return NULL;
642  return *KKQueue<Entry>::begin ();
643  }
644 
645 
646 
647  template <class Entry>
648  typename KKQueue<Entry>::EntryPtr KKQueue<Entry>::PopFromBack ()
649  {
650  if (KKQueue<Entry>::size () <= 0)
651  return NULL;
652 
653  Entry* e = KKQueue<Entry>::back ();
654  KKQueue<Entry>::pop_back ();
655  return e;
656  }
657 
658 
659 
660  template <class Entry>
661  typename KKQueue<Entry>::EntryPtr KKQueue<Entry>::BackOfQueue () const
662  {
663  if (KKQueue<Entry>::size () <= 0)
664  return NULL;
665  return KKQueue<Entry>::back ();
666  }
667 
668 
669 
670 
671 
672  template <class Entry>
673  typename KKQueue<Entry>::EntryPtr KKQueue<Entry>::FrontOfQueue () const
674  {
675  if ( KKQueue<Entry>::size () <= 0)
676  return NULL;
677 
678  return * KKQueue<Entry>::begin ();
679  }
680 
681 
682 
683  template <class Entry>
684  void KKQueue<Entry>::DeleteEntry (EntryPtr _entry)
685  {
686  for (iterator y = KKQueue<Entry>::begin (); y != KKQueue<Entry>::end (); y++)
687  {
688  if (*y == _entry)
689  {
690  KKQueue<Entry>::erase (y);
691  return;
692  }
693  }
694  } /* DeleteEntry */
695 
696 
697 
698 
699  template <class Entry>
700  void KKQueue<Entry>::SetIdxToPtr (kkuint32 _idx,
701  Entry* _ptr
702  )
703  {
704  if ((kkuint32)_idx >= KKQueue<Entry>::size ())
705  return;
706 
707  std::vector<Entry*>::operator[] (_idx) = _ptr;
708  } /* SetIdxToPtr */
709 
710 
711 
712 
713 
714  template <class Entry>
715  void KKQueue<Entry>::DeleteEntry (kkuint32 _idx)
716  {
717  if ((kkuint32)_idx >= KKQueue<Entry>::size ())
718  return;
719 
720  iterator i = KKQueue<Entry>::begin ();
721 
722  for (kkuint32 j = 0; ((j < _idx) && (i != KKQueue<Entry>::end ())); j++)
723  i++;
724 
725  EntryPtr ep = *i;
726  KKQueue<Entry>::erase (i);
727  } /* DeleteEntry */
728 
729 
730 
731  template <class Entry>
732  typename KKQueue<Entry>::EntryPtr KKQueue<Entry>::IdxToPtr (kkuint32 idx) const
733  {
734  if (idx >= KKQueue<Entry>::size ())
735  return NULL;
736 
737  return &((*this)[idx]);
738  //return (typename Entry*)(vector<Entry*>::operator[] (idx));
739  } /* IdxToPtr */
740 
741 
742 
743 
744  template <class Entry>
745  kkint32 KKQueue<Entry>::LocateEntry (EntryConstPtr _entry) const
746  {
747  kkint32 i = 0;
748 
749  for (const_iterator j = KKQueue<Entry>::begin (); j != KKQueue<Entry>::end (); j++)
750  {
751  if (*j == _entry)
752  return i;
753  i++;
754  }
755  return -1;
756  } /* LocateEntry */
757 
758 
759 
760  template <class Entry>
761  kkint32 KKQueue<Entry>::PtrToIdx (EntryConstPtr _entry) const
762  {
763  return LocateEntry (_entry);
764  }
765 
766 
767 
768  template <class Entry>
769  void KKQueue<Entry>::SwapIndexes (size_t idx1, size_t idx2)
770  {
771  if ((idx1 < 0) || (idx1 >= KKQueue<Entry>::size ()) ||
772  (idx2 < 0) || (idx2 >= KKQueue<Entry>::size ())
773  )
774  {
775  std::cerr << std::endl;
776 
777  std::cerr << " *** ERROR *** (KKQueue::SwapIndexes) Indexes["
778  << (kkint32)idx1 << ", " << (kkint32)idx2 << "] Out of Range."
779  << std::endl;
780 
781  std::cerr << " KKQueue Size[" << (kkint32)KKQueue<Entry>::size () << "]."
782  << std::endl
783  << std::endl;
784 
785  exit (1);
786  }
787 
788  //vector<typename Entry*>& us (*this);
790 
791  // (*this)[idx1];
792 
795  //(*this)[idx1] = (*this)[idx2];
796  //(*this)[idx2] = tempPtr;
797  } /* SwapIndexes */
798 
799 
800 
801  template <class Entry>
802  Entry& KKQueue<Entry>::operator[] (kkuint32 idx) const
803  {
804  //KKQueue<Entry>::Entry* entry;
805 
806  if ((idx < 0) || (idx >= KKQueue<Entry>::size ()))
807  {
808  std::cerr << std::endl
809  << "*** ERROR *** KKQueue<Entry>::operator[], Index [" << idx << "] out of bounds." << std::endl
810  << std::endl;
811  exit (-1);
812  }
813 
814  return (Entry&)*(std::vector<Entry*>::operator[] (idx));
815  } /* operator[] */
816 
817 } /* namespace KKB; */
818 
819 
820 
821 
822 #endif
kkuint32 FindTheKthElement(kkuint32 k, Functor pred)
Definition: KKQueue.h:527
std::vector< Entry * >::iterator iterator
Definition: KKQueue.h:88
__int32 kkint32
Definition: KKBaseTypes.h:88
void DeleteEntry(EntryPtr _entry)
Definition: KKQueue.h:684
std::vector< Entry * >::const_iterator const_iterator
Definition: KKQueue.h:89
EntryPtr IdxToPtr(kkuint32 idx) const
Definition: KKQueue.h:732
bool operator==(const KKQueue< Entry > &rightSide) const
Returns True if every entry in both containers point to the same elements.
Definition: KKQueue.h:438
void DeleteContents()
Definition: KKQueue.h:321
virtual EntryPtr PopFromBack()
Definition: KKQueue.h:648
KKQueue & operator=(const KKQueue &q)
Assignment Operator.
Definition: KKQueue.h:415
EntryPtr BackOfQueue() const
Definition: KKQueue.h:661
unsigned __int32 kkuint32
Definition: KKBaseTypes.h:89
bool Owner() const
Definition: KKQueue.h:305
__int64 kkint64
Definition: KKBaseTypes.h:90
virtual void AddQueue(const KKQueue &q)
Add the contents of a separate KKQueue container to this container.
Definition: KKQueue.h:355
KKTHread * KKTHreadPtr
void Owner(bool _owner)
Definition: KKQueue.h:297
virtual EntryPtr RemoveLast()
Definition: KKQueue.h:619
kkint32 LocateEntry(EntryConstPtr _entry) const
Definition: KKQueue.h:745
void SetIdxToPtr(kkuint32 _idx, Entry *_ptr)
Definition: KKQueue.h:700
virtual void Add(EntryPtr _entry)
Definition: KKQueue.h:339
void RandomizeOrder(RandomNumGenerator &randomVariable)
Randomizes the order of the vector.
Definition: KKQueue.h:504
EntryPtr GetLast() const
Definition: KKQueue.h:374
A typed container class/template that keeps track of entries via pointers only.
Definition: KKQueue.h:77
virtual void PushOnBack(EntryPtr _entry)
Definition: KKQueue.h:398
virtual EntryPtr RemoveFirst()
Definition: KKQueue.h:611
void RandomizeOrder(kkint64 seed)
Definition: KKQueue.h:490
Represents one single random number generator.
EntryPtr LookAtBack() const
Definition: KKQueue.h:627
kkint32 QueueSize() const
Definition: KKQueue.h:313
virtual void AddFirst(EntryPtr _entry)
Definition: KKQueue.h:347
KKQueue(const KKQueue &q)
Copy Constructor creating new instance; including duplicating contents if owner set to true...
Definition: KKQueue.h:227
void RandomizeOrder()
Randomizes the order of the vector.
Definition: KKQueue.h:469
bool operator!=(const KKQueue< Entry > &rightSide) const
returns False if NOT every entry in both containers point to the same elements
Definition: KKQueue.h:457
virtual EntryPtr PopFromFront()
Definition: KKQueue.h:596
void DeleteEntry(kkuint32 _idx)
Definition: KKQueue.h:715
EntryPtr LookAtFront() const
Definition: KKQueue.h:638
kkint32 PtrToIdx(EntryConstPtr _entry) const
Definition: KKQueue.h:761
KKQueue(bool _owner=true)
Definition: KKQueue.h:219
EntryPtr GetFirst() const
Definition: KKQueue.h:366
virtual void PushOnFront(EntryPtr _entry)
Definition: KKQueue.h:383
KKQueue * DuplicateListAndContents() const
Creates a new container including duplicating the contents, which also makes the new instance the own...
Definition: KKQueue.h:263
virtual ~KKQueue()
Virtual destructor; if owns its contents will also call the destructor on each one entry that it cont...
Definition: KKQueue.h:280
Entry & operator[](kkuint32 i) const
Definition: KKQueue.h:802
EntryPtr FrontOfQueue() const
Definition: KKQueue.h:673
void SwapIndexes(size_t idx1, size_t idx2)
Definition: KKQueue.h:769
KKQueue(const KKQueue &q, bool _owner)
Constructor, similar to the Copy Constructor except that you can control whether it duplicates the co...
Definition: KKQueue.h:243