Struct geohashrust::BinaryHash [] [src]

pub struct BinaryHash { /* fields omitted */ }

Binary hash code for a given GeoLocation with specific precision

Methods

impl BinaryHash
[src]

Create an empty BinaryHash

Create a BinaryHash from a String

Example

let bh=geohashrust::BinaryHash::from_string("11100110");
assert_eq!(bh.to_string(), "11100110");

Encode a GeoLocation into binary hash

Example

let l=geohashrust::GeoLocation{
        latitude:31.23,
        longitude:121.473,
};
let bh=geohashrust::BinaryHash::encode(&l, 8);
assert_eq!(bh.to_string(), "11100110");

Decode binary hash into a BoundingBox

Example

let bh=geohashrust::BinaryHash::from_string("11100");
let bbox=bh.decode();
assert!(bbox.contains(&geohashrust::GeoLocation::from_coordinates(21.0, 113.0)));

Decode binary hash into a BoundingBox

Example

let bbox=geohashrust::BinaryHash::decode_string("11100");
assert!(bbox.contains(&geohashrust::GeoLocation::from_coordinates(21.0, 113.0)));

Convert BinaryHash to a String

Example

let bh=geohashrust::BinaryHash::from_string("11100110");
assert_eq!(bh.to_string(), "11100110");

Return the count of effective bits in the binary hash

Example

let mut bh=geohashrust::BinaryHash::new();
assert_eq!(bh.len(), 0);
bh.push(true);
bh.push(true);
assert_eq!(bh.len(), 2);
bh.push(false);
bh.push(true);
assert_eq!(bh.len(), 4);

Test if the binary hash is empty

Example

let mut bh=geohashrust::BinaryHash::new();
assert!(bh.empty());
bh.push(true);
bh.push(true);
bh.push(false);
bh.push(true);
assert!(!bh.empty());

Test specific bit of the binary hash

Example

let mut bh=geohashrust::BinaryHash::new();
bh.push(true);
bh.push(true);
bh.push(false);
bh.push(true);
assert!(bh.test(0));
assert!(bh.test(1));
assert!(!bh.test(2));
assert!(bh.test(3));

Push a bit into binary hash

Example

let mut bh=geohashrust::BinaryHash::new();
bh.push(true);
bh.push(true);
bh.push(false);
bh.push(true);
assert_eq!(bh.to_string(), "1101");

Trait Implementations

impl Default for BinaryHash
[src]

Returns the "default value" for a type. Read more

impl Clone for BinaryHash
[src]

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

impl Copy for BinaryHash
[src]

impl PartialEq for BinaryHash
[src]

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.