Read@CVL
LinkedBlockList.h
Go to the documentation of this file.
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 
9 #ifndef __LINKEDBLOCKLIST_H__
10 #define __LINKEDBLOCKLIST_H__
11 
12 #define GCLL_BLOCK_SIZE 4
13 // GCLL_BLOCKSIZE should "fit" into the type BlockType. That is
14 // if GCLL_BLOCKSIZE is larger than 255 but smaller than largest short integer
15 // then BlockType should be set to short
16 typedef unsigned char BlockType; // diem: unsigned for we use it as number
17 
18 //The type of data stored in the linked list
19 typedef void * ListType;
20 
22 
23 public:
24  void addFront(ListType item);
25  inline bool isEmpty(){if (m_head == 0) return(true); else return(false);};
26  inline LinkedBlockList(){m_head = 0; m_head_block_size = GCLL_BLOCK_SIZE;};
28 
29  // Next three functins are for the linked list traversal
30  inline void setCursorFront(){m_cursor = m_head; m_cursor_ind = 0;};
31  ListType next();
32  bool hasNext();
33 
34 private:
35  typedef struct LLBlockStruct{
36  ListType m_item[GCLL_BLOCK_SIZE];
37  struct LLBlockStruct *m_next;
38  } LLBlock;
39 
40  LLBlock *m_head;
41  // Remembers the number of elements in the head block, since it may not be full
42  BlockType m_head_block_size;
43  // For block traversal, points to current element in the current block
44  BlockType m_cursor_ind;
45  // For block traversal, points to current block in the linked list
46  LLBlock *m_cursor;
47 };
48 
49 #endif
50 
#define GCLL_BLOCK_SIZE
Definition: LinkedBlockList.h:12
unsigned char BlockType
Definition: LinkedBlockList.h:16
void addFront(ListType item)
Definition: LinkedBlockList.cpp:7
~LinkedBlockList()
Definition: LinkedBlockList.cpp:54
LinkedBlockList()
Definition: LinkedBlockList.h:26
bool hasNext()
Definition: LinkedBlockList.cpp:45
ListType next()
Definition: LinkedBlockList.cpp:24
Definition: LinkedBlockList.h:21
bool isEmpty()
Definition: LinkedBlockList.h:25
void * ListType
Definition: LinkedBlockList.h:19
void setCursorFront()
Definition: LinkedBlockList.h:30