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

[store] use struct{} as a value in a hashset #7718

Merged
merged 1 commit into from
Apr 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions go/store/datas/commit.go
Original file line number Diff line number Diff line change
Expand Up @@ -651,12 +651,12 @@ func GetCommitRootHash(cv types.Value) (hash.Hash, error) {
}

func parentsToQueue(ctx context.Context, commits []*Commit, q *CommitByHeightHeap, vr types.ValueReader) error {
seen := make(map[hash.Hash]bool)
seen := make(map[hash.Hash]struct{})
for _, c := range commits {
if _, ok := seen[c.Addr()]; ok {
continue
}
seen[c.Addr()] = true
seen[c.Addr()] = struct{}{}

parents, err := GetCommitParents(ctx, vr, c.NomsValue())
if err != nil {
Expand Down
6 changes: 3 additions & 3 deletions go/store/nbs/frag/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ func main() {
chartFmt := "| %6d | %7d | %8d | %9d | %6d | %5d | %6d |\n"

var optimal, sum int
visited := map[hash.Hash]bool{}
visited := make(map[hash.Hash]struct{})

current := hash.HashSlice{root}
for numNodes := 1; numNodes > 0; numNodes = len(current) {
Expand All @@ -120,7 +120,7 @@ func main() {
for i, v := range readValues {
h := current[i]
currentValues[h] = v
visited[h] = true
visited[h] = struct{}{}
}

// Iterate all the Values at the current level of the graph IN ORDER (as specified in |current|) and gather up their embedded refs. We'll build two different lists of hash.Hashes during this process:
Expand All @@ -132,7 +132,7 @@ func main() {
for _, h := range current {
_ = types.WalkAddrs(currentValues[h], types.Format_Default, func(h hash.Hash, isleaf bool) error {
orderedChildren = append(orderedChildren, h)
if !visited[h] && !isleaf {
if _, ok := visited[h]; !ok && !isleaf {
nextLevel = append(nextLevel, h)
}
return nil
Expand Down
4 changes: 2 additions & 2 deletions go/store/nbs/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,15 @@ func IterChunks(ctx context.Context, rd io.ReadSeeker, cb func(chunk chunks.Chun

defer idx.Close()

seen := make(map[hash.Hash]bool)
seen := make(map[hash.Hash]struct{})
for i := uint32(0); i < idx.chunkCount(); i++ {
var h hash.Hash
ie, err := idx.indexEntry(i, &h)
if err != nil {
return err
}
if _, ok := seen[h]; !ok {
seen[h] = true
seen[h] = struct{}{}
chunkBytes, err := readNFrom(rd, ie.Offset(), ie.Length())
if err != nil {
return err
Expand Down