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

analyzer: refactor value type of neededPackages map #37

Merged
merged 1 commit into from
Nov 26, 2024

Conversation

alexandear
Copy link
Contributor

@alexandear alexandear commented Nov 21, 2024

The boolean value of the neededPackages[fname] map is never used, so we can change it to struct{}.

@catenacyber
Copy link
Owner

Why does this matter ?
I find bool more readable than struct even if I miss a good golang set to use instead of this kind of map

@ccoVeille
Copy link

It's about memory allocation. map[whatever]struct{} are known to be memory efficient, but also to be used for deduplication of keys of the map.

Right now with slices and map packages. I don't see them much

@catenacyber
Copy link
Owner

It's about memory allocation. map[whatever]struct{} are known to be memory efficient

TIL

but also to be used for deduplication of keys of the map.

How so ?

@catenacyber catenacyber merged commit d9131b0 into catenacyber:main Nov 26, 2024
1 check passed
@alexandear alexandear deleted the refactor/needed-pkgs-map branch November 26, 2024 21:46
@ccoVeille
Copy link

but also to be used for deduplication of keys of the map.

How so ?

Like a for loop

known := make(maps[string]struct{})
for _, v := range []string{"aa", "bb", "aa"} {
    if _, found := known[v]; found {
        continue
    }
    known[v] = struct{}{}

    // do something, like a log, reading a file
}

But now you have methods like slices.Sort + slices.Compacts

They can be used with maps.Keys or maps.Values

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.

3 participants