src

Go monorepo.
git clone git://code.dwrz.net/src
Log | Files | Refs

scope.go (601B)


      1 // Copyright 2021 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 package trie
      6 
      7 import (
      8 	"strconv"
      9 	"sync/atomic"
     10 )
     11 
     12 // Scope represents a distinct collection of maps.
     13 // Maps with the same Scope can be equal. Maps in different scopes are distinct.
     14 // Each Builder creates maps within a unique Scope.
     15 type Scope struct {
     16 	id int32
     17 }
     18 
     19 var nextScopeId atomic.Int32
     20 
     21 func newScope() Scope {
     22 	id := nextScopeId.Add(1)
     23 	return Scope{id: id}
     24 }
     25 
     26 func (s Scope) String() string {
     27 	return strconv.Itoa(int(s.id))
     28 }