Skip to content

Commit

Permalink
sql/catalog: add String and SafeFormat methods to DescriptorIDSet
Browse files Browse the repository at this point in the history
Epic: none

Release note: None
  • Loading branch information
ajwerner committed Mar 27, 2023
1 parent 20e41ff commit 2b1482e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
1 change: 1 addition & 0 deletions pkg/sql/catalog/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ go_library(
"//pkg/util/iterutil",
"@com_github_cockroachdb_errors//:errors",
"@com_github_cockroachdb_redact//:redact",
"@com_github_cockroachdb_redact//interfaces",
],
)

Expand Down
14 changes: 14 additions & 0 deletions pkg/sql/catalog/descriptor_id_set.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,25 @@ package catalog
import (
"github.com/cockroachdb/cockroach/pkg/sql/catalog/descpb"
"github.com/cockroachdb/cockroach/pkg/util/intsets"
"github.com/cockroachdb/redact"
"github.com/cockroachdb/redact/interfaces"
)

// DescriptorIDSet efficiently stores an unordered set of descriptor ids.
type DescriptorIDSet struct {
set intsets.Fast
}

// SafeFormat implements SafeFormatter for DescriptorIDSet.
func (d *DescriptorIDSet) SafeFormat(s interfaces.SafePrinter, verb rune) {
s.SafeString(redact.SafeString(d.String()))
}

// String implement fmt.Stringer for DescriptorIDSet.
func (d *DescriptorIDSet) String() string {
return d.set.String()
}

// MakeDescriptorIDSet returns a set initialized with the given values.
func MakeDescriptorIDSet(ids ...descpb.ID) DescriptorIDSet {
s := DescriptorIDSet{}
Expand All @@ -32,6 +44,8 @@ func MakeDescriptorIDSet(ids ...descpb.ID) DescriptorIDSet {
// Suppress the linter.
var _ = MakeDescriptorIDSet

var _ redact.SafeFormatter = (*DescriptorIDSet)(nil)

// Add adds an id to the set. No-op if the id is already in the set.
func (d *DescriptorIDSet) Add(id descpb.ID) {
d.set.Add(int(id))
Expand Down

0 comments on commit 2b1482e

Please sign in to comment.