Skip to content

Commit

Permalink
Renamed cache.rs to index.rs
Browse files Browse the repository at this point in the history
  • Loading branch information
ezrasingh committed Aug 23, 2024
1 parent fa8abe7 commit 2416564
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 42 deletions.
1 change: 1 addition & 0 deletions geoprox-core/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- Added support for key expirations ([#15](https://github.com/ezrasingh/geoprox/issues/15)).
- Implemented serde for `SpatialIndex` ([#17](https://github.com/ezrasingh/geoprox/issues/17)).
- renamed `cache.rs` to `index.rs`

## 0.4.2

Expand Down
76 changes: 38 additions & 38 deletions geoprox-core/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

Geoprox Core is the foundational Rust crate for the [Geoprox](https://github.com/ezrasingh/geoprox/) project, providing robust geospatial indexing and sharding capabilities. It includes two primary modules:

- **`cache`**: Manages in-memory storage and retrieval of geospatial data to ensure quick access and efficient querying.
- **`index`**: Manages in-memory storage and retrieval of geospatial data to ensure quick access and efficient querying.
- **`shard`**: Handles the partitioning and indexing of geospatial information, optimizing data distribution and retrieval across large datasets.

These modules are built to handle various use cases, such as food delivery services and real-time inventory tracking.
Expand All @@ -16,43 +16,6 @@ These modules are built to handle various use cases, such as food delivery servi

## Data Stuctures

### SpatialIndex

The `cache` module implements the `SpatialIndex` data structure, enabling efficient placement and searching of resources based on their geohash-encoded locations.

Key features include:

- **Placing Resources**: Add resources to the index with their geohash-encoded locations.
- **Searching Resources**: Perform range queries to find resources within a specified distance from a given location.

#### Example Usage

```rust
extern crate geoprox_core;

let mut geo_index = geoprox_core::SpatialIndex::default();

// ? place object keys into index
geo_index.insert("alice", "s00j8n0");
geo_index.insert("bob", "s00j8n1");

// ? search index for objects near New York
let nearby: LatLngCoord = [40.7128, 74.006];
let within: f64 = 200.0; // 200km radius
let count = 100; // return up to 100 results
let sorted = true; // sort results by distance
let search_depth = 6; // search precision (higher means more precise)
let res = geo_index.search(nearby, within, count, sorted, depth).unwrap();

println!("found: {:#?}", res);

assert_eq!(res.len(), 2);

res.iter().for_each(|neighbor| {
assert!(neighbor.distance <= within);
});
```

### GeoShard

The `shard` module implements the `GeoShard` data structure, which facilitates geographical sharding of datasets and enables efficient range queries.
Expand Down Expand Up @@ -101,6 +64,43 @@ let res = shard.query_range("drivers", nearby, within, Some(count), Some(sorted)
println!("found: {:#?}", res.unwrap());
```

### SpatialIndex

The `index` module implements the `SpatialIndex` data structure, enabling efficient placement and searching of resources based on their geohash-encoded locations.

Key features include:

- **Placing Resources**: Add resources to the index with their geohash-encoded locations.
- **Searching Resources**: Perform range queries to find resources within a specified distance from a given location.

#### Example Usage

```rust
extern crate geoprox_core;

let mut geo_index = geoprox_core::SpatialIndex::default();

// ? place object keys into index
geo_index.insert("alice", "s00j8n0");
geo_index.insert("bob", "s00j8n1");

// ? search index for objects near New York
let nearby: LatLngCoord = [40.7128, 74.006];
let within: f64 = 200.0; // 200km radius
let count = 100; // return up to 100 results
let sorted = true; // sort results by distance
let search_depth = 6; // search precision (higher means more precise)
let res = geo_index.search(nearby, within, count, sorted, depth).unwrap();

println!("found: {:#?}", res);

assert_eq!(res.len(), 2);

res.iter().for_each(|neighbor| {
assert!(neighbor.distance <= within);
});
```

## Contributing

Contributions are welcome! Please see the [contributing guidelines](https://github.com/ezrasingh/geoprox/blob/main/CONTRIBUTING.md) for more information.
Expand Down
2 changes: 1 addition & 1 deletion geoprox-core/benches/spatial_index_benchmark.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use criterion::{
black_box, criterion_group, criterion_main, BatchSize, BenchmarkId, Criterion, Throughput,
};
use geoprox_core::{cache::SpatialIndex, models::LatLngCoord};
use geoprox_core::{index::SpatialIndex, models::LatLngCoord};
use hashbrown::HashSet;
use rand::prelude::*;

Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion geoprox-core/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
mod metric;

pub mod cache;
pub mod index;
pub mod models;
pub mod serde;
pub mod shard;
Expand Down
2 changes: 1 addition & 1 deletion geoprox-core/src/serde.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::time::{Duration, Instant, SystemTime};

use serde::{Deserialize, Serialize};

use crate::cache::SpatialIndex;
use crate::index::SpatialIndex;

impl Serialize for SpatialIndex {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
Expand Down
2 changes: 1 addition & 1 deletion geoprox-core/src/shard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use itertools::Itertools;
use rayon::prelude::*;
use serde::{Deserialize, Serialize};

use crate::cache::SpatialIndex;
use crate::index::SpatialIndex;
use crate::models::{BatchOutput, GeoShardConfig, GeoShardError, LatLngCoord, Neighbor};

/// A collection of geospatial indexes stored in-memory
Expand Down

0 comments on commit 2416564

Please sign in to comment.