-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use compact numeric IDs for GTFS objects, shrinking a London-wide fil…
…e from 2GB down to 1.3GB
- Loading branch information
1 parent
d1b95a2
commit b0b7097
Showing
8 changed files
with
117 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
use std::collections::BTreeMap; | ||
|
||
use anyhow::Result; | ||
use serde::{Deserialize, Serialize}; | ||
|
||
/// The full string IDs used in GTFS | ||
pub mod orig_ids { | ||
use serde::{Deserialize, Serialize}; | ||
|
||
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize)] | ||
pub struct StopID(String); | ||
|
||
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize)] | ||
pub struct TripID(String); | ||
} | ||
|
||
#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize)] | ||
pub struct StopID(pub usize); | ||
|
||
#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize)] | ||
pub struct TripID(pub usize); | ||
|
||
impl CheapID for StopID { | ||
fn new(x: usize) -> Self { | ||
Self(x) | ||
} | ||
} | ||
impl CheapID for TripID { | ||
fn new(x: usize) -> Self { | ||
Self(x) | ||
} | ||
} | ||
|
||
pub trait CheapID: Copy { | ||
fn new(x: usize) -> Self; | ||
} | ||
|
||
#[derive(Serialize, Deserialize)] | ||
pub struct IDMapping<K: Ord, V> { | ||
orig_to_cheap: BTreeMap<K, V>, | ||
// We don't need to store the inverse. It's more convenient for each object to own that. | ||
} | ||
|
||
impl<K: Clone + std::fmt::Debug + Ord, V: CheapID> IDMapping<K, V> { | ||
pub fn new() -> Self { | ||
Self { | ||
orig_to_cheap: BTreeMap::new(), | ||
} | ||
} | ||
|
||
pub fn insert_new(&mut self, orig: K) -> Result<V> { | ||
let cheap = V::new(self.orig_to_cheap.len()); | ||
if self.orig_to_cheap.insert(orig.clone(), cheap).is_some() { | ||
bail!("IDMapping::insert_new has duplicate input for {:?}", orig); | ||
} | ||
Ok(cheap) | ||
} | ||
|
||
pub fn get(&self, orig: &K) -> Option<V> { | ||
self.orig_to_cheap.get(orig).cloned() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
#[macro_use] | ||
extern crate anyhow; | ||
#[macro_use] | ||
extern crate log; | ||
|
||
use std::sync::Once; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters