Skip to content

Internal representation #5

@Y-Less

Description

@Y-Less

If you don't see it on the other fork:

karimcambridge/samp-foreach#10 (comment)

For reference, your Iter_Remove:

foreach/foreach.inc

Lines 1543 to 1561 in 9cca892

stock Iter_SafeRemoveInternal(&count, array[], value, &last, size)
{
if (0 <= value < size && array[value] <= size) {
last = size;
new
next = array[last];
while (next < size) {
if (next == value) {
array[last] = array[value];
array[value] = size + 1;
--count;
return 1;
}
last = next;
next = array[last];
}
}
return 0;
}

My current one:

https://github.com/Misiur/YSI-Includes/blob/6e34cff72408958ca7f800d97eca529db2972713/YSI_Data/y_foreach/impl.inc#L426-L440

stock Iter_SafeRemove_InternalC(&count, array[], size, value, &last)
{
	if (0 <= value < size++ && array[value] > value)
	{
		// This version has reverse iterators, which need maintaining, and can
		// be used in place of a loop to jump backwards in the list.
		return
			--count,
			last = (array[(value - 1) % size] - 1) % size,
			array[last] = array[value],
			array[value] = value,
			array[(array[last] - 1) % size] = (last + 1) % size;
	}
	return INVALID_ITERATOR_SLOT;
}

(Don't know why it didn't make that link to the other repository in to a nice box).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions