Started an experimental doubly linked list implementation of attribute lists.

This commit is contained in:
Pietro Gagliardi 2016-12-16 23:31:04 -05:00
parent 6726ab70a9
commit 98082068f6
1 changed files with 52 additions and 0 deletions

52
common/exp_attrdll.c Normal file
View File

@ -0,0 +1,52 @@
// 16 december 2016
struct attr {
uiAttribute type;
uintptr_t val;
size_t start;
size_t end;
struct attr *prev;
struct attr *next;
};
struct attrlist {
struct attr *first;
struct attr *last;
};
void attrlistInsertAt(struct attrlist *alist, uiAttribute type, uintptr_t val, size_t start, size_t end)
{
struct attr *a;
struct attr *after;
a = uiNew(struct attr);
a->type = type;
a->val = val;
a->start = start;
a->end = end;
if (alist->first == NULL) { // empty list
alist->first = a;
alist->last = a;
return;
}
// place a before the first element that starts after a does
for (before = alist->first; before != NULL; before = before->next)
if (before->start > a->start)
break;
if (before == NULL) { // if there is none, add a to the end
alist->last->next = a;
a->prev = alist->last;
alist->last = a;
return;
}
if (before == alist->first)
alist->first = a;
else // not the first; hook up our new prev
before->prev->next = a;
a->next = before;
a->prev = before->prev;
before->prev = a;
}