| Q D E V _ H L P _ D E L T A I T E R ( )
| | | | | SOURCE: qdev_macros.txt 1.16 (12/09/2014) English
AMIGA - PUBLIC
----------------------------------------------------------------------------
NAME
QDEV_HLP_DELTAITER() - Allows to traverse Amiga, doubly
linked list in a fast way.
SYNOPSIS
QDEV_HLP_DELTAITER(lh, type, h, t);
QDEV_HLP_DELTAITER(
struct List *, <type>, <node_h>, <node_t>);
FUNCTION
This macro allows to traverse the Amiga, doubly linked
list by reducing number of iterations by a half by
examining head and tail entries at once. Principle of
operation on a list of 10 nodes explained:
Regular walkthrough gets slower and slower as it goes.
1 2 3 4 5 6 7 8 9 10
-> -> -> -> -> -> -> -> -> -> E = End
Delta scan slows down only to a certain point (half the
regular scan).
1 2 3 4 5 6 7 8 9 10
-> -> -> -> -> E <- <- <- <- <-
So it looks like this in reality which means that even
entry miss is faster and bottom entries can be found
with the same overhead as the top ones:
1 & 10 2 & 9 3 & 8 4 & 7 5 & 6
-> -> -> -> -> E
INPUTS
list - Addr. of the list (struct List, struct MinList).
type - Typecasting of the <node_(h|t)> pointer.
h - Head node pointer (entry from the top).
t - Tail node pointer (entry from the bottom).
RETURNS
No output.
BASES
None.
NOTES
This macro does not cache ln_Succ, ln_Pred pointers so
it is not safe to call 'Remove()' during iteration!
This macro was designed mainly to quickly compare the
node addresses. It is most probably useless for other
purposes (counting, data extraction, etc). Use helper
macros QDEV_HLP_DELTA#? to match and stop at the delta
point.
All OS lists can be traversed with this macro but some
sort of arbitration must be provided. This is typically
to be Forbid()/Permit() pair.
SEE ALSO
QDEV_HLP_ISLISTEMPTY(), QDEV_HLP_ITERATE(),
QDEV_HLP_DELTASCAN()
EXAMPLE
#include <proto/exec.h>
#include <qdev.h>
LONG isonlist(struct List *lh, void *node)
{
REGISTER struct Node *a;
REGISTER struct Node *b;
REGISTER LONG res = 0;
/*
* Enter forbidden state in case of OS list.
*/
QDEV_HLP_NOSWITCH
(
QDEV_HLP_DELTAITER(lh, struct Node *, a, b)
{
if (((res = QDEV_HLP_DELTAADDR(node, a, b))) ||
QDEV_HLP_DELTACOND(struct Node *, a, b))
{
break;
}
}
);
return res;
}
BUGS
None known.
----------------------------------------------------------------------------
| |
| |