#ifndef _TKINTSET
# error "do not include this private header file"
#endif
#ifndef _TKINTSETPRIV
#define _TKINTSETPRIV
MODULE_SCOPE bool TkIntSetContains__(
const TkIntSetType *set1, const TkIntSetType *end1,
const TkIntSetType *set2, const TkIntSetType *end2);
MODULE_SCOPE bool TkIntSetDisjunctive__(
const TkIntSetType *set1, const TkIntSetType *end1,
const TkIntSetType *set2, const TkIntSetType *end2);
MODULE_SCOPE bool TkIntSetIsEqual__(
const TkIntSetType *set1, const TkIntSetType *end1,
const TkIntSetType *set2, const TkIntSetType *end2);
#endif
#ifdef _TK_NEED_IMPLEMENTATION
#include <assert.h>
#ifdef _MSC_VER
# if _MSC_VER >= 1900
# define inline __inline
# else
# define inline
# endif
#elif __STDC_VERSION__ < 199901L
# define inline
#endif
extern TkIntSetType *
TkIntSetLowerBound(
TkIntSetType *first,
TkIntSetType *last,
TkIntSetType value);
inline
const unsigned char *
TkIntSetData(
const TkIntSet *set)
{
assert(set);
return (const void *) set->buf;
}
inline
unsigned
TkIntSetByteSize(
const TkIntSet *set)
{
assert(set);
return (set->end - set->buf)*sizeof(TkIntSetType);
}
inline
bool
TkIntSetIsEmpty(
const TkIntSet *set)
{
assert(set);
return set->end == set->buf;
}
inline
bool
TkIntSetIsEqual(
const TkIntSet *set1,
const TkIntSet *set2)
{
assert(set1);
assert(set2);
return set1 == set2 || TkIntSetIsEqual__(set1->buf, set1->end, set2->buf, set2->end);
}
inline
bool
TkIntSetContains(
const TkIntSet *set1,
const TkIntSet *set2)
{
assert(set1);
assert(set2);
return set1 == set2 || TkIntSetContains__(set1->buf, set1->end, set2->buf, set2->end);
}
inline
bool
TkIntSetDisjunctive(
const TkIntSet *set1,
const TkIntSet *set2)
{
assert(set1);
assert(set2);
if (set1 == set2) {
return TkIntSetIsEmpty(set1);
}
return TkIntSetDisjunctive__(set1->buf, set1->end, set2->buf, set2->end);
}
inline
unsigned
TkIntSetSize(
const TkIntSet *set)
{
assert(set);
return set->end - set->buf;
}
inline
unsigned
TkIntSetMax(
const TkIntSet *set)
{
assert(!TkIntSetIsEmpty(set));
return set->end[-1];
}
inline
unsigned
TkIntSetRefCount(
const TkIntSet *set)
{
assert(set);
return set->refCount;
}
inline
void
TkIntSetIncrRefCount(TkIntSet *set)
{
assert(set);
set->refCount += 1;
}
inline
unsigned
TkIntSetDecrRefCount(TkIntSet *set)
{
unsigned refCount;
assert(set);
assert(set->refCount > 0);
if ((refCount = --set->refCount) == 0) {
TkIntSetDestroy(&set);
}
return refCount;
}
inline
TkIntSetType
TkIntSetAccess(
const TkIntSet *set,
unsigned index)
{
assert(set);
assert(index < TkIntSetSize(set));
return set->buf[index];
}
inline
void
TkIntSetChange(
TkIntSet *set,
unsigned index,
unsigned n)
{
assert(set);
assert(index < TkIntSetSize(set));
set->buf[index] = n;
}
inline
bool
TkIntSetTest(
const TkIntSet *set,
unsigned n)
{
const TkIntSetType *pos;
assert(set);
pos = TkIntSetLowerBound(((TkIntSet *) set)->buf, ((TkIntSet *) set)->end, n);
return pos < set->end && *pos == n;
}
inline
bool
TkIntSetNone(
const TkIntSet *set)
{
assert(set);
return set->buf == set->end;
}
inline
bool
TkIntSetAny(
const TkIntSet *set)
{
assert(set);
return set->buf < set->end;
}
inline
bool
TkIntSetIntersects(
const TkIntSet *set1,
const TkIntSet *set2)
{
return !TkIntSetDisjunctive(set1, set2);
}
inline
unsigned
TkIntSetFindNext(
const TkIntSet *set)
{
assert(set);
return set->curr == set->end ? TK_SET_NPOS : *(((TkIntSet *) set)->curr++);
}
inline
unsigned
TkIntSetFindFirst(
const TkIntSet *set)
{
assert(set);
((TkIntSet *) set)->curr = ((TkIntSet *) set)->buf;
return TkIntSetFindNext(set);
}
inline
TkIntSet *
TkIntSetAddOrErase(
TkIntSet *set,
unsigned n,
bool add)
{
assert(set);
return add ? TkIntSetAdd(set, n) : TkIntSetErase(set, n);
}
#undef _TK_NEED_IMPLEMENTATION
#endif