import { computeBufferAttributeHash } from "./computeBufferAttributeHash.js";
import { computeStringHash } from "../../../../core/primitives/strings/computeStringHash.js";

/**
 *
 * @param {THREE.BufferGeometry} geometry
 * @returns {number}
 */
export function computeGeometryHash(geometry) {
    let hash = 0;
    const attributes = geometry.attributes;

    for (const attributesKey in attributes) {
        hash = hash * 31 + computeStringHash(attributesKey);
    }

    hash ^= computeBufferAttributeHash(geometry.getIndex());

    const position_attribute = geometry.getAttribute('position');

    if (position_attribute !== undefined) {
        hash ^= computeBufferAttributeHash(position_attribute);
    }

    return hash;
}
