gonum.org/v1/gonum@v0.15.1-0.20240517103525-f853624cb1bb/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 //go:build !safe 6 // +build !safe 7 8 package set 9 10 import "unsafe" 11 12 // same determines whether two sets are backed by the same store. In the 13 // current implementation using hash maps it makes use of the fact that 14 // hash maps are passed as a pointer to a runtime Hmap struct. A map is 15 // not seen by the runtime as a pointer though, so we use unsafe to get 16 // the maps' pointer values to compare. 17 func same(a, b Nodes) bool { 18 return *(*uintptr)(unsafe.Pointer(&a)) == *(*uintptr)(unsafe.Pointer(&b)) 19 } 20 21 // intsSame determines whether two sets are backed by the same store. In the 22 // current implementation using hash maps it makes use of the fact that 23 // hash maps are passed as a pointer to a runtime Hmap struct. A map is 24 // not seen by the runtime as a pointer though, so we use unsafe to get 25 // the maps' pointer values to compare. 26 func intsSame[T Int](a, b Ints[T]) bool { 27 return *(*uintptr)(unsafe.Pointer(&a)) == *(*uintptr)(unsafe.Pointer(&b)) 28 }