From c19b157a2880ca6a1efd9ce6cab36cb3f5d1091e Mon Sep 17 00:00:00 2001 From: aaron-jack-manning Date: Wed, 7 Sep 2022 20:26:20 +1000 Subject: [PATCH] switched to sets and maps with stable serialization --- src/graph.rs | 10 +++++----- src/index.rs | 8 ++++---- src/tasks.rs | 4 ++-- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/graph.rs b/src/graph.rs index 27af28a..1c9c243 100755 --- a/src/graph.rs +++ b/src/graph.rs @@ -4,19 +4,19 @@ use crate::format; use crate::tasks::Id; use std::fmt::Write; -use std::collections::{HashSet, HashMap, BTreeSet}; +use std::collections::{HashSet, BTreeSet, BTreeMap}; use serde_with::{serde_as, DisplayFromStr}; #[serde_as] #[derive(Clone, Debug, serde::Serialize, serde::Deserialize)] pub struct Graph { - #[serde_as(as = "HashMap")] - pub edges : HashMap>, + #[serde_as(as = "BTreeMap")] + pub edges : BTreeMap>, } impl Graph { pub fn create(tasks : Vec) -> Self { - let mut edges = HashMap::with_capacity(tasks.len()); + let mut edges = BTreeMap::new(); for task in tasks { edges.insert(task.data.id, task.data.dependencies); @@ -32,7 +32,7 @@ impl Graph { } pub fn insert_node(&mut self, node : Id) -> bool { - self.edges.insert(node, HashSet::new()).is_none() + self.edges.insert(node, BTreeSet::new()).is_none() } pub fn insert_edge(&mut self, first : Id, second : Id) -> Result { diff --git a/src/index.rs b/src/index.rs index 9007d49..607ea53 100755 --- a/src/index.rs +++ b/src/index.rs @@ -4,19 +4,19 @@ use crate::format; use crate::tasks::Id; use std::fmt::Write; -use std::collections::HashMap; +use std::collections::BTreeMap; use serde_with::{serde_as, DisplayFromStr}; #[serde_as] #[derive(serde::Serialize, serde::Deserialize)] pub struct Index { - #[serde_as(as = "HashMap")] - map : HashMap> + #[serde_as(as = "BTreeMap")] + map : BTreeMap> } impl Index { pub fn create(tasks : &Vec) -> Index { - let mut map : HashMap> = HashMap::with_capacity(tasks.len()); + let mut map : BTreeMap> = BTreeMap::new(); for task in tasks { match map.get_mut(&task.data.name) { Some(ids) => { diff --git a/src/tasks.rs b/src/tasks.rs index 344d06a..3ff256b 100755 --- a/src/tasks.rs +++ b/src/tasks.rs @@ -11,7 +11,7 @@ use std::mem; use std::cmp; use std::path; use std::io::{Write, Seek}; -use std::collections::{HashSet, HashMap}; +use std::collections::{HashSet, HashMap, BTreeSet}; use chrono::SubsecRound; pub type Id = u64; @@ -49,7 +49,7 @@ pub struct InternalTask { pub id : Id, pub name : String, pub tags : HashSet, - pub dependencies : HashSet, + pub dependencies : BTreeSet, pub priority : Priority, pub due : Option, pub created : chrono::NaiveDateTime,