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

Introduce Map/MapOf configs and grow-only option #132

Merged
merged 1 commit into from
Jun 22, 2024
Merged

Conversation

puzpuzpuz
Copy link
Owner

@puzpuzpuz puzpuzpuz commented Jun 22, 2024

Adds options support to the NewMap/NewMapOf functions. A MapOf can now be created like this:

m := xsync.NewMapOf(WithPresize(100))

Also, adds WithGrowOnly option. It configures new Map/MapOf instance to be grow-only. This means that the underlying hash table grows in capacity when new keys are added, but does not shrink when keys are deleted. The only exception to this rule is the Clear method which shrinks the hash table back to the initial capacity.

Grow-only maps are more efficient in the case of oscillating map size, i.e. when the map frequently grows and then shrinks in size.

@puzpuzpuz puzpuzpuz added the enhancement New feature or request label Jun 22, 2024
@puzpuzpuz puzpuzpuz self-assigned this Jun 22, 2024
@puzpuzpuz puzpuzpuz merged commit ec68f42 into main Jun 22, 2024
8 checks passed
@puzpuzpuz puzpuzpuz deleted the grow-only-maps branch June 22, 2024 05:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant