/*
- * Bacula doubly linked list routines.
+ * Bacula doubly linked list routines.
*
* dlist is a doubly linked list with the links being in the
* list data item.
- *
+ *
* Kern Sibbald, July MMIII
*
* Version $Id$
/*
* Append an item to the list
*/
-void dlist::append(void *item)
+void dlist::append(void *item)
{
((dlink *)(((char *)item)+loffset))->next = NULL;
((dlink *)(((char *)item)+loffset))->prev = tail;
/*
* Append an item to the list
*/
-void dlist::prepend(void *item)
+void dlist::prepend(void *item)
{
((dlink *)(((char *)item)+loffset))->next = head;
((dlink *)(((char *)item)+loffset))->prev = NULL;
((dlink *)(((char *)head)+loffset))->prev = item;
}
head = item;
- if (tail == NULL) { /* if empty list, */
+ if (tail == NULL) { /* if empty list, */
tail = item; /* item is tail too */
}
num_items++;
}
-void dlist::insert_before(void *item, void *where)
+void dlist::insert_before(void *item, void *where)
{
- dlink *where_link = (dlink *)((char *)where+loffset);
+ dlink *where_link = (dlink *)((char *)where+loffset);
((dlink *)(((char *)item)+loffset))->next = where;
((dlink *)(((char *)item)+loffset))->prev = where_link->prev;
num_items++;
}
-void dlist::insert_after(void *item, void *where)
+void dlist::insert_after(void *item, void *where)
{
- dlink *where_link = (dlink *)((char *)where+loffset);
+ dlink *where_link = (dlink *)((char *)where+loffset);
((dlink *)(((char *)item)+loffset))->next = where_link->next;
((dlink *)(((char *)item)+loffset))->prev = where;
return item;
}
if (num_items == 1) {
- comp = compare(item, first());
+ comp = compare(item, first());
if (comp < 0) {
prepend(item);
//Dmsg0(000, "Insert before first.\n");
cur++;
}
while (nxt < cur) {
- cur_item = prev(cur_item);
+ cur_item = prev(cur_item);
cur--;
}
//Dmsg1(000, "Compare item to %d\n", cur);
jcr_chain = (dlist *)malloc(sizeof(dlist));
jcr_chain->init(jcr, &jcr->link);
-
+
printf("Prepend 20 items 0-19\n");
for (int i=0; i<20; i++) {
sprintf(buf, "This is dlist item %d", i);
jcr_chain->remove(save_jcr);
printf("Re-insert 10th item\n");
jcr_chain->insert_before(jcr, next_jcr);
-
+
printf("Print remaining list.\n");
foreach_dlist (jcr, jcr_chain) {
printf("Dlist item = %s\n", jcr->buf);
jcr_chain->remove(save_jcr);
printf("Re-insert 10th item\n");
jcr_chain->insert_before(jcr, next_jcr);
-
+
printf("Print remaining list.\n");
foreach_dlist (jcr, jcr_chain) {
printf("Dlist item = %s\n", jcr->buf);
for (int k=0; k<CNT; k++) {
count++;
if ((count & 0x3FF) == 0) {
- Dmsg1(000, "At %d\n", count);
+ Dmsg1(000, "At %d\n", count);
}
jcr = (MYJCR *)malloc(sizeof(MYJCR));
jcr->buf = bstrdup(buf);
jcr1 = (MYJCR *)jcr_chain->binary_insert(jcr, my_compare);
if (jcr != jcr1) {
- Dmsg2(000, "Insert of %s vs %s failed.\n", jcr->buf, jcr1->buf);
+ Dmsg2(000, "Insert of %s vs %s failed.\n", jcr->buf, jcr1->buf);
}
buf[1]--;
}
- buf[1] = 'Z';
+ buf[1] = 'Z';
buf[2]--;
}
buf[2] = 'Z';