|
|
1.1 root 1: // ************************************************************************
2: // LinkList.H - (Ordered) Double Linked List Header
3: // ************************************************************************
4: // PURPOSE: Provide a generalized sorted double linked list package
5: //
6: // FUNCTIONS:
7: // InitList - initialize/clear list
8: // CreateNode - allocate a new node that can be put into list
9: // InsertNode - insert a new node into the list
10: // DeleteCurrentNode - remove a node from the list
11: // GetNextNode - get the next (right) node from the CurrentNode
12: // GetPreviousNode - get the previous (left) node from the
13: // CurrentNode
14: // GetNode - get nth Occurence of a node that matches a
15: // key(s)
16: // GetListError - get the error value
17: //
18: // COMMENTS: The application must serialize access to the linked list
19: //
20: // Format of the Ordering and Matching functions is as follows:
21: //
22: // int OrderFunc( PNODE pNodeOne, PNODE pNodeTwo )
23: // {
24: // if( (pNodeOne->NodeData).Key < (pNodeTwo->NodeData).Key )
25: // return( LEFT_OF );
26: // if( (pNodeOne->NodeData).Key == (pNodeTwo->NodeData).Key )
27: // return( MATCH );
28: // if( (pNodeOne->NodeData).Key > (pNodeTwo->NodeData).Key )
29: // return( RIGHT_OF );
30: // }
31: //
32: // ************************************************************************
33: #include <WinDef.H> // for DWORD definition only
34:
35: #define NO_ERROR_FOUND 1
36: #define NO_FREE_MEM_ERROR -1
37: #define NO_NODE_ERROR -2
38: #define NO_MATCH_ERROR -3
39: #define NO_NEXT_NODE_ERROR -4
40: #define NO_PREV_NODE_ERROR -5
41:
42: #define DEREFERENCE_NULL_ERROR -99
43:
44: #define LEFT_OF -1
45: #define MATCH 0
46: #define OVERWRITE 0
47: #define RIGHT_OF 1
48:
49: // ************************************************************************
50: // the NODE_DATA type should be modified to suit needs
51:
52: typedef struct NODE_DATA_STRUCT {
53: DWORD dwThreadId;
54: HANDLE hThread;
55: } NODE_DATA;
56:
57: //* End of custom NODE_DATA definition
58: // ************************************************************************
59:
60: typedef struct NODE_STRUCT* PNODE;
61:
62: //-- definition of a node
63: typedef struct NODE_STRUCT {
64: NODE_DATA NodeData;
65: PNODE pLeftLink;
66: PNODE pRightLink;
67: } NODE;
68:
69: //-- definition of a list
70: typedef struct LIST_STRUCT* PLIST;
71:
72: typedef struct LIST_STRUCT {
73: int ListError;
74: PNODE pFirstNode;
75: PNODE pCurrentNode;
76: PNODE pLastNode;
77: int (*OrderFunction)(PNODE, PNODE);
78: } LIST;
79:
80: //-- prototypes
81: int GetListError( PLIST pList );
82: int InitList( PLIST pList, int (*OrderingFunction)( PNODE pNodeOne, PNODE pNodeTwo ) );
83: int CreateNode( PLIST pList, PNODE* pNewNode );
84: int InsertNode( PLIST pList, PNODE pNewNode );
85: int DestroyNode( PNODE pNode );
86: int DeleteCurrentNode( PLIST pList );
87: int GetNextNode( PLIST pList, PNODE* ppNode );
88: int GetPreviousNode( PLIST pList, PNODE* ppNode );
89: int GetNode( PLIST pList, PNODE* pKeyNode,
90: int (*MatchingFunction)( PNODE pNodeOne, PNODE pNodeTwo ),
91: int Occurence );
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.