| 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 "reflect" |
| 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 reflect to get |
| 16 | // the maps' pointer values to compare. |
| 17 | func same(a, b Nodes) bool { |
| 18 | return reflect.ValueOf(a).Pointer() == reflect.ValueOf(b).Pointer() |
| 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 reflect to get |
| 25 | // the maps' pointer values to compare. |
| 26 | func intsSame[T Int](a, b Ints[T]) bool { |
| 27 | return reflect.ValueOf(a).Pointer() == reflect.ValueOf(b).Pointer() |
| 28 | } |