www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - std.container.rbtree has no search method?! e.g. `contains`, `canFind`

reply mw <mingwu gmail.com> writes:
Hi,

on doc:

https://dlang.org/phobos/std_container_rbtree.html#.RedBlackTree

I cannot find any search method?! e.g. `contains`, `canFind`.

Is this a over look? Or there are such functions else where?
Jul 13
next sibling parent Dennis <dkorpel gmail.com> writes:
On Saturday, 13 July 2024 at 17:41:42 UTC, mw wrote:
 I cannot find any search method?! e.g. `contains`, `canFind`.

 Is this a over look? Or there are such functions else where?
It's the `in` operator: https://dlang.org/phobos/std_container_rbtree.html#.RedBlackTree.opBinaryRight But indeed, the documentation can be clearer about that.
Jul 13
prev sibling parent reply Steven Schveighoffer <schveiguy gmail.com> writes:
On Saturday, 13 July 2024 at 17:41:42 UTC, mw wrote:
 Hi,

 on doc:

 https://dlang.org/phobos/std_container_rbtree.html#.RedBlackTree

 I cannot find any search method?! e.g. `contains`, `canFind`.

 Is this a over look? Or there are such functions else where?
The functions are called `equalRange` (which gives you a range of all the elements that compare equal to the parameter), `lowerBound` (all elements less than the parameter), and `upperBound` (all elements greater than the parameter). This was not my choice, my original dcollections implementation used a `find` function. It was a condition for having the type added to phobos. -Steve
Jul 13
parent mw <mingwu gmail.com> writes:
On Sunday, 14 July 2024 at 02:01:44 UTC, Steven Schveighoffer 
wrote:
 On Saturday, 13 July 2024 at 17:41:42 UTC, mw wrote:
 Hi,

 on doc:

 https://dlang.org/phobos/std_container_rbtree.html#.RedBlackTree

 I cannot find any search method?! e.g. `contains`, `canFind`.

 Is this a over look? Or there are such functions else where?
The functions are called `equalRange` (which gives you a range of all the elements that compare equal to the parameter), `lowerBound` (all elements less than the parameter), and `upperBound` (all elements greater than the parameter). This was not my choice, my original dcollections implementation used a `find` function. It was a condition for having the type added to phobos. -Steve
I think for containers, it's better to have uniform naming convention, either `contains`, `canFind` or `in`, so writing generic code (e.g. via D template) is easier.
Jul 14