set.ts
utils/set.ts
No strong subsystem tag
54
Lines
1036
Bytes
4
Exports
0
Imports
10
Keywords
What this is
This page documents one file from the repository and includes its full source so you can read it without leaving the docs site.
Beginner explanation
This file is one piece of the larger system. Its name, directory, imports, and exports show where it fits. Start by reading the exports and related files first.
How it is used
Start from the exports list and related files. Those are the easiest clues for where this file fits into the system.
Expert explanation
Architecturally, this file intersects with general runtime concerns. It contains 54 lines, 0 detected imports, and 4 detected exports.
Important relationships
Detected exports
differenceintersectseveryunion
Keywords
itemresultnotecodeoptimizedspeedsizereadonlysetdifferenceintersects
Detected imports
- No import paths detected.
Source notes
This page embeds the full file contents. Small or leaf files are still indexed honestly instead of being over-explained.
Full source
/**
* 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
}