LinkedBlockList.h 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. /* Singly Linked List of Blocks */
  2. // This data structure should be used only for the GCoptimization class implementation
  3. // because it lucks some important general functions for general list, like remove_item()
  4. // The head block may be not full
  5. // For regular 2D grids, it's better to set GCLL_BLOCK_SIZE to 2
  6. // For other graphs, it should be set to the average expected number of neighbors
  7. // Data in linked list for the neighborhood system is allocated in blocks of size GCLL_BLOCK_SIZE
  8. #ifndef __LINKEDBLOCKLIST_H__
  9. #define __LINKEDBLOCKLIST_H__
  10. #define GCLL_BLOCK_SIZE 4
  11. // GCLL_BLOCKSIZE should "fit" into the type BlockType. That is
  12. // if GCLL_BLOCKSIZE is larger than 255 but smaller than largest short integer
  13. // then BlockType should be set to short
  14. typedef char BlockType;
  15. //The type of data stored in the linked list
  16. typedef void * ListType;
  17. namespace OBJREC {
  18. class LinkedBlockList {
  19. public:
  20. void addFront(ListType item);
  21. inline bool isEmpty() {
  22. if (m_head == 0) return(true);
  23. else return(false);
  24. };
  25. inline LinkedBlockList() {
  26. m_head = 0;
  27. m_head_block_size = GCLL_BLOCK_SIZE;
  28. };
  29. ~LinkedBlockList();
  30. // Next three functins are for the linked list traversal
  31. inline void setCursorFront() {
  32. m_cursor = m_head;
  33. m_cursor_ind = 0;
  34. };
  35. ListType next();
  36. bool hasNext();
  37. private:
  38. typedef struct LLBlockStruct {
  39. ListType m_item[GCLL_BLOCK_SIZE];
  40. struct LLBlockStruct *m_next;
  41. } LLBlock;
  42. LLBlock *m_head;
  43. // Remembers the number of elements in the head block, since it may not be full
  44. BlockType m_head_block_size;
  45. // For block traversal, points to current element in the current block
  46. BlockType m_cursor_ind;
  47. // For block traversal, points to current block in the linked list
  48. LLBlock *m_cursor;
  49. };
  50. } //namespace
  51. #endif