Skip to content

Conversation

@reosfire
Copy link
Contributor

@reosfire reosfire commented May 2, 2025

Current code working in O(n * c) where n is children count and c is count we are going to remove.
This is the optimization to O(n)

Also I don't understand how is it possible that child view from __children list has other container as a parent. Is it expected behavior? If not then maybe the code should throw instead of returning everywhere?

@soywiz soywiz requested a review from Copilot May 2, 2025 07:19
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR optimizes the child removal functionality in the Container by changing the removeChildAt method to work in O(n) time instead of O(n²). It includes updated tests that assert the correct count of removed children and validate proper reindexing of remaining children.

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
korge/test/korlibs/korge/view/ContainerTest.kt Added tests to verify removal count and child reindexing behavior
korge/src/korlibs/korge/view/Container.kt Optimized removeChildAt method to remove multiple children in one pass (O(n))

@soywiz soywiz changed the title removeChildAt in O(n) instead of O(n^2) removeChildAt in O(n) instead of O(n^2) and simplify removeChild May 5, 2025
@soywiz soywiz enabled auto-merge (squash) May 5, 2025 07:25
@soywiz
Copy link
Contributor

soywiz commented May 5, 2025

Thanks @reosfire for the PR!

@soywiz soywiz merged commit 0231ec4 into korlibs:main May 5, 2025
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants