xref: /illumos-gate/usr/src/contrib/mDNSResponder/mDNSShared/GenLinkedList.h (revision 533affcbc7fc4d0c8132976ea454aaa715fe2307)
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 
18 #ifndef __GenLinkedList__
19 #define __GenLinkedList__
20 
21 
22 #include <stddef.h>
23 
24 
25 struct  GenLinkedList
26 {
27     void        *Head,
28     *Tail;
29     size_t LinkOffset;
30 };
31 typedef struct GenLinkedList GenLinkedList;
32 
33 
34 void        InitLinkedList( GenLinkedList *pList, size_t linkOffset);
35 
36 void        AddToHead( GenLinkedList *pList, void *elem);
37 void        AddToTail( GenLinkedList *pList, void *elem);
38 
39 int     RemoveFromList( GenLinkedList *pList, void *elem);
40 
41 int     ReplaceElem( GenLinkedList *pList, void *elemInList, void *newElem);
42 
43 
44 
45 struct  GenDoubleLinkedList
46 {
47     void        *Head,
48     *Tail;
49     size_t FwdLinkOffset,
50            BackLinkOffset;
51 };
52 typedef struct GenDoubleLinkedList GenDoubleLinkedList;
53 
54 
55 void        InitDoubleLinkedList( GenDoubleLinkedList *pList, size_t fwdLinkOffset,
56                                   size_t backLinkOffset);
57 
58 void        DLLAddToHead( GenDoubleLinkedList *pList, void *elem);
59 
60 void        DLLRemoveFromList( GenDoubleLinkedList *pList, void *elem);
61 
62 
63 
64 /* A GenLinkedOffsetList is like a GenLinkedList that stores the *Next field as a signed */
65 /* offset from the address of the beginning of the element, rather than as a pointer. */
66 
67 struct  GenLinkedOffsetList
68 {
69     size_t Head,
70            Tail;
71     size_t LinkOffset;
72 };
73 typedef struct GenLinkedOffsetList GenLinkedOffsetList;
74 
75 
76 void        InitLinkedOffsetList( GenLinkedOffsetList *pList, size_t linkOffset);
77 
78 void        *GetHeadPtr( GenLinkedOffsetList *pList);
79 void        *GetTailPtr( GenLinkedOffsetList *pList);
80 void        *GetOffsetLink( GenLinkedOffsetList *pList, void *elem);
81 
82 void        OffsetAddToHead( GenLinkedOffsetList *pList, void *elem);
83 void        OffsetAddToTail( GenLinkedOffsetList *pList, void *elem);
84 
85 int     OffsetRemoveFromList( GenLinkedOffsetList *pList, void *elem);
86 
87 int     OffsetReplaceElem( GenLinkedOffsetList *pList, void *elemInList, void *newElem);
88 
89 
90 #endif //	__GenLinkedList__
91