| 123456789101112131415161718192021 |
- "use strict";
- Object.defineProperty(exports, "__esModule", { value: true });
- exports.buffersXOR = exports.bufferXOR = void 0;
- const buffer_1 = require("buffer");
- // Often in the code, when we want to calculate a content-based ID, where the content is an unordered set, we compute the XOR of the content-based IDs of the set elements. This is because XOR is insensitive to order.
- // Precondition that is NOT CHECKED: buffers must be of equal length
- // Returns new buffer that is bitwise XOR of inputs.
- function bufferXOR(a, b) {
- const result = buffer_1.Buffer.allocUnsafe(a.length);
- for (let i = 0; i < a.length; i += 4) {
- // Little endian is fastest, because native to Intel CPUs
- result.writeInt32LE(a.readInt32LE(i) ^ b.readInt32LE(i), i);
- }
- return result;
- }
- exports.bufferXOR = bufferXOR;
- function buffersXOR(...args) {
- return args.reduce((a, b) => bufferXOR(a, b), buffer_1.Buffer.alloc(32));
- }
- exports.buffersXOR = buffersXOR;
- //# sourceMappingURL=buffer_xor.js.map
|