Struct geohashrust::BinaryHash
[−]
[src]
pub struct BinaryHash { /* fields omitted */ }
Binary hash code for a given GeoLocation
with specific precision
Methods
impl BinaryHash
[src]
fn new() -> BinaryHash
Create an empty BinaryHash
fn from_string(s: &str) -> BinaryHash
Create a BinaryHash
from a String
Example
let bh=geohashrust::BinaryHash::from_string("11100110"); assert_eq!(bh.to_string(), "11100110");
fn encode(l: &GeoLocation, precision: u8) -> BinaryHash
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");
fn decode(&self) -> BoundingBox
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)));
fn decode_string(s: &str) -> BoundingBox
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)));
fn to_string(&self) -> String
Convert BinaryHash
to a String
Example
let bh=geohashrust::BinaryHash::from_string("11100110"); assert_eq!(bh.to_string(), "11100110");
fn len(&self) -> u8
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);
fn empty(&self) -> bool
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());
fn test(&self, n: u8) -> bool
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));
fn push(&mut self, b: bool)
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]
fn default() -> BinaryHash
Returns the "default value" for a type. Read more
impl Clone for BinaryHash
[src]
fn clone(&self) -> BinaryHash
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0
Performs copy-assignment from source
. Read more
impl Copy for BinaryHash
[src]
impl PartialEq for BinaryHash
[src]
fn eq(&self, __arg_0: &BinaryHash) -> bool
This method tests for self
and other
values to be equal, and is used by ==
. Read more
fn ne(&self, __arg_0: &BinaryHash) -> bool
This method tests for !=
.