View source code
Display the source code in std/algorithm/setops.d from which this page was generated on
github.
Improve this page
Quickly fork, edit online, and submit a pull request for this page.
Requires a signed-in GitHub account. This works well for small changes.
If you'd like to make larger changes you may want to consider using
local clone.
Page wiki
View or edit the community-maintained wiki page associated with this page.
Function std.algorithm.setops.largestPartialIntersectionWeighted
Similar to
, but associates a weight
with each distinct element in the intersection.
largestPartialIntersection
Prototype
void largestPartialIntersectionWeighted(alias less, RangeOfRanges, Range, WeightsAA)( RangeOfRanges ror, Range tgt, WeightsAA weights, SortOutput sorted = SortOutput.no );
Parameters
Name | Description |
---|---|
less | The predicate the ranges are sorted by. |
ror | A range of forward ranges sorted by less . |
tgt | The target range to copy common elements to. |
weights | An associative array mapping elements to weights . |
sorted | Whether the elements copied should be in sorted order. |
Example
// Figure which number can be found in most arrays of the set of // arrays below, with specific per-element weights double[][] a = [ [ 1, 4, 7, 8 ], [ 1, 7 ], [ 1, 7, 8], [ 4 ], [ 7 ], ]; auto b = new Tuple!(double, uint)[1]; double[double] weights = [ 1:1.2, 4:2.3, 7:1.1, 8:1.1 ]; largestPartialIntersectionWeighted(a, b, weights); // First member is the item, second is the occurrence count assert(b[0] == tuple(4.0, 2u));
The correct answer in this case is 4.0
, which, although only
appears two times, has a total weight 4.6
(three times its weight
2.3
). The value 7
is weighted with 1.1
and occurs four
times for a total weight 4.4
.