Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Your Todo: NthElement #7

Open
kak0na opened this issue Feb 18, 2025 · 2 comments · May be fixed by #8
Open

Your Todo: NthElement #7

kak0na opened this issue Feb 18, 2025 · 2 comments · May be fixed by #8
Labels
enhancement New feature or request

Comments

@kak0na
Copy link

kak0na commented Feb 18, 2025

This is the NthElement function I wrote

template
void NthElement(T* First, T* Nth, T* Last, TFunctionRef<int(T, T)> Comparator)
{
// TODO: Use faster algorithm such as introselect.
//QuickSort(First, Last - 1, Comparator);
while (true)
{
T* Pivot = First;
T* Left = First + 1;
T* Right = Last - 1;

	while (Left <= Right)
	{
		while (Left <= Right && Comparator(*Left, *Pivot) == 1) Left++;
		while (Left <= Right && Comparator(*Right, *Pivot) == -1) Right--;
		if (Left <= Right)
		{
			Swap(Left, Right);
			Left++;
			Right--;
		}
	}

	Swap(Pivot, Right);

	if (Right == Nth)
	{
		break;
	}
	else if (Nth < Right)
	{
		Last = Right;
	}
	else
	{
		First = Left;
	}
}

}

@kak0na kak0na added the enhancement New feature or request label Feb 18, 2025
@nutti
Copy link
Owner

nutti commented Feb 21, 2025

Thank you @kak0na

You can send the pull request also.
https://github.com/nutti/UEPlugin-Kdtree/pulls
Are you willing to do this?

@kak0na
Copy link
Author

kak0na commented Feb 22, 2025

Thank you.
I am willing.

@nutti nutti linked a pull request Feb 22, 2025 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants