aboutsummaryrefslogtreecommitdiff
path: root/nx-X11/programs/Xserver/record/set.c
diff options
context:
space:
mode:
Diffstat (limited to 'nx-X11/programs/Xserver/record/set.c')
-rw-r--r--nx-X11/programs/Xserver/record/set.c305
1 files changed, 26 insertions, 279 deletions
diff --git a/nx-X11/programs/Xserver/record/set.c b/nx-X11/programs/Xserver/record/set.c
index afb1024dd..c3085c54d 100644
--- a/nx-X11/programs/Xserver/record/set.c
+++ b/nx-X11/programs/Xserver/record/set.c
@@ -1,4 +1,3 @@
-
/*
Copyright 1995, 1998 The Open Group
@@ -44,9 +43,6 @@ from The Open Group.
implemented, and RecordCreateSet will decide heuristically which one
to use based on the set members.
- Note: When compiling for use in the server, do not use -DTESTING.
- When compiling for stand-alone testing of the set ADT, use -DTESTING.
-
*/
#ifdef HAVE_DIX_CONFIG_H
@@ -55,34 +51,11 @@ from The Open Group.
#include <string.h>
-#ifndef TESTING
#include "misc.h"
-#else
-#include <stdio.h>
-#include <stdlib.h>
-
-/* stuff that you normally get from the X Server's environment */
-
-typedef int Bool;
-#ifndef TRUE
-#define TRUE 1
-#define FALSE 0
-#endif
-
-typedef unsigned short CARD16;
-
-#ifndef max
-#define max(_a, _b) ( ((_a) > (_b)) ? (_a) : (_b) )
-#endif
-
-#endif /* TESTING */
-
#include "set.h"
static int
-maxMemberInInterval(pIntervals, nIntervals)
- RecordSetInterval *pIntervals;
- int nIntervals;
+maxMemberInInterval(RecordSetInterval *pIntervals, int nIntervals)
{
int i;
int maxMember = -1;
@@ -95,8 +68,7 @@ maxMemberInInterval(pIntervals, nIntervals)
}
static void
-NoopDestroySet(pSet)
- RecordSetPtr pSet;
+NoopDestroySet(RecordSetPtr pSet)
{
}
@@ -113,16 +85,13 @@ typedef struct {
#define BITS_PER_LONG (sizeof(unsigned long) * 8)
static void
-BitVectorDestroySet(pSet)
- RecordSetPtr pSet;
+BitVectorDestroySet(RecordSetPtr pSet)
{
free(pSet);
}
static unsigned long
-BitVectorIsMemberOfSet(pSet, pm)
- RecordSetPtr pSet;
- int pm;
+BitVectorIsMemberOfSet(RecordSetPtr pSet, int pm)
{
BitVectorSetPtr pbvs = (BitVectorSetPtr)pSet;
unsigned long *pbitvec;
@@ -134,10 +103,7 @@ BitVectorIsMemberOfSet(pSet, pm)
static int
-BitVectorFindBit(pSet, iterbit, bitval)
- RecordSetPtr pSet;
- int iterbit;
- Bool bitval;
+BitVectorFindBit(RecordSetPtr pSet, int iterbit, Bool bitval)
{
BitVectorSetPtr pbvs = (BitVectorSetPtr)pSet;
unsigned long *pbitvec = (unsigned long *)(&pbvs[1]);
@@ -183,10 +149,8 @@ BitVectorFindBit(pSet, iterbit, bitval)
static RecordSetIteratePtr
-BitVectorIterateSet(pSet, pIter, pInterval)
- RecordSetPtr pSet;
- RecordSetIteratePtr pIter;
- RecordSetInterval *pInterval;
+BitVectorIterateSet(RecordSetPtr pSet, RecordSetIteratePtr pIter,
+ RecordSetInterval *pInterval)
{
int iterbit = (int)(long)pIter;
int b;
@@ -200,18 +164,15 @@ BitVectorIterateSet(pSet, pIter, pInterval)
return (RecordSetIteratePtr)(long)(pInterval->last + 1);
}
-RecordSetOperations BitVectorSetOperations = {
+static RecordSetOperations BitVectorSetOperations = {
BitVectorDestroySet, BitVectorIsMemberOfSet, BitVectorIterateSet };
-RecordSetOperations BitVectorNoFreeOperations = {
+static RecordSetOperations BitVectorNoFreeOperations = {
NoopDestroySet, BitVectorIsMemberOfSet, BitVectorIterateSet };
static int
-BitVectorSetMemoryRequirements(pIntervals, nIntervals, maxMember, alignment)
- RecordSetInterval *pIntervals;
- int nIntervals;
- int maxMember;
- int *alignment;
+BitVectorSetMemoryRequirements(RecordSetInterval *pIntervals, int nIntervals,
+ int maxMember, int *alignment)
{
int nlongs;
@@ -221,11 +182,8 @@ BitVectorSetMemoryRequirements(pIntervals, nIntervals, maxMember, alignment)
}
static RecordSetPtr
-BitVectorCreateSet(pIntervals, nIntervals, pMem, memsize)
- RecordSetInterval *pIntervals;
- int nIntervals;
- void *pMem;
- int memsize;
+BitVectorCreateSet(RecordSetInterval *pIntervals, int nIntervals,
+ void *pMem, int memsize)
{
BitVectorSetPtr pbvs;
int i, j;
@@ -273,16 +231,13 @@ typedef struct {
} IntervalListSet, *IntervalListSetPtr;
static void
-IntervalListDestroySet(pSet)
- RecordSetPtr pSet;
+IntervalListDestroySet(RecordSetPtr pSet)
{
free(pSet);
}
static unsigned long
-IntervalListIsMemberOfSet(pSet, pm)
- RecordSetPtr pSet;
- int pm;
+IntervalListIsMemberOfSet(RecordSetPtr pSet, int pm)
{
IntervalListSetPtr prls = (IntervalListSetPtr)pSet;
RecordSetInterval *pInterval = (RecordSetInterval *)(&prls[1]);
@@ -302,10 +257,8 @@ IntervalListIsMemberOfSet(pSet, pm)
static RecordSetIteratePtr
-IntervalListIterateSet(pSet, pIter, pIntervalReturn)
- RecordSetPtr pSet;
- RecordSetIteratePtr pIter;
- RecordSetInterval *pIntervalReturn;
+IntervalListIterateSet(RecordSetPtr pSet, RecordSetIteratePtr pIter,
+ RecordSetInterval *pIntervalReturn)
{
RecordSetInterval *pInterval = (RecordSetInterval *)pIter;
IntervalListSetPtr prls = (IntervalListSetPtr)pSet;
@@ -324,29 +277,23 @@ IntervalListIterateSet(pSet, pIter, pIntervalReturn)
return (RecordSetIteratePtr)NULL;
}
-RecordSetOperations IntervalListSetOperations = {
+static RecordSetOperations IntervalListSetOperations = {
IntervalListDestroySet, IntervalListIsMemberOfSet, IntervalListIterateSet };
-RecordSetOperations IntervalListNoFreeOperations = {
+static RecordSetOperations IntervalListNoFreeOperations = {
NoopDestroySet, IntervalListIsMemberOfSet, IntervalListIterateSet };
static int
-IntervalListMemoryRequirements(pIntervals, nIntervals, maxMember, alignment)
- RecordSetInterval *pIntervals;
- int nIntervals;
- int maxMember;
- int *alignment;
+IntervalListMemoryRequirements(RecordSetInterval *pIntervals, int nIntervals,
+ int maxMember, int *alignment)
{
*alignment = sizeof(unsigned long);
return sizeof(IntervalListSet) + nIntervals * sizeof(RecordSetInterval);
}
static RecordSetPtr
-IntervalListCreateSet(pIntervals, nIntervals, pMem, memsize)
- RecordSetInterval *pIntervals;
- int nIntervals;
- void *pMem;
- int memsize;
+IntervalListCreateSet(RecordSetInterval *pIntervals, int nIntervals,
+ void *pMem, int memsize)
{
IntervalListSetPtr prls;
int i, j, k;
@@ -417,20 +364,6 @@ bailout:
return (RecordSetPtr)prls;
}
-#ifdef TESTING
-typedef enum {
- BitVectorImplementation, IntervalListImplementation} RecordSetImplementation;
-
-RecordSetImplementation _RecordSetImpl;
-
-static void
-_RecordForceSetImplementation(setimpl)
- RecordSetImplementation setimpl;
-{
- _RecordSetImpl = setimpl;
-}
-#endif
-
typedef RecordSetPtr (*RecordCreateSetProcPtr)(
RecordSetInterval *pIntervals,
int nIntervals,
@@ -439,11 +372,9 @@ typedef RecordSetPtr (*RecordCreateSetProcPtr)(
);
static int
-_RecordSetMemoryRequirements(pIntervals, nIntervals, alignment, ppCreateSet)
- RecordSetInterval *pIntervals;
- int nIntervals;
- int *alignment;
- RecordCreateSetProcPtr *ppCreateSet;
+_RecordSetMemoryRequirements(RecordSetInterval *pIntervals, int nIntervals,
+ int *alignment,
+ RecordCreateSetProcPtr *ppCreateSet)
{
int bmsize, rlsize, bma, rla;
int maxMember;
@@ -455,12 +386,8 @@ _RecordSetMemoryRequirements(pIntervals, nIntervals, alignment, ppCreateSet)
&bma);
rlsize = IntervalListMemoryRequirements(pIntervals, nIntervals, maxMember,
&rla);
-#ifdef TESTING
- if (_RecordSetImpl == BitVectorImplementation)
-#else
if ( ( (nIntervals > 1) && (maxMember <= 255) )
|| (bmsize < rlsize) )
-#endif
{
*alignment = bma;
*ppCreateSet = BitVectorCreateSet;
@@ -509,183 +436,3 @@ RecordCreateSet(pIntervals, nIntervals, pMem, memsize)
}
return (*pCreateSet)(pIntervals, nIntervals, pMem, size);
}
-
-/***************************************************************************/
-
-#ifdef TESTING
-
-/*
-
-Test Strategy
-
-Having two set representations is convenient for testing because we
-can play them against each other. The test code will be able to
-specify which implementation to use. This breaks the encapsulation,
-but that seems acceptable for testing. The crux of the test loop
-looks like this:
-
-loop:
- generate random list of Intervals
-
- create set A using bit vector implementation
- create set B using Interval list implementation
-
- for each possible set member
- if set A and set B disagree on whether this is a member error;
-
- iterate over both sets, comparing the intervals returned by each.
- if intervals or number of intervals are different error;
-
- iterate over intervals of set A
- for i = interval.first to interval.last
- if i is not a member of set B error;
-
- iterate over intervals of set B
- for i = interval.first to interval.last
- if i is not a member of set A error;
-
- destroy sets A, B
-
-*/
-
-int GenerateRandomIntervals(pIntervals, maxintervals)
- RecordSetInterval *pIntervals;
- int maxintervals;
-{
- int i, nIntervals;
-
- nIntervals = rand() % maxintervals;
-
- for (i = 0; i < nIntervals; i++)
- {
- pIntervals[i].first = rand();
- pIntervals[i].last = pIntervals[i].first + rand();
- }
- return nIntervals;
-}
-
-#define MAXINTERVALS 100
-
-int main(argc, argv)
- int argc;
- char **argv;
-{
- RecordSetPtr bs, rs;
- RecordSetInterval br, rr;
- RecordSetIteratePtr bi, ri;
- CARD16 i;
- int testcount;
- RecordSetInterval intervals[MAXINTERVALS];
- int nIntervals;
- int bsize, rsize;
- int balign, ralign;
- int pad;
-
- for (testcount = 0; 1; testcount++)
- {
- nIntervals = GenerateRandomIntervals(intervals, MAXINTERVALS);
- printf("%d nIntervals %d\n", testcount, nIntervals);
-
- if (testcount & 1)
- {
- _RecordForceSetImplementation(BitVectorImplementation);
- bsize = RecordSetMemoryRequirements(intervals, nIntervals, &balign);
- _RecordForceSetImplementation(IntervalListImplementation);
- rsize = RecordSetMemoryRequirements(intervals, nIntervals, &ralign);
- pad = (ralign - (bsize & (ralign - 1))) & (ralign - 1);
- bs = (RecordSetPtr)malloc(bsize + pad + rsize );
- if (!bs)
- {
- fprintf(stderr, "%d: failed to alloc memory for sets\n",
- testcount);
- continue;
- }
- rs = (RecordSetPtr)(((char *)bs) + bsize + pad);
- }
- else
- {
- bs = rs = NULL;
- bsize = rsize = 0;
- }
-
- _RecordForceSetImplementation(BitVectorImplementation);
- bs = RecordCreateSet(intervals, nIntervals, bs, bsize);
- _RecordForceSetImplementation(IntervalListImplementation);
- rs = RecordCreateSet(intervals, nIntervals, rs, rsize);
-
- if (!bs || !rs)
- {
- fprintf(stderr, "%d: failed to create sets\n", testcount);
- continue;
- }
-
- for (i = 0; i < 65535; i++)
- {
- unsigned long b, r;
-
- b = RecordIsMemberOfSet(bs, i);
- r = RecordIsMemberOfSet(rs, i);
- if ( (b && !r) || (!b && r) )
- {
- fprintf(stderr, "%d: isMemberOfSet %d\n",
- testcount, (int)i);
- }
- }
-
- bi = RecordIterateSet(bs, NULL, &br);
- ri = RecordIterateSet(rs, NULL, &rr);
-
- while (bi && ri)
- {
- if ( (rr.first != br.first) || (rr.last != br.last) )
- {
- fprintf(stderr, "%d: iterateSet interval value mismatch\n",
- testcount);
- }
- bi = RecordIterateSet(bs, bi, &br);
- ri = RecordIterateSet(rs, ri, &rr);
- }
- if (bi != ri)
- {
- fprintf(stderr, "%d: iterateSet interval count mismatch\n",
- testcount);
- }
-
-
- bi = NULL;
- while (bi = RecordIterateSet(bs, bi, &br))
- {
- for (i = br.first; i <= br.last; i++)
- {
- if (!RecordIsMemberOfSet(rs, i))
- {
- fprintf(stderr, "%d: iterateSet b / isMemberOfSet r %d\n",
- testcount, (int)i);
- }
- }
- }
-
- ri = NULL;
- while (ri = RecordIterateSet(rs, ri, &rr))
- {
- for (i = rr.first; i <= rr.last; i++)
- {
- if (!RecordIsMemberOfSet(bs, i) )
- {
- fprintf(stderr, "%d: iterateSet r / isMemberOfSet b %d\n",
- testcount, (int)i);
- }
- }
- }
-
- RecordDestroySet(bs);
- RecordDestroySet(rs);
-
- if (testcount & 1)
- {
- free(bs);
- }
- }
-}
-
-#endif /* TESTING */