mpdn/radix-heap

Usage with floats as keys

dbdr opened this issue · 3 comments

dbdr commented

I'm trying to use NotNan as keys, as I saw the impl Radix provided. Here is my test code:

use ordered_float::NotNan;

fn main() {
	let heap = radix_heap::RadixHeapMap::new_at(NotNan::new(0.0f64).unwrap());
}

Compilation fails with:

 --> src/main.rs:4:13
  |
4 |     let heap = radix_heap::RadixHeapMap::new_at(NotNan::new(0.0f64).unwrap());
  |                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `radix_heap::Radix` is not implemented for `ordered_float::NotNan<f64>`

Am I doing it wrong?

dbdr commented

I think the issue is related to ordered_float 1.0 deprecating NotNaN and making it a type alias for NotNan. I wonder if it's not a rustc bug though that things don't work through the alias.

mpdn commented

Since this crate depends on 0.5 and you depend on 1.0 and these are not semver compatible, cargo will create two different ordered_float crates; one for each version. So the impl of Radix for NotNaN exists only for the 0.5 version and not the 1.0 version. The error rust displays in this case is confusing though.

The solution would be to either:

  • Lower your dependency version to match radix-heap.
  • Bump the dependency version of radix-heap (I probably ought to do that eventually).
dbdr commented

Thanks for the explanation. Version 0.5 is fine for me right now.