View source code
Display the source code in std/algorithm/setops.d from which this
page was generated on github.
Report a bug
If you spot a problem with this page, click here to create a
Bugzilla issue.
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.
Function std.algorithm.setops.largestPartialIntersectionWeighted
Similar to largestPartialIntersection
, but associates a weight
with each distinct element in the intersection.
void largestPartialIntersectionWeighted(alias less, RangeOfRanges, Range, WeightsAA)
(
RangeOfRanges ror,
Range tgt,
WeightsAA weights,
SortOutput sorted = No .sortOutput
);
If at least one of the ranges is a multiset, then all occurences
of a duplicate element are taken into account. The result
is equivalent to merging all input ranges and picking the highest
tgt
, weight-based ranking elements.
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
import std .typecons : tuple, Tuple;
// 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
writeln(b[0]); // tuple(4.0, 2u)
// 4.0 occurs 2 times -> 4.6 (2 * 2.3)
// 7.0 occurs 3 times -> 4.4 (3 * 1.1)
// multiset
double[][] x =
[
[ 1, 1, 1, 4, 7, 8 ],
[ 1, 7 ],
[ 1, 7, 8],
[ 4 ],
[ 7 ],
];
auto y = new Tuple!(double, uint)[1];
largestPartialIntersectionWeighted(x, y, weights);
writeln(y[0]); // tuple(1.0, 5u)
// 1.0 occurs 5 times -> 1.2 * 5 = 6
Authors
License
Copyright © 1999-2022 by the D Language Foundation | Page generated by ddox.