Skip to content

Commit

Permalink
Merge pull request #7706 from arturmelanchyk/iter-chunks-seen-hashset
Browse files Browse the repository at this point in the history
[store] use struct{} as a value in a hashset
  • Loading branch information
macneale4 committed Apr 10, 2024
2 parents 43849f8 + 607cd02 commit 85183fb
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
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

0 comments on commit 85183fb

Please sign in to comment.