TinyBase logoTinyBase β

addOrRemoveHash

The addOrRemoveHash function combines two hashes together, which, because it is a simple alias for bitwise XOR, serves both as addition and removal of one hash from the other.

addOrRemoveHash(
  hash1: number,
  hash2: number,
): Hash
TypeDescription
hash1number

A first hash.

hash2number

A second hash to add or remove from the first.

returnsHash

The resulting hash of the two hashes added to or removed from each other.

This is used internally within TinyBase to collate hashes of objects, such as producing a hash for a Table which is composed of the hashes of its Rows.

Example

This example adds two hashes together.

import {addOrRemoveHash} from 'tinybase';

const hash1 = 123456789;
const hash2 = 987654321;
console.log(addOrRemoveHash(hash1, hash2));
// -> 1032168868

console.log(addOrRemoveHash(1032168868, hash1));
// -> 987654321
console.log(addOrRemoveHash(1032168868, hash2));
// -> 123456789

Since

v6.2.0