Skip to main content

Hasher

Struct Hasher 

Source
pub struct Hasher { /* private fields */ }
Expand description

A structure for creating sortable spatio-temporal hashes with millisecond temporal precision.

Implementations§

Source§

impl Hasher

Source

pub fn global( start_datetime: DateTime<Utc>, end_datetime: DateTime<Utc>, ) -> Result<Self>

Creates a new hasher for the given datetime and the global extents.

§Examples
use stac_hash::Hasher;
use chrono::{Utc, TimeZone};

let start_datetime = Utc.with_ymd_and_hms(2026, 1, 1, 0, 0, 0).unwrap();
let end_datetime = Utc.with_ymd_and_hms(2027, 1, 1, 0, 0, 0).unwrap();
let hasher = Hasher::global(start_datetime, end_datetime).unwrap();
Source

pub fn new( start_datetime: DateTime<Utc>, end_datetime: DateTime<Utc>, min: impl Into<Point>, max: impl Into<Point>, ) -> Result<Self>

Creates a new hasher for the given datetime and spatial intervals.

§Examples
use stac_hash::Hasher;
use chrono::{Utc, TimeZone};

// CONUS (roughly)
let start_datetime = Utc.with_ymd_and_hms(2026, 1, 1, 0, 0, 0).unwrap();
let end_datetime = Utc.with_ymd_and_hms(2027, 1, 1, 0, 0, 0).unwrap();
let hasher = Hasher::new(start_datetime, end_datetime, (-125., 25.), (-66., 50.)).unwrap();
Source

pub fn hash( &self, datetime: DateTime<Utc>, point: impl Into<Point>, ) -> Result<u64>

Converts a datetime and a Point into a hash.

Returns an error if the datetime or the point falls outside of this hasher’s extent. Use Hasher::hash_clamped to clamp onto the boundary instead of erroring.

§Examples
use stac_hash::Hasher;
use chrono::{Utc, TimeZone};

let start = Utc.with_ymd_and_hms(2023, 1, 1, 0, 0, 0).unwrap();
let end = Utc.with_ymd_and_hms(2024, 1, 1, 0, 0, 0).unwrap();
let hasher = Hasher::global(start, end).unwrap();
let hash = hasher.hash(start, (0., 0.)).unwrap();
Source

pub fn hash_clamped( &self, datetime: DateTime<Utc>, point: impl Into<Point>, ) -> u64

Converts a datetime and a Point into a hash, clamping anything outside of this hasher’s extent onto its boundary.

This cannot fail. A datetime before start_datetime hashes as start_datetime, a longitude west of the minimum hashes as that minimum, and so on. Each clamped value is logged at warn level. Use Hasher::hash to get an error instead.

§Examples
use stac_hash::Hasher;
use chrono::{Utc, TimeZone};

let start = Utc.with_ymd_and_hms(2026, 1, 1, 0, 0, 0).unwrap();
let end = Utc.with_ymd_and_hms(2027, 1, 1, 0, 0, 0).unwrap();
let hasher = Hasher::new(start, end, (-109., 37.), (-102., 41.)).unwrap();

// Well west of the bounding box, so it hashes as if it were on the edge.
let hash = hasher.hash_clamped(start, (-120., 40.));
assert_eq!(hash, hasher.hash(start, (-109., 40.)).unwrap());

Trait Implementations§

Source§

impl Debug for Hasher

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

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.