const int IL_MAX = 128;
+ERASEABLE
void IL_INIT(entity this);
+ERASEABLE
void IL_DTOR(entity this);
+ERASEABLE
void IL_ENDFRAME();
/**
* freed entities must be removed from the list
*/
CLASS(IntrusiveList, Object)
- ATTRIB(IntrusiveList, il_head, entity, NULL);
- ATTRIB(IntrusiveList, il_tail, entity, NULL);
+ ATTRIB(IntrusiveList, il_head, entity);
+ ATTRIB(IntrusiveList, il_tail, entity);
ATTRIB(IntrusiveList, il_nextfld, .entity, nil);
ATTRIB(IntrusiveList, il_prevfld, .entity, nil);
INIT(IntrusiveList) { IL_INIT(this); }
#define IL_LAST(this) (this.il_tail)
#define IL_PEEK(this) (this.il_tail)
+ERASEABLE
bool IL_CONTAINS(IntrusiveList this, entity it)
{
assert(this, return false);
/**
* Push to tail
*/
+ERASEABLE
entity IL_PUSH(IntrusiveList this, entity it)
{
assert(this, return NULL);
/**
* Push to head
*/
+ERASEABLE
entity IL_UNSHIFT(IntrusiveList this, entity it)
{
assert(this, return NULL);
/**
* Pop from tail
*/
+ERASEABLE
entity IL_POP(IntrusiveList this)
{
assert(this, return NULL);
/**
* Pop from head
*/
+ERASEABLE
entity IL_SHIFT(IntrusiveList this)
{
assert(this, return NULL);
/**
* Remove any element, anywhere in the list
*/
+ERASEABLE
void IL_REMOVE(IntrusiveList this, entity it)
{
assert(this, return);
.entity il_next = this.il_nextfld;
.entity il_prev = this.il_prevfld;
+ //assert(!IL_CONTAINS(this, it), return);
entity next = it.(il_next);
entity prev = it.(il_prev);
entity ohead = this.il_head;
entity otail = this.il_tail;
next ? next.(il_prev) = prev : this.il_tail = prev;
prev ? prev.(il_next) = next : this.il_head = next;
- LOG_DEBUGF("remove %i (%i :: %i), head: %i -> %i, tail: %i -> %i\n", it, it.(il_prev), it.(il_next), ohead, this.il_head, otail, this.il_tail);
+ LOG_DEBUGF("remove %i (%i :: %i), head: %i -> %i, tail: %i -> %i", it, it.(il_prev), it.(il_next), ohead, this.il_head, otail, this.il_tail);
it.(il_next) = it.(il_prev) = NULL;
}
*/
#define IL_CLEAR(this) \
MACRO_BEGIN \
- { \
IntrusiveList __il = this; \
assert(__il); \
.entity il_prev = __il.il_prevfld; \
IL_EACH(__il, true, it.(il_next) = it.(il_prev) = NULL); \
__il.il_head = __il.il_tail = NULL; \
- } MACRO_END
+ MACRO_END
/**
* Delete the list
*/
-#define IL_DELETE(this, dtor) \
+#define IL_DELETE(this) \
MACRO_BEGIN \
- { \
- remove(this); \
+ delete(this); \
this = NULL; \
- } MACRO_END
+ MACRO_END
#define IL_EACH(this, cond, body) \
MACRO_BEGIN \
- { \
IntrusiveList _il = this; \
assert(_il); \
.entity il_next = _il.il_nextfld; \
_next = it.(il_next); \
if (cond) { LAMBDA(body) } \
} \
- } MACRO_END
+ MACRO_END
.int il_id;
IntrusiveList il_links[IL_MAX];
#define IL_LISTS_PER_BIT IL_CEIL(IL_MAX / (3 * 24))
+ERASEABLE
void IL_INIT(IntrusiveList this)
{
.entity nextfld, prevfld;
return;
}
}
- LOG_WARNINGF("IntrusiveList overflow");
+ LOG_WARN("IntrusiveList overflow");
}
+ERASEABLE
void IL_DTOR(IntrusiveList this)
{
IL_CLEAR(this);
il_links[this.il_id] = NULL;
}
+ERASEABLE
void IL_ENDFRAME()
{
#if 0
#endif
}
+ERASEABLE
void ONREMOVE(entity this)
{
if (this.il_lists) {
for (int i = 0; i < IL_MAX; ++i) {
IntrusiveList list = il_links[i];
- if (this.il_lists & list.il_listmask && IL_CONTAINS(list, this)) {
+ if ((this.il_lists & list.il_listmask) && IL_CONTAINS(list, this)) {
IL_REMOVE(list, this);
}
}