std.container.rbtree as Interval Tree?
RazvanN
razvan.nitu1305 at gmail.com
Tue Feb 5 10:10:44 UTC 2019
On Monday, 4 February 2019 at 22:54:01 UTC, James Blachly wrote:
> I tried to implement an interval tree backed by
> std.container.rbtree today and fell flat.
>
> [...]
You can use alias this [1] in your interval element type:
struct IntervalElem
{
size_t start, end;
/* ... other declarations */
alias start this;
}
[1] https://dlang.org/spec/class.html#AliasThis
> Q2: Would replacing "Elem" with a generic type "T" in the
> function signatures for upperBound, lowerBound, and various
> related fns like _firstGreater / _firstGreaterEqual solve this
> problem?
>
> [...]
Elem is already a generic type. I don't know how you can make it
more generic without adding other template parameters to the
class declaration (which means reimplementing RBTree from
std.container);
> James
>
> [1] https://dlang.org/spec/operatoroverloading.html#eqcmp ("For
> example ... x and y are disjoint sets, then neither x < y nor y
> < x holds, but that does not imply that x == y. Thus, it is
> insufficient to determine equality purely based on opCmp alone.
> ")
More information about the Digitalmars-d-learn
mailing list