Sign in to follow this  

[C#] I'm looking for a more efficient way of removing items from a list

This topic is 3100 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi guys, Currently I have a list of stored Quads that must have their Index_ properties changed when an Quad is removed from 2 other Dictionaries (Vertex & Index). The problem is while this method works, it is far from efficient as it has to iterate through the same list containing all Quads each time a Quad is removed:

        public void RemoveQuad(IQuad quad)
        {
            int iI = quad.Index_Indices;
            int iV = quad.Index_Vertices;

            this.vertices_Dictionary[this.effect_Type].RemoveRange(quad.Index_Vertices, GameConstants.QUAD_NUMBER_OF_VERTICES);
            this.indices_Dictionary[this.effect_Type].RemoveRange(quad.Index_Indices, GameConstants.QUAD_NUMBER_OF_INDICES);

            // Because a Quad has been removed
            foreach (IQuad quad_Stored in quad_List)
            {
                if (quad_Stored.Index_Vertices > iV)
                {
                    quad_Stored.Index_Vertices -= GameConstants.QUAD_NUMBER_OF_VERTICES;
                    quad_Stored.Index_Indices = (quad_Stored.Index_Vertices / GameConstants.QUAD_NUMBER_OF_VERTICES) * 6;
                }
            }

...

As you can see when removing the current Quad (based on the current Quad's Index_Vertices & Index_Indices properties) from the two Dictionaries the remaining Quads must have their Index_ properties updated so they point to the right place in the Dictionaries. The problem is that the foreach iteration is being called every time a Quad is removed, this is far from ideal. How could I go about only having to reorganize all the Quad.Index_Vertices/Indices once after all Quads have been removed. I can't figure out a good way since the Quads would not be deleted in any particular order. Thank you.

Share this post


Link to post
Share on other sites

This topic is 3100 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this