Black Lives Matter. Support the Equal Justice Initiative.

Source file src/go/types/objset.go

Documentation: go/types

     1  // Copyright 2013 The Go Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  // This file implements objsets.
     6  //
     7  // An objset is similar to a Scope but objset elements
     8  // are identified by their unique id, instead of their
     9  // object name.
    10  
    11  package types
    12  
    13  // An objset is a set of objects identified by their unique id.
    14  // The zero value for objset is a ready-to-use empty objset.
    15  type objset map[string]Object // initialized lazily
    16  
    17  // insert attempts to insert an object obj into objset s.
    18  // If s already contains an alternative object alt with
    19  // the same name, insert leaves s unchanged and returns alt.
    20  // Otherwise it inserts obj and returns nil.
    21  func (s *objset) insert(obj Object) Object {
    22  	id := obj.Id()
    23  	if alt := (*s)[id]; alt != nil {
    24  		return alt
    25  	}
    26  	if *s == nil {
    27  		*s = make(map[string]Object)
    28  	}
    29  	(*s)[id] = obj
    30  	return nil
    31  }
    32  

View as plain text