PtrSet.xcc
Benoit Dupont de Dinechin (Benoit.Dupont-de-Dinechin@st.com)
Copyright 2007 STMicroelectronics. Copyright 1995 - 1998 Commissariat a l'Energie Atomique.
This program is free software; you can redistribute it and/or modify it under the terms of either (at your option): the GNU General Public License (GPL) version 2; the GNU Lesser General Public License (LGPL) version 2.1; any later version of these licences as published by the Free Software Foundation.
PtrSetMember_GT— Compare two PtrSetMembers for less than.
PtrSetMember_LT— Compare two PtrSetMembers for greater than.
PtrSetMember_EQ— Compare two PtrSetMembers for equality
PtrSetMember_NE— Compare two PtrSetMembers for non-equality
#define PtrSetMember_GT(a, b) ((uintptr_t)(a) > (uintptr_t)(b)) #define PtrSetMember_LT(a, b) ((uintptr_t)(a) < (uintptr_t)(b)) #define PtrSetMember_EQ(a, b) ((a) == (b)) #define PtrSetMember_NE(a, b) ((a) != (b))
PtrSet— Pointer Set implemented as an array ordered in decreasing order.
struct PtrSet_ { //@args Memory memory, int32_t maxCount Memory MEMORY; // Where the PtrSet members are allocated. uint32_t STATUS; // MAXCOUNT:31;ISORDERED:1; //@access ISORDERED (PtrSet_STATUS(this)&0x1) //@access MAXCOUNT (int32_t)(PtrSet_STATUS(this)>>1) //@access MAXSIZE (PtrSet_MAXCOUNT(this)*sizeof(PtrSetMember)) PtrSetMember *BASE; PtrSetMember *PAST; //@access USEDSIZE ((char*)PtrSet_PAST(this) - (char*)PtrSet_BASE(this)) };
PtrSet_resize— Resize this PtrSet.
- maxCount
- The new
maxCount
.
void PtrSet_resize(PtrSet this, int32_t maxCount);
PtrSet_empty— Empty this PtrSet.
void PtrSet_empty(PtrSet this);
PtrSet_checkOrder— Check order of this PtrSet.
bool PtrSet_checkOrder(const_PtrSet this);
PtrSet_base— For use by PtrSet_FOREACH.
static inline const PtrSetMember * PtrSet_base(const_PtrSet this) { return (const PtrSetMember *)PtrSet_BASE(this); }
PtrSet_past— For use by PtrSet_FOREACH.
static inline const PtrSetMember * PtrSet_past(const_PtrSet this) { return (const PtrSetMember *)PtrSet_PAST(this); }
PtrSet_FOREACH— Iterates over the PtrSet members.
#define PtrSet_FOREACH(this, Type, member) { \ const PtrSetMember *PtrSet_BASE = PtrSet_base(this); \ const PtrSetMember *PtrSet_PAST = PtrSet_past(this); \ if (PtrSet_BASE != PtrSet_PAST) { \ const PtrSetMember *(PtrSet_ITER) = PtrSet_PAST - 1; \ for (; PtrSet_ITER >= PtrSet_BASE; --(PtrSet_ITER)) { \ Type member = (Type)*(PtrSet_ITER); #define PtrSet_ENDEACH \ } \ } \ }
PtrSet_FORSORT— Iterates over the sorted PtrSet members.
#define PtrSet_FORSORT(this, compare, Type, member) { \ PtrSetMemberCompare PtrSet_COMPARE = (PtrSetMemberCompare)(compare); \ uint32_t PtrSet_COUNT = PtrSet_count(this), PtrSet_I = 0; \ const PtrSetMember *PtrSet_BASE = PtrSet_base(this); \ const PtrSetMember *PtrSet_PAST = PtrSet_past(this), *(PtrSet_ITER); \ PtrSetMember *PtrSet_ARRAY = alloca(sizeof(PtrSetMember)*PtrSet_COUNT); \ for (PtrSet_I = 0, PtrSet_ITER = PtrSet_BASE; \ PtrSet_ITER < PtrSet_PAST; ++(PtrSet_ITER), ++PtrSet_I) \ PtrSet_ARRAY[PtrSet_I] = *(PtrSet_ITER); \ HackerPtr_Sort(PtrSet_ARRAY, 0, PtrSet_COUNT - 1, PtrSet_COMPARE); \ for (PtrSet_I = 0; PtrSet_I < PtrSet_COUNT; PtrSet_I++) { \ Type member = (Type)PtrSet_ARRAY[PtrSet_I]; #define PtrSet_ENDSORT \ } \ }
PtrSet_isFull— True iff this PtrSet is full.
static inline bool PtrSet_isFull(const_PtrSet this) { int32_t maxCount = PtrSet_MAXCOUNT(this); PtrSetMember *base = PtrSet_BASE(this); PtrSetMember *past = PtrSet_PAST(this); return past - base == maxCount; }
PtrSet_addMember— Add a member to the PtrSet, resizing the PtrSet if necessary. As the PtrSet may be resized, it is an error to maintain pointers to existing members.
void PtrSet_addMember(PtrSet this, PtrSetMember member);
PtrSet_makeOrder— Reorder this PtrSet members after calls to PtrSet_addMember.
Use the en.wikibook.org heapsort, then call PtrSet_uniq.
int32_t PtrSet_makeOrder(PtrSet this);
PtrSet_memory— This PtrSet memory.
static inline Memory PtrSet_memory(const_PtrSet this) { return PtrSet_MEMORY(this); }
PtrSet_isEmpty— True iff this PtrSet is empty.
static inline bool PtrSet_isEmpty(const_PtrSet this) { PtrSetMember *base = PtrSet_BASE(this); PtrSetMember *past = PtrSet_PAST(this); return past == base; }
PtrSet_isSingle— True iff this PtrSet contains a single member.
static inline bool PtrSet_isSingle(const_PtrSet this) { PtrSetMember *base = PtrSet_BASE(this); PtrSetMember *past = PtrSet_PAST(this); return past - base == 1; }
PtrSet_count— Count members contained in the PtrSet.
- Return
- The count of members in this PtrSet.
static inline int32_t PtrSet_count(const_PtrSet this) { PtrSetMember *base = PtrSet_BASE(this); PtrSetMember *past = PtrSet_PAST(this); return past - base; }
PtrSet_isOrdered— This PtrSet ordered status.
static inline bool PtrSet_isOrdered(const_PtrSet this) { return PtrSet_ISORDERED(this); }
PtrSet_clearOrdered— Set this PtrSet status as unordered.
static inline void PtrSet_clearOrdered(PtrSet this) { *PtrSet__STATUS(this) &= ~0x1; }
PtrSet_base_— Base of this PtrSet for use by external sort.
static inline PtrSetMember * PtrSet_base_(PtrSet this) { *PtrSet__STATUS(this) &= ~0x1; return PtrSet_BASE(this); }
PtrSet_contains— Test a member for containment.
- Return
- True if this PtrSet contains member.
bool PtrSet_contains(const_PtrSet this, PtrSetMember member);
PtrSet_insert— Insert a member in this PtrSet.
- Return
- False iff member was already contained in this PtrSet.
bool PtrSet_insert(PtrSet this, PtrSetMember member);
PtrSet_remove— Remove a member from this PtrSet.
- Return
- False iff member was not contained in this PtrSet.
bool PtrSet_remove(PtrSet this, PtrSetMember member);
PtrSet_choose— Choose and remove a member of the PtrSet.
static inline PtrSetMember PtrSet_choose(PtrSet this) { PtrSetMember *past = PtrSet_PAST(this); Except_REQUIRE(!PtrSet_isEmpty(this)); Except_REQUIRE(PtrSet_isOrdered(this)); *PtrSet__PAST(this) = past - 1; return *(PtrSetMember *)(past - 1); }
PtrSet_equals— Test for PtrSet equality.
bool PtrSet_equals(const_PtrSet this, const_PtrSet that);
PtrSet_assign— Assign the contents of that PtrSet to this PtrSet.
void PtrSet_assign(PtrSet this, const_PtrSet that);
PtrSet_comprises— True iff this PtrSet comprises that PtrSet.
bool PtrSet_comprises(const_PtrSet this, const_PtrSet that);
PtrSet_union— Union of this PtrSet with that PtrSet.
bool PtrSet_union(PtrSet this, const_PtrSet that);
PtrSet_inter— Intersect this PtrSet with that PtrSet.
bool PtrSet_inter(PtrSet this, const_PtrSet that);
PtrSet_overlap— Check if this PtrSet and that PtrSet overlap.
bool PtrSet_overlap(const_PtrSet this, const_PtrSet that);
PtrSet_diff— Remove that PtrSet members from this PtrSet.
bool PtrSet_diff(PtrSet this, const_PtrSet that);