How to remove the key from the `redBlackTree` with comparator" a <= b "?

anonymous via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sun Jun 7 12:11:23 PDT 2015


On Sunday, 7 June 2015 at 19:04:08 UTC, Dennis Ritchie wrote:
> OK. But I want to return a `upperBound` segment with the 
> included `key`. It does not suit me:
>
> auto rbt = redBlackTree!("a < b", int)(1, 2, 3, 4, 5);
> writeln(rbt.upperBound(3)); // prints [4, 5]
>
> I want it to be so:
>
> auto rbt = redBlackTree!("a <= b", int)(1, 2, 3, 4, 5);
> writeln(rbt.upperBound(3)); // prints [3, 4, 5]
>
> How do I do with the comparator "a < b" ?

Use equalRange to get the elements that equal 3, too:
writeln(std.range.chain(rbt.equalRange(3), rbt.upperBound(3)));



More information about the Digitalmars-d-learn mailing list