mrhooray/kdtree-rs

Question about U on kdtre.rs

Closed this issue · 2 comments

Hi,

I'm interested in space aware datastructures and just learning rust, I was wondering what does the U: AsRef<f64> means in the kdtree.rs file. Does it mean that there should be a generic parameter U that defaults to a slice of f64 items that are default implemented and functions like:

    pub fn nearest<F>(&self,
                      point: &[f64],
                      num: usize,
                      distance: &F)
                      -> Result<Vec<(f64, &T)>, ErrorKind>

can be implemented to use a type U rather than f64?

It means that the structure can hold the "point" data in any type as long as it implements AsRef<[f64]> AsRef is from https://doc.rust-lang.org/std/convert/trait.AsRef.html
That is a type that that can be seean as a &[f64]. There are a lot of types that can be seen as a slice of f64. Vec or Arrays or slices or any custom types that chooses to implement the trait. Does that make sense?

@Eh2406 oh, thanks, ye, just to see if I understood well, if I implement my own structure, with wathever fields, and then implement the trait, then I can store elements of that structure in the kdtree, sweet 😄