github.com/gopherjs/gopherjs@v1.19.0-beta1.0.20240506212314-27071a8796e4/compiler/typesutil/typenames.go (about)

     1  package typesutil
     2  
     3  import "go/types"
     4  
     5  // TypeNames implements an ordered set of *types.TypeName pointers.
     6  //
     7  // The set is ordered to ensure deterministic behavior across compiler runs.
     8  type TypeNames struct {
     9  	known map[*types.TypeName]struct{}
    10  	order []*types.TypeName
    11  }
    12  
    13  // Add a type name to the set. If the type name has been previously added,
    14  // this operation is a no-op. Two type names are considered equal iff they have
    15  // the same memory address.
    16  func (tn *TypeNames) Add(name *types.TypeName) {
    17  	if _, ok := tn.known[name]; ok {
    18  		return
    19  	}
    20  	if tn.known == nil {
    21  		tn.known = map[*types.TypeName]struct{}{}
    22  	}
    23  	tn.order = append(tn.order, name)
    24  	tn.known[name] = struct{}{}
    25  }
    26  
    27  // Slice returns set elements in the order they were first added to the set.
    28  func (tn *TypeNames) Slice() []*types.TypeName {
    29  	return tn.order
    30  }