-
Notifications
You must be signed in to change notification settings - Fork 185
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* exclusiveFacets * pad the data with duplicates * reindex * test * done * reindex iterables * reindex symbol --------- Co-authored-by: Philippe Rivière <[email protected]>
- Loading branch information
Showing
6 changed files
with
1,224 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import {reindex, slice} from "../options.js"; | ||
|
||
export function exclusiveFacets(data, facets) { | ||
if (facets.length === 1) return {data, facets}; // only one facet; trivially exclusive | ||
|
||
const n = data.length; | ||
const O = new Uint8Array(n); | ||
let overlaps = 0; | ||
|
||
// Count the number of overlapping indexes across facets. | ||
for (const facet of facets) { | ||
for (const i of facet) { | ||
if (O[i]) ++overlaps; | ||
O[i] = 1; | ||
} | ||
} | ||
|
||
// Do nothing if the facets are already exclusive. | ||
if (overlaps === 0) return {data, facets}; // facets are exclusive | ||
|
||
// For each overlapping index (duplicate), assign a new unique index at the | ||
// end of the existing array, duplicating the datum. For example, [[0, 1, 2], | ||
// [2, 1, 3]] would become [[0, 1, 2], [4, 5, 3]]. Also attach a reindex to | ||
// the data to preserve the association of channel values specified as arrays. | ||
data = slice(data); | ||
const R = (data[reindex] = new Uint32Array(n + overlaps)); | ||
facets = facets.map((facet) => slice(facet, Uint32Array)); | ||
let j = n; | ||
O.fill(0); | ||
for (const facet of facets) { | ||
for (let k = 0, m = facet.length; k < m; ++k) { | ||
const i = facet[k]; | ||
if (O[i]) (facet[k] = j), (data[j] = data[i]), (R[j] = i), ++j; | ||
else R[i] = i; | ||
O[i] = 1; | ||
} | ||
} | ||
|
||
return {data, facets}; | ||
} |
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
Oops, something went wrong.