1
/* $Xorg: set.h,v 1.4 2001/02/09 02:05:27 xorgcvs Exp $ */
5
Copyright 1995, 1998 The Open Group
7
Permission to use, copy, modify, distribute, and sell this software and its
8
documentation for any purpose is hereby granted without fee, provided that
9
the above copyright notice appear in all copies and that both that
10
copyright notice and this permission notice appear in supporting
13
The above copyright notice and this permission notice shall be
14
included in all copies or substantial portions of the Software.
16
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19
IN NO EVENT SHALL THE OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR
20
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22
OTHER DEALINGS IN THE SOFTWARE.
24
Except as contained in this notice, the name of The Open Group shall
25
not be used in advertising or otherwise to promote the sale, use or
26
other dealings in this Software without prior written authorization
32
A Set Abstract Data Type (ADT) for the RECORD Extension
36
The RECORD extension server code needs to maintain sets of numbers
37
that designate protocol message types. In most cases the interval of
38
numbers starts at 0 and does not exceed 255, but in a few cases (minor
39
opcodes of extension requests) the maximum is 65535. This disparity
40
suggests that a single set representation may not be suitable for all
41
sets, especially given that server memory is precious. We introduce a
42
set ADT to hide implementation differences so that multiple
43
simultaneous set representations can exist. A single interface is
44
presented to the set user regardless of the implementation in use for
47
The existing RECORD SI appears to require only four set operations:
48
create (given a list of members), destroy, see if a particular number
49
is a member of the set, and iterate over the members of a set. Though
50
many more set operations are imaginable, to keep the code space down,
51
we won't provide any more operations than are needed.
53
The following types and functions/macros define the ADT.
56
/* an interval of set members */
62
typedef struct _RecordSetRec *RecordSetPtr; /* primary set type */
64
typedef void *RecordSetIteratePtr;
66
/* table of function pointers for set operations.
67
set users should never declare a variable of this type.
71
#if NeedNestedPrototypes
75
unsigned long (*IsMemberOfSet)(
76
#if NeedNestedPrototypes
81
RecordSetIteratePtr (*IterateSet)(
82
#if NeedNestedPrototypes
84
RecordSetIteratePtr pIter,
85
RecordSetInterval *interval
88
} RecordSetOperations;
90
/* "base class" for sets.
91
set users should never declare a variable of this type.
93
typedef struct _RecordSetRec {
94
RecordSetOperations *ops;
97
RecordSetPtr RecordCreateSet(
98
#if NeedFunctionPrototypes
99
RecordSetInterval *intervals,
106
RecordCreateSet creates and returns a new set having members specified
107
by intervals and nintervals. nintervals is the number of RecordSetInterval
108
structures pointed to by intervals. The elements belonging to the new
109
set are determined as follows. For each RecordSetInterval structure, the
110
elements between first and last inclusive are members of the new set.
111
If a RecordSetInterval's first field is greater than its last field, the
112
results are undefined. It is valid to create an empty set (nintervals ==
113
0). If RecordCreateSet returns NULL, the set could not be created due
114
to resource constraints.
117
int RecordSetMemoryRequirements(
118
#if NeedFunctionPrototypes
119
RecordSetInterval * /*pIntervals*/,
125
#define RecordDestroySet(_pSet) \
126
/* void */ (*_pSet->ops->DestroySet)(/* RecordSetPtr */ _pSet)
128
RecordDestroySet frees all resources used by _pSet. _pSet should not be
129
used after it is destroyed.
132
#define RecordIsMemberOfSet(_pSet, _m) \
133
/* unsigned long */ (*_pSet->ops->IsMemberOfSet)(/* RecordSetPtr */ _pSet, \
136
RecordIsMemberOfSet returns a non-zero value if _m is a member of
137
_pSet, else it returns zero.
140
#define RecordIterateSet(_pSet, _pIter, _interval) \
141
/* RecordSetIteratePtr */ (*_pSet->ops->IterateSet)(/* RecordSetPtr */ _pSet,\
142
/* RecordSetIteratePtr */ _pIter, /* RecordSetInterval */ _interval)
144
RecordIterateSet returns successive intervals of members of _pSet. If
145
_pIter is NULL, the first interval of set members is copied into _interval.
146
The return value should be passed as _pIter in the next call to
147
RecordIterateSet to obtain the next interval. When the return value is
148
NULL, there were no more intervals in the set, and nothing is copied into
149
the _interval parameter. Intervals appear in increasing numerical order
150
with no overlap between intervals. As such, the list of intervals produced
151
by RecordIterateSet may not match the list of intervals that were passed
152
in RecordCreateSet. Typical usage:
155
while (pIter = RecordIterateSet(pSet, pIter, &interval))