#rust equivalent to java navigable set
14 messages · Page 1 of 1 (latest)
you might be looking for https://doc.rust-lang.org/nightly/std/collections/struct.BTreeSet.html#method.range
it's a bit more generic of an api, as it takes a range and returns an iterator of elements, but set.higher(x) could be done with
set.range(x..).next()
```and `set.lower(x)` with
```rs
set.range(..x).next_back()
does this work when x is not an integer, but is a linesegment?
it just has an Ord and PartialOrd implementation
BTreeSet::range accepts any range that satisfies RangeBounds<T>, which includes (Bound<T>, Bound<T>) so in your case, you could use
(BoundIncluded(x) Bound::Unbounded)
```for a `x..` equivalent and
```rs
(Bound::Unbounded, BoundExcluded(x))
```for a `..x` equivalent
THANK YOU
seems that the std docs actually use BtreeMap::range in their example of Bound: https://doc.rust-lang.org/nightly/std/ops/enum.Bound.html#examples
though they do it with integers, which is a bit weird
yea
the fact that im not using integers confused me in how id use that