LEFT | RIGHT |
(no file at all) | |
1 // Copyright 2014 The Go Authors. All rights reserved. | 1 // Copyright 2014 The Go Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style | 2 // Use of this source code is governed by a BSD-style |
3 // license that can be found in the LICENSE file. | 3 // license that can be found in the LICENSE file. |
4 | 4 |
5 package runtime | 5 package runtime |
6 | 6 |
7 import "unsafe" | 7 import "unsafe" |
8 | 8 |
9 const ( | 9 const ( |
10 c0 = uintptr((8-uint64(ptrSize))/4*2860486313 + (uint64(ptrSize)-4)/4*33
054211828000289) | 10 c0 = uintptr((8-uint64(ptrSize))/4*2860486313 + (uint64(ptrSize)-4)/4*33
054211828000289) |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
104 return f64hash(&x[1], 4, f64hash(&x[0], 4, h)) | 104 return f64hash(&x[1], 4, f64hash(&x[0], 4, h)) |
105 } | 105 } |
106 | 106 |
107 func nohash(a unsafe.Pointer, s uintptr, h uintptr) uintptr { | 107 func nohash(a unsafe.Pointer, s uintptr, h uintptr) uintptr { |
108 panic(errorString("hash of unhashable type")) | 108 panic(errorString("hash of unhashable type")) |
109 } | 109 } |
110 | 110 |
111 func interhash(a *interface { | 111 func interhash(a *interface { |
112 f() | 112 f() |
113 }, s uintptr, h uintptr) uintptr { | 113 }, s uintptr, h uintptr) uintptr { |
114 » return 0 | 114 » tab := (*iface)(unsafe.Pointer(a)).tab |
| 115 » if tab == nil { |
| 116 » » return h |
| 117 » } |
| 118 » t := tab._type |
| 119 » fn := goalg(t.alg).hash |
| 120 » if **(**uintptr)(unsafe.Pointer(&fn)) == nohashcode { |
| 121 » » // calling nohash will panic too, |
| 122 » » // but we can print a better error. |
| 123 » » panic(errorString("hash of unhashable type " + *t._string)) |
| 124 » } |
| 125 » if uintptr(t.size) <= ptrSize { |
| 126 » » return c1 * fn(unsafe.Pointer(&(*eface)(unsafe.Pointer(a)).data)
, uintptr(t.size), h^c0) |
| 127 » } else { |
| 128 » » return c1 * fn((*eface)(unsafe.Pointer(a)).data, uintptr(t.size)
, h^c0) |
| 129 » } |
115 } | 130 } |
116 | 131 |
117 func nilinterhash(a *interface{}, s uintptr, h uintptr) uintptr { | 132 func nilinterhash(a *interface{}, s uintptr, h uintptr) uintptr { |
118 t := (*eface)(unsafe.Pointer(a))._type | 133 t := (*eface)(unsafe.Pointer(a))._type |
119 if t == nil { | 134 if t == nil { |
120 return h | 135 return h |
121 } | 136 } |
122 fn := goalg(t.alg).hash | 137 fn := goalg(t.alg).hash |
123 if **(**uintptr)(unsafe.Pointer(&fn)) == nohashcode { | 138 if **(**uintptr)(unsafe.Pointer(&fn)) == nohashcode { |
124 // calling nohash will panic too, | 139 // calling nohash will panic too, |
(...skipping 21 matching lines...) Expand all Loading... |
146 return goalg(&algarray[alg_MEM]).hash(*(*unsafe.Pointer)(unsafe.Pointer(
&b)), uintptr(len(b)), seed) | 161 return goalg(&algarray[alg_MEM]).hash(*(*unsafe.Pointer)(unsafe.Pointer(
&b)), uintptr(len(b)), seed) |
147 } | 162 } |
148 | 163 |
149 func int32Hash(i uint32, seed uintptr) uintptr { | 164 func int32Hash(i uint32, seed uintptr) uintptr { |
150 return goalg(&algarray[alg_MEM32]).hash(noescape(unsafe.Pointer(&i)), 4,
seed) | 165 return goalg(&algarray[alg_MEM32]).hash(noescape(unsafe.Pointer(&i)), 4,
seed) |
151 } | 166 } |
152 | 167 |
153 func int64Hash(i uint64, seed uintptr) uintptr { | 168 func int64Hash(i uint64, seed uintptr) uintptr { |
154 return goalg(&algarray[alg_MEM64]).hash(noescape(unsafe.Pointer(&i)), 8,
seed) | 169 return goalg(&algarray[alg_MEM64]).hash(noescape(unsafe.Pointer(&i)), 8,
seed) |
155 } | 170 } |
LEFT | RIGHT |