Skip to content

Conversation

@RamanaReddy0M
Copy link
Contributor

@RamanaReddy0M RamanaReddy0M commented Feb 26, 2024

Code can be updated with this snippest:

func main() {
	om := mapsutil.NewOrderedMap[string, string]()
	om.Set("offset", "0")
	om.Set("limit", "10")
	om.Set("sort", "desc")
	om.Set("cwe-id", "CWE-77")

	ignoreKeys := []string{"offset", "limit", "sort"}

	om.Iterate(func(key string, value string) bool {
		fmt.Println(key, value)
		for _, ignoreKey := range ignoreKeys {
			if key == ignoreKey {
				om.MarkDelete(key)
				break
			}
		}
		return true
	})
	om.PruneDeleted()
}

Copy link
Member

@tarunKoyalwar tarunKoyalwar left a comment

Choose a reason for hiding this comment

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

minor updated, instead of marking delete outside we use dirty byte internally to track state when iterating

@tarunKoyalwar tarunKoyalwar merged commit 44db4d1 into main Feb 26, 2024
@tarunKoyalwar tarunKoyalwar deleted the bug-in-ordered-map branch February 26, 2024 18:19
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.

Bug: Skipping the elements while iterating with deletion operation

4 participants