Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
adopt interning for set operations (#231)
- Loading branch information
Showing
15 changed files
with
83 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,19 @@ | ||
export default function superset(values, other) { | ||
const iterator = values[Symbol.iterator](), set = new Set(); | ||
for (const o of other) { | ||
if (set.has(o)) continue; | ||
const io = intern(o); | ||
if (set.has(io)) continue; | ||
let value, done; | ||
while (({value, done} = iterator.next())) { | ||
if (done) return false; | ||
set.add(value); | ||
if (Object.is(o, value)) break; | ||
const ivalue = intern(value); | ||
set.add(ivalue); | ||
if (Object.is(io, ivalue)) break; | ||
} | ||
} | ||
return true; | ||
} | ||
|
||
function intern(value) { | ||
return value !== null && typeof value === "object" ? value.valueOf() : value; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,9 @@ | ||
import assert from "assert"; | ||
import {InternSet} from "internmap"; | ||
|
||
export function assertSetEqual(A, B) { | ||
assert(setEqual(A, B)); | ||
} | ||
|
||
function setEqual(A, B) { | ||
if (!(A instanceof Set)) throw new Error("not a set"); | ||
for (const a of A) if (!B.has(a)) return false; | ||
for (const b of B) if (!A.has(b)) return false; | ||
return true; | ||
export function assertSetEqual(actual, expected) { | ||
assert(actual instanceof Set); | ||
expected = new InternSet(expected); | ||
for (const a of actual) assert(expected.has(a), `unexpected ${a}`); | ||
for (const e of expected) assert(actual.has(e), `expected ${e}`); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters