github.com/jingcheng-WU/gonum@v0.9.1-0.20210323123734-f1a2a11a8f7b/graph/internal/set/same.go (about)

     1  // Copyright ©2014 The Gonum 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  // +build !safe
     6  
     7  package set
     8  
     9  import "unsafe"
    10  
    11  // same determines whether two sets are backed by the same store. In the
    12  // current implementation using hash maps it makes use of the fact that
    13  // hash maps are passed as a pointer to a runtime Hmap struct. A map is
    14  // not seen by the runtime as a pointer though, so we use unsafe to get
    15  // the maps' pointer values to compare.
    16  func same(a, b Nodes) bool {
    17  	return *(*uintptr)(unsafe.Pointer(&a)) == *(*uintptr)(unsafe.Pointer(&b))
    18  }
    19  
    20  // intsSame determines whether two sets are backed by the same store. In the
    21  // current implementation using hash maps it makes use of the fact that
    22  // hash maps are passed as a pointer to a runtime Hmap struct. A map is
    23  // not seen by the runtime as a pointer though, so we use unsafe to get
    24  // the maps' pointer values to compare.
    25  func intsSame(a, b Ints) bool {
    26  	return *(*uintptr)(unsafe.Pointer(&a)) == *(*uintptr)(unsafe.Pointer(&b))
    27  }
    28  
    29  // int64sSame determines whether two sets are backed by the same store. In the
    30  // current implementation using hash maps it makes use of the fact that
    31  // hash maps are passed as a pointer to a runtime Hmap struct. A map is
    32  // not seen by the runtime as a pointer though, so we use unsafe to get
    33  // the maps' pointer values to compare.
    34  func int64sSame(a, b Int64s) bool {
    35  	return *(*uintptr)(unsafe.Pointer(&a)) == *(*uintptr)(unsafe.Pointer(&b))
    36  }