<commit_before>// based on @researchgate/react-intersection-observer
import { parseRootMargin, shallowCompareOptions } from '../lib/utils'

export function getPooled(options = {}) {
    const root = options.root || null
    const rootMargin = parseRootMargin(options.rootMargin)
    const threshold = Array.isArray(options.threshold)
        ? options.threshold
        : [options.threshold != null ? options.threshold : 0]

    for (const observer of storage.keys()) {
        const unmatched = [
            [root, observer.root],
            [rootMargin, observer.rootMargin],
            [threshold, observer.thresholds],
        ].some(option => shallowCompareOptions(...option))

        if (!unmatched) {
            return observer
        }
    }

    return null
}

export const storage = new Map()

export default class ObserverContainer {
    static create(callback, options) {
        return getPooled(options) || new IntersectionObserver(callback, options)
    }

    static findElement(entry, observer) {
        const elements = storage.get(observer)
        if (elements) {
            for (const element of elements.values()) {
                if (element.target === entry.target) {
                    return element
                }
            }
        }

        return null
    }

    static observe(element) {
        let targets

        if (storage.has(element.observer)) {
            targets = storage.get(element.observer)
        } else {
            targets = new Set()
            storage.set(element.observer, targets)
        }

        targets.add(element)
        element.observer.observe(element.target)
    }

    static unobserve(element) {
        if (storage.has(element.observer)) {
            const targets = storage.get(element.observer)

            if (targets.delete(element)) {
                if (targets.size > 0) {
                    element.observer.unobserve(element.target)
                } else {
                    element.observer.disconnect()
                    storage.delete(element.observer)
                }
            }
        }
    }

    static clear() {
        storage.clear()
    }

    static count() {
        return storage.size
    }
}
<commit_msg>Remove indirect Symbol polyfill requirement<commit_after>// based on @researchgate/react-intersection-observer
import { parseRootMargin, shallowCompareOptions } from '../lib/utils'

export function getPooled(options = {}) {
    const root = options.root || null
    const rootMargin = parseRootMargin(options.rootMargin)
    const threshold = Array.isArray(options.threshold)
        ? options.threshold
        : [options.threshold != null ? options.threshold : 0]

    const observers = storage.keys()

    for (let observer = observers.next(); !observer.done; observer = observers.next()) {
        const unmatched =
            shallowCompareOptions(root, observer.value.root) ||
            shallowCompareOptions(rootMargin, observer.value.rootMargin) ||
            shallowCompareOptions(threshold, observer.value.threshold)

        if (!unmatched) {
            return observer.value
        }
    }

    return null
}

export const storage = new Map()

export default class ObserverContainer {
    static create(callback, options) {
        return getPooled(options) || new IntersectionObserver(callback, options)
    }

    static findElement(entry, observer) {
        const observerElements = storage.get(observer)

        if (observerElements) {
            const elements = observerElements.values()

            for (let element = elements.next(); !element.done; element = elements.next()) {
                if (element.value.target === entry.target) {
                    return element.value
                }
            }
        }

        return null
    }

    static observe(element) {
        let targets

        if (storage.has(element.observer)) {
            targets = storage.get(element.observer)
        } else {
            targets = new Set()
            storage.set(element.observer, targets)
        }

        targets.add(element)
        element.observer.observe(element.target)
    }

    static unobserve(element) {
        if (storage.has(element.observer)) {
            const targets = storage.get(element.observer)

            if (targets.delete(element)) {
                if (targets.size > 0) {
                    element.observer.unobserve(element.target)
                } else {
                    element.observer.disconnect()
                    storage.delete(element.observer)
                }
            }
        }
    }

    static clear() {
        storage.clear()
    }

    static count() {
        return storage.size
    }
}

{'fraction_non_alphanumeric': 0.10059296908089793, 'fraction_numerical': 0.0008470986869970351, 'mean_word_length': 1.890452876376989, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6066512', 'n_tokens_mistral': 1239, 'n_tokens_neox': 1172, 'n_words': 260}