* tree-ssa-reassoc.c (reassociate_bb): Clarify code slighly.
[official-gcc.git] / libgo / go / go / types / objset.go
blob55eb74addbae5e69fa19d15f9bd7966e793631b3
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.
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.
11 package types
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
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
26 if *s == nil {
27 *s = make(map[string]Object)
29 (*s)[id] = obj
30 return nil