Skip to main content

Tree2D

Struct Tree2D 

Source
pub struct Tree2D<C, V> { /* private fields */ }
Expand description

Two-dimensional tree that maps a location given by [C; 2] to a value V.

§References

Implementations§

Source§

impl Tree2D<i64, String>

Source

pub fn write(&self, writer: impl Write) -> Result<()>

Available on crate feature std only.

Writes the tree into a stream in RGC format.

RGC is an internal format of this crate that uses columnar storage to compress the data.

Source

pub fn read(reader: impl Read) -> Result<Self>

Available on crate feature std only.

Reads a tree from the stream in RGC format.

§RGC format

RGC is an internal format of this crate that uses columnar storage to compress the data. To obtain a file in such a format you can use CLI utility provided in the Git repo. You can use any OSM-PBF file as an input.

In the following script europe-latest.osm.pbf (32 GiB) is used as an input. CLI utiliy extracts names from each node, compresses them, and produces other.rgc.zst and settlements.rgc.zst. The total size of the resulting files is around 200 MiB.

cargo run --bin geo-coding-cli --release -- convert europe-latest.osm.pbf
Source§

impl<C: Ord + Copy + Default, V: Default> Tree2D<C, V>

Source

pub fn from_nodes(nodes: Vec<([C; 2], V)>) -> Self

Create a new tree from the given nodes.

The nodes are recursively subdividded into two groups: one that is behind and one that is in front of the plane that goes through the median node. The plane alternates between x = 0 and y = 0 for each layer of the tree.

The values are moved from the vector without copying.

Source

pub fn find_nearest<D>( &self, location: &[C; 2], max_distance: D, max_neighbours: usize, calc_distance: impl FnMut(&[C; 2], &[C; 2]) -> D, ) -> Vec<(D, &[C; 2], &V)>
where D: Ord + Copy + Display,

Returns up to max_neighbours nodes within max_distance that are closest to the location.

The distance between nodes is computed using calc_distance.

Source

pub fn iter(&self) -> impl Iterator<Item = (&[C; 2], &V)>

Returns an iterator over nodes.

Source

pub fn len(&self) -> usize

Returns the number of nodes.

Source

pub fn is_empty(&self) -> bool

Returns true if the tree is empty.

Trait Implementations§

Source§

impl<C: Debug, V: Debug> Debug for Tree2D<C, V>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<C: PartialEq, V: PartialEq> PartialEq for Tree2D<C, V>

Source§

fn eq(&self, other: &Tree2D<C, V>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<C: Eq, V: Eq> Eq for Tree2D<C, V>

Source§

impl<C, V> StructuralPartialEq for Tree2D<C, V>

Auto Trait Implementations§

§

impl<C, V> Freeze for Tree2D<C, V>

§

impl<C, V> RefUnwindSafe for Tree2D<C, V>

§

impl<C, V> Send for Tree2D<C, V>
where V: Send, C: Send,

§

impl<C, V> Sync for Tree2D<C, V>
where V: Sync, C: Sync,

§

impl<C, V> Unpin for Tree2D<C, V>
where V: Unpin, C: Unpin,

§

impl<C, V> UnsafeUnpin for Tree2D<C, V>

§

impl<C, V> UnwindSafe for Tree2D<C, V>
where V: UnwindSafe, C: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.