xref: /aosp_15_r20/external/mdnsresponder/mDNSShared/GenLinkedList.h (revision 48a54d368dc4fa860885eef7b70b6c53499e7c25)
1*48a54d36SAndroid Build Coastguard Worker /* -*- Mode: C; tab-width: 4 -*-
2*48a54d36SAndroid Build Coastguard Worker  *
3*48a54d36SAndroid Build Coastguard Worker  * Copyright (c) 2003 Apple Computer, Inc. All rights reserved.
4*48a54d36SAndroid Build Coastguard Worker  *
5*48a54d36SAndroid Build Coastguard Worker  * Licensed under the Apache License, Version 2.0 (the "License");
6*48a54d36SAndroid Build Coastguard Worker  * you may not use this file except in compliance with the License.
7*48a54d36SAndroid Build Coastguard Worker  * You may obtain a copy of the License at
8*48a54d36SAndroid Build Coastguard Worker  *
9*48a54d36SAndroid Build Coastguard Worker  *     http://www.apache.org/licenses/LICENSE-2.0
10*48a54d36SAndroid Build Coastguard Worker  *
11*48a54d36SAndroid Build Coastguard Worker  * Unless required by applicable law or agreed to in writing, software
12*48a54d36SAndroid Build Coastguard Worker  * distributed under the License is distributed on an "AS IS" BASIS,
13*48a54d36SAndroid Build Coastguard Worker  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14*48a54d36SAndroid Build Coastguard Worker  * See the License for the specific language governing permissions and
15*48a54d36SAndroid Build Coastguard Worker  * limitations under the License.
16*48a54d36SAndroid Build Coastguard Worker  */
17*48a54d36SAndroid Build Coastguard Worker 
18*48a54d36SAndroid Build Coastguard Worker #ifndef __GenLinkedList__
19*48a54d36SAndroid Build Coastguard Worker #define __GenLinkedList__
20*48a54d36SAndroid Build Coastguard Worker 
21*48a54d36SAndroid Build Coastguard Worker 
22*48a54d36SAndroid Build Coastguard Worker #include <stddef.h>
23*48a54d36SAndroid Build Coastguard Worker 
24*48a54d36SAndroid Build Coastguard Worker 
25*48a54d36SAndroid Build Coastguard Worker struct	GenLinkedList
26*48a54d36SAndroid Build Coastguard Worker {
27*48a54d36SAndroid Build Coastguard Worker 	void		*Head,
28*48a54d36SAndroid Build Coastguard Worker 				*Tail;
29*48a54d36SAndroid Build Coastguard Worker 	size_t		LinkOffset;
30*48a54d36SAndroid Build Coastguard Worker };
31*48a54d36SAndroid Build Coastguard Worker typedef struct GenLinkedList	GenLinkedList;
32*48a54d36SAndroid Build Coastguard Worker 
33*48a54d36SAndroid Build Coastguard Worker 
34*48a54d36SAndroid Build Coastguard Worker void		InitLinkedList( GenLinkedList *pList, size_t linkOffset);
35*48a54d36SAndroid Build Coastguard Worker 
36*48a54d36SAndroid Build Coastguard Worker void		AddToHead( GenLinkedList *pList, void *elem);
37*48a54d36SAndroid Build Coastguard Worker void		AddToTail( GenLinkedList *pList, void *elem);
38*48a54d36SAndroid Build Coastguard Worker 
39*48a54d36SAndroid Build Coastguard Worker int		RemoveFromList( GenLinkedList *pList, void *elem);
40*48a54d36SAndroid Build Coastguard Worker 
41*48a54d36SAndroid Build Coastguard Worker int		ReplaceElem( GenLinkedList *pList, void *elemInList, void *newElem);
42*48a54d36SAndroid Build Coastguard Worker 
43*48a54d36SAndroid Build Coastguard Worker 
44*48a54d36SAndroid Build Coastguard Worker 
45*48a54d36SAndroid Build Coastguard Worker struct	GenDoubleLinkedList
46*48a54d36SAndroid Build Coastguard Worker {
47*48a54d36SAndroid Build Coastguard Worker 	void		*Head,
48*48a54d36SAndroid Build Coastguard Worker 				*Tail;
49*48a54d36SAndroid Build Coastguard Worker 	size_t		FwdLinkOffset,
50*48a54d36SAndroid Build Coastguard Worker 				BackLinkOffset;
51*48a54d36SAndroid Build Coastguard Worker };
52*48a54d36SAndroid Build Coastguard Worker typedef struct GenDoubleLinkedList	GenDoubleLinkedList;
53*48a54d36SAndroid Build Coastguard Worker 
54*48a54d36SAndroid Build Coastguard Worker 
55*48a54d36SAndroid Build Coastguard Worker void		InitDoubleLinkedList( GenDoubleLinkedList *pList, size_t fwdLinkOffset,
56*48a54d36SAndroid Build Coastguard Worker 									  size_t backLinkOffset);
57*48a54d36SAndroid Build Coastguard Worker 
58*48a54d36SAndroid Build Coastguard Worker void		DLLAddToHead( GenDoubleLinkedList *pList, void *elem);
59*48a54d36SAndroid Build Coastguard Worker 
60*48a54d36SAndroid Build Coastguard Worker void		DLLRemoveFromList( GenDoubleLinkedList *pList, void *elem);
61*48a54d36SAndroid Build Coastguard Worker 
62*48a54d36SAndroid Build Coastguard Worker 
63*48a54d36SAndroid Build Coastguard Worker 
64*48a54d36SAndroid Build Coastguard Worker /* A GenLinkedOffsetList is like a GenLinkedList that stores the *Next field as a signed */
65*48a54d36SAndroid Build Coastguard Worker /* offset from the address of the beginning of the element, rather than as a pointer. */
66*48a54d36SAndroid Build Coastguard Worker 
67*48a54d36SAndroid Build Coastguard Worker struct	GenLinkedOffsetList
68*48a54d36SAndroid Build Coastguard Worker {
69*48a54d36SAndroid Build Coastguard Worker 	size_t		Head,
70*48a54d36SAndroid Build Coastguard Worker 				Tail;
71*48a54d36SAndroid Build Coastguard Worker 	size_t		LinkOffset;
72*48a54d36SAndroid Build Coastguard Worker };
73*48a54d36SAndroid Build Coastguard Worker typedef struct GenLinkedOffsetList	GenLinkedOffsetList;
74*48a54d36SAndroid Build Coastguard Worker 
75*48a54d36SAndroid Build Coastguard Worker 
76*48a54d36SAndroid Build Coastguard Worker void		InitLinkedOffsetList( GenLinkedOffsetList *pList, size_t linkOffset);
77*48a54d36SAndroid Build Coastguard Worker 
78*48a54d36SAndroid Build Coastguard Worker void		*GetHeadPtr( GenLinkedOffsetList *pList);
79*48a54d36SAndroid Build Coastguard Worker void		*GetTailPtr( GenLinkedOffsetList *pList);
80*48a54d36SAndroid Build Coastguard Worker void		*GetOffsetLink( GenLinkedOffsetList *pList, void *elem);
81*48a54d36SAndroid Build Coastguard Worker 
82*48a54d36SAndroid Build Coastguard Worker void		OffsetAddToHead( GenLinkedOffsetList *pList, void *elem);
83*48a54d36SAndroid Build Coastguard Worker void		OffsetAddToTail( GenLinkedOffsetList *pList, void *elem);
84*48a54d36SAndroid Build Coastguard Worker 
85*48a54d36SAndroid Build Coastguard Worker int		OffsetRemoveFromList( GenLinkedOffsetList *pList, void *elem);
86*48a54d36SAndroid Build Coastguard Worker 
87*48a54d36SAndroid Build Coastguard Worker int		OffsetReplaceElem( GenLinkedOffsetList *pList, void *elemInList, void *newElem);
88*48a54d36SAndroid Build Coastguard Worker 
89*48a54d36SAndroid Build Coastguard Worker 
90*48a54d36SAndroid Build Coastguard Worker #endif //	__GenLinkedList__
91