MCPcopy Create free account
hub / github.com/MagicStack/asyncpg / record_hash

Function record_hash

asyncpg/protocol/record/recordobj.c:244–270  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

242#endif
243
244static Py_hash_t
245record_hash(PyObject *op)
246{
247 ApgRecordObject *v = (ApgRecordObject *)op;
248 Py_uhash_t acc;
249 Py_ssize_t len = Py_SIZE(v);
250 PyObject **item = v->ob_item;
251 acc = _ApgRecord_HASH_XXPRIME_5;
252 for (Py_ssize_t i = 0; i < len; i++) {
253 Py_uhash_t lane = (Py_uhash_t)PyObject_Hash(item[i]);
254 if (lane == (Py_uhash_t)-1) {
255 return -1;
256 }
257 acc += lane * _ApgRecord_HASH_XXPRIME_2;
258 acc = _ApgRecord_HASH_XXROTATE(acc);
259 acc *= _ApgRecord_HASH_XXPRIME_1;
260 }
261
262 /* Add input length, mangled to keep the historical value of hash(()). */
263 acc += (Py_uhash_t)len ^ (_ApgRecord_HASH_XXPRIME_5 ^ 3527539UL);
264
265 if (acc == (Py_uhash_t)-1) {
266 acc = 1546275796;
267 }
268
269 return (Py_hash_t)acc;
270}
271
272static Py_ssize_t
273record_length(PyObject *self)

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected