Jump to content
  • Advertisement
Sign in to follow this  

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

This topic is 3321 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
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!