from typing import Iterator
import json


def dictsets_match(dictset_1: Iterator[dict], dictset_2: Iterator[dict]):
    """
    Tests if two dictsets match regardless of the order of the order of the
    records in the dictset. Return is True if the sets match.

    Note that this will exhaust a generator.

    Parameters:
        dictset_1: iterable of dictionaries:
            The first dictset to match
        dictset_2: iterable of dictionaries:
            The second dictset to match

    Returns:
        boolean
    """

    def _hash_set(dictset: Iterator[dict]):
        xor = 0
        for record in dictset:
            entry = json.serialize(record)  # type:ignore
            _hash = hash(entry)
            xor = xor ^ _hash
        return xor

    return _hash_set(dictset_1) == _hash_set(dictset_2)