Coda Distributed File System
dlist.h
Go to the documentation of this file.
1/* BLURB gpl
2
3 Coda File System
4 Release 8
5
6 Copyright (c) 1987-2025 Carnegie Mellon University
7 Additional copyrights listed below
8
9This code is distributed "AS IS" without warranty of any kind under
10the terms of the GNU General Public Licence Version 2, as shown in the
11file LICENSE. The technical and financial contributors to Coda are
12listed in the file CREDITS.
13
14 Additional copyrights
15 none currently
16
17#*/
18
19/*
20 *
21 * dlist.h -- Specification of doubly-linked list type where list elements
22 * can be on only one list at a time and are kept in sorted order.
23 *
24 */
25
26#ifndef _UTIL_DLIST_H_
27#define _UTIL_DLIST_H_ 1
28
29#ifdef __cplusplus
30extern "C" {
31#endif
32
33#include <stdio.h>
34
35#ifdef __cplusplus
36}
37#endif
38
39class dlink;
40class dlist;
41class dhashtab;
42typedef int (*CFN)(dlink *, dlink *);
43
45{
48};
49
50class dlist {
51 friend class dhashtab;
52 dlink *head; // head of list
53 int cnt;
54 CFN CmpFn; // function to order the elements
55public:
56 dlist(); // default init with NULL compare func
57 dlist(CFN);
58 virtual ~dlist();
59 void insert(dlink *); // insert in sorted order
60 void prepend(dlink *); // add at beginning of list
61 void append(dlink *); // add at end of list
62 dlink *remove(dlink *); // remove specified entry
63 dlink *first(); // return head of list
64 dlink *last(); // return tail of list
65 dlink *get(DlGetType = DlGetMin); // return and remove head or tail of list
66 void clear(); // remove all entries
67 int count();
68 int IsMember(dlink *);
69 virtual void print();
70 virtual void print(FILE *);
71 virtual void print(int);
72};
73
75{
78};
79
81 dlist *cdlist; // current dlist
82 dlink *cdlink; // current dlink
83 DlIterOrder order; // iteration order
84public:
86 dlink *operator()(); // return next object or 0.
87 // Does *not* support safe deletion
88 // of currently returned entry. See the
89 // comment below for more explanation.
90};
91
92class dlink { // objects are derived from this class
93 friend class dlist;
94 friend class dlist_iterator;
95 dlink *next;
96 dlink *prev;
97
98public:
99 dlink();
100 void clear() { next = prev = NULL; };
101 int is_linked() { return next != NULL; };
102 virtual ~dlink();
103 virtual void print();
104 virtual void print(FILE *);
105 virtual void print(int);
106};
107
108#endif /* _UTIL_DLIST_H_ */
Definition: dhash.h:45
Definition: dlist.h:80
dlist_iterator(dlist &, DlIterOrder=DlAscending)
Definition: dlist.cc:257
dlink * operator()()
Definition: dlist.cc:264
Definition: dlist.h:50
dlink * first()
Definition: dlist.cc:184
virtual ~dlist()
Definition: dlist.cc:62
dlist()
Definition: dlist.cc:48
int count()
Definition: dlist.cc:212
void insert(dlink *)
Definition: dlist.cc:70
virtual void print()
Definition: dlist.cc:232
void clear()
Definition: dlist.cc:202
dlink * last()
Definition: dlist.cc:189
dlink * remove(dlink *)
Definition: dlist.cc:159
dlink * get(DlGetType=DlGetMin)
Definition: dlist.cc:194
int IsMember(dlink *)
Definition: dlist.cc:217
void prepend(dlink *)
Definition: dlist.cc:115
void append(dlink *)
Definition: dlist.cc:138
int(* CFN)(dlink *, dlink *)
Definition: dlist.h:42
DlIterOrder
Definition: dlist.h:75
@ DlDescending
Definition: dlist.h:77
@ DlAscending
Definition: dlist.h:76
DlGetType
Definition: dlist.h:45
@ DlGetMin
Definition: dlist.h:46
@ DlGetMax
Definition: dlist.h:47
PROC * head
Definition: util.c:73
#define NULL
Definition: voltypes.h:44