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

OrderedMap: Fix skipping elements while iterating with deletion #350

Merged
merged 3 commits into from
Feb 26, 2024

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
7 checks passed
@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
3 participants