xref: /titanic_41/usr/src/cmd/cmd-inet/usr.lib/mdnsd/GenLinkedList.h (revision 4b22b9337f359bfd063322244f5336cc7c6ffcfa)
1 /* -*- Mode: C; tab-width: 4 -*-
2  *
3  * Copyright (c) 2003 Apple Computer, Inc. All rights reserved.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  *     http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16 
17  	File:		GenLinkedList.c
18 
19  	Contains:	interface to generic linked lists.
20 
21  	Version:	1.0
22  	Tabs:		4 spaces
23 
24     Change History (most recent first):
25 
26 $Log: GenLinkedList.h,v $
27 Revision 1.3  2006/08/14 23:24:56  cheshire
28 Re-licensed mDNSResponder daemon source code under Apache License, Version 2.0
29 
30 Revision 1.2  2004/02/05 07:41:08  cheshire
31 Add Log header
32 
33 */
34 
35 #pragma ident	"%Z%%M%	%I%	%E% SMI"
36 
37 #ifndef __GenLinkedList__
38 #define __GenLinkedList__
39 
40 
41 #include <stddef.h>
42 
43 
44 struct	GenLinkedList
45 {
46 	void		*Head,
47 				*Tail;
48 	size_t		LinkOffset;
49 };
50 typedef struct GenLinkedList	GenLinkedList;
51 
52 
53 void		InitLinkedList( GenLinkedList *pList, size_t linkOffset);
54 
55 void		AddToHead( GenLinkedList *pList, void *elem);
56 void		AddToTail( GenLinkedList *pList, void *elem);
57 
58 int		RemoveFromList( GenLinkedList *pList, void *elem);
59 
60 int		ReplaceElem( GenLinkedList *pList, void *elemInList, void *newElem);
61 
62 
63 
64 struct	GenDoubleLinkedList
65 {
66 	void		*Head,
67 				*Tail;
68 	size_t		FwdLinkOffset,
69 				BackLinkOffset;
70 };
71 typedef struct GenDoubleLinkedList	GenDoubleLinkedList;
72 
73 
74 void		InitDoubleLinkedList( GenDoubleLinkedList *pList, size_t fwdLinkOffset,
75 									  size_t backLinkOffset);
76 
77 void		DLLAddToHead( GenDoubleLinkedList *pList, void *elem);
78 
79 void		DLLRemoveFromList( GenDoubleLinkedList *pList, void *elem);
80 
81 
82 
83 /* A GenLinkedOffsetList is like a GenLinkedList that stores the *Next field as a signed */
84 /* offset from the address of the beginning of the element, rather than as a pointer. */
85 
86 struct	GenLinkedOffsetList
87 {
88 	size_t		Head,
89 				Tail;
90 	size_t		LinkOffset;
91 };
92 typedef struct GenLinkedOffsetList	GenLinkedOffsetList;
93 
94 
95 void		InitLinkedOffsetList( GenLinkedOffsetList *pList, size_t linkOffset);
96 
97 void		*GetHeadPtr( GenLinkedOffsetList *pList);
98 void		*GetTailPtr( GenLinkedOffsetList *pList);
99 void		*GetOffsetLink( GenLinkedOffsetList *pList, void *elem);
100 
101 void		OffsetAddToHead( GenLinkedOffsetList *pList, void *elem);
102 void		OffsetAddToTail( GenLinkedOffsetList *pList, void *elem);
103 
104 int		OffsetRemoveFromList( GenLinkedOffsetList *pList, void *elem);
105 
106 int		OffsetReplaceElem( GenLinkedOffsetList *pList, void *elemInList, void *newElem);
107 
108 
109 #endif //	__GenLinkedList__
110