Oh, now I see what you mean.
You’re right, the “purge algorithm” will always remove the items in the order they appear in the playlist, not in the order they were actually played. The reason is that that information may not be consistent or even unavailable (in case the item was manually marked as played by the user).
To give a definitive answer to your questions, let’s have a look at the original code:
function CleanUpHistory: boolean;
var
i: integer;
canDelete: boolean;
begin
Result := false;
i := 0;
while (i < GetCount) and ((fMaxHistoryCount = 0) or (fMaxHistoryCount < GetTotalHistoryCount)) do begin
if Items[i].HistoryFlag then begin
canDelete := true;
DoBeforeDelete(i, false, canDelete);
if canDelete then begin
Items[i].HistoryFlag := false;
Delete(i);
Result := true;
continue;
end;
end
else if (plcoCleanupHistoryTop in fOptions) then break;
inc(i);
end;
end;
The algorithm walks through the playlist and expects each item, one by one, until it reaches the end of the playlist or the desired total number of played items (GetTotalHistoryCount) is reached. When it encounters an item with the HistoryFlag set, it checks if it can be deleted (not locked by any player etc.), and if so, deletes it from the playlist, also resetting the HistoryFlag. The Delete() function does not only delete it from the playlist but also gathers all deleted items in a temporary playlist which is later appended to the recycle bin. That happens outside this function.
Now it’s pretty obvious what the plcoCleanupHistoryTop option does: As soon as it encounters an item whose HistoryFlag is not set (that is, the item is still active), it just stops the algorithm. In other words, when the option is enabled, at item will never be moved to the history as long as at least one non-history item exists above it.
When the option is turned off, it can in fact happen that a non-topmost item is purged, namely when the total number of history items exceeds the threshold, that is, when there are n or more history items below that item.
Just try it for your self: Take a fresh playlist, then mark item #2 as played, and then items #5, #6, #7. Item #2 will be removed, although item #1 is still active.