Files
free-code/src/utils/set.ts
T
instructkr 4b9d30f795 asdf
Squash the current repository state back into one baseline commit while
preserving the README reframing and repository contents.

Constraint: User explicitly requested a single squashed commit with subject "asdf"
Confidence: high
Scope-risk: broad
Reversibility: clean
Directive: This commit intentionally rewrites published history; coordinate before future force-pushes
Tested: git status clean; local history rewritten to one commit; force-pushed main to origin and instructkr
Not-tested: Fresh clone verification after push
2026-03-31 03:34:03 -07:00

54 lines
1.0 KiB
TypeScript

/**
* Note: this code is hot, so is optimized for speed.
*/
export function difference<A>(a: Set<A>, b: Set<A>): Set<A> {
const result = new Set<A>()
for (const item of a) {
if (!b.has(item)) {
result.add(item)
}
}
return result
}
/**
* Note: this code is hot, so is optimized for speed.
*/
export function intersects<A>(a: Set<A>, b: Set<A>): boolean {
if (a.size === 0 || b.size === 0) {
return false
}
for (const item of a) {
if (b.has(item)) {
return true
}
}
return false
}
/**
* Note: this code is hot, so is optimized for speed.
*/
export function every<A>(a: ReadonlySet<A>, b: ReadonlySet<A>): boolean {
for (const item of a) {
if (!b.has(item)) {
return false
}
}
return true
}
/**
* Note: this code is hot, so is optimized for speed.
*/
export function union<A>(a: Set<A>, b: Set<A>): Set<A> {
const result = new Set<A>()
for (const item of a) {
result.add(item)
}
for (const item of b) {
result.add(item)
}
return result
}