switched to sets and maps with stable serialization
This commit is contained in:
		
							
								
								
									
										10
									
								
								src/graph.rs
									
									
									
									
									
								
							
							
						
						
									
										10
									
								
								src/graph.rs
									
									
									
									
									
								
							@@ -4,19 +4,19 @@ use crate::format;
 | 
				
			|||||||
use crate::tasks::Id;
 | 
					use crate::tasks::Id;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
use std::fmt::Write;
 | 
					use std::fmt::Write;
 | 
				
			||||||
use std::collections::{HashSet, HashMap, BTreeSet};
 | 
					use std::collections::{HashSet, BTreeSet, BTreeMap};
 | 
				
			||||||
use serde_with::{serde_as, DisplayFromStr};
 | 
					use serde_with::{serde_as, DisplayFromStr};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#[serde_as]
 | 
					#[serde_as]
 | 
				
			||||||
#[derive(Clone, Debug, serde::Serialize, serde::Deserialize)]
 | 
					#[derive(Clone, Debug, serde::Serialize, serde::Deserialize)]
 | 
				
			||||||
pub struct Graph {
 | 
					pub struct Graph {
 | 
				
			||||||
    #[serde_as(as = "HashMap<DisplayFromStr, _>")]
 | 
					    #[serde_as(as = "BTreeMap<DisplayFromStr, _>")]
 | 
				
			||||||
    pub edges : HashMap<Id, HashSet<Id>>,
 | 
					    pub edges : BTreeMap<Id, BTreeSet<Id>>,
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
impl Graph {
 | 
					impl Graph {
 | 
				
			||||||
    pub fn create(tasks : Vec<tasks::Task>) -> Self {
 | 
					    pub fn create(tasks : Vec<tasks::Task>) -> Self {
 | 
				
			||||||
        let mut edges = HashMap::with_capacity(tasks.len());
 | 
					        let mut edges = BTreeMap::new();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        for task in tasks {
 | 
					        for task in tasks {
 | 
				
			||||||
            edges.insert(task.data.id, task.data.dependencies);
 | 
					            edges.insert(task.data.id, task.data.dependencies);
 | 
				
			||||||
@@ -32,7 +32,7 @@ impl Graph {
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    pub fn insert_node(&mut self, node : Id) -> bool {
 | 
					    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<bool, error::Error> {
 | 
					    pub fn insert_edge(&mut self, first : Id, second : Id) -> Result<bool, error::Error> {
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -4,19 +4,19 @@ use crate::format;
 | 
				
			|||||||
use crate::tasks::Id;
 | 
					use crate::tasks::Id;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
use std::fmt::Write;
 | 
					use std::fmt::Write;
 | 
				
			||||||
use std::collections::HashMap;
 | 
					use std::collections::BTreeMap;
 | 
				
			||||||
use serde_with::{serde_as, DisplayFromStr};
 | 
					use serde_with::{serde_as, DisplayFromStr};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#[serde_as]
 | 
					#[serde_as]
 | 
				
			||||||
#[derive(serde::Serialize, serde::Deserialize)]
 | 
					#[derive(serde::Serialize, serde::Deserialize)]
 | 
				
			||||||
pub struct Index {
 | 
					pub struct Index {
 | 
				
			||||||
    #[serde_as(as = "HashMap<DisplayFromStr, _>")]
 | 
					    #[serde_as(as = "BTreeMap<DisplayFromStr, _>")]
 | 
				
			||||||
    map : HashMap<String, Vec<Id>>
 | 
					    map : BTreeMap<String, Vec<Id>>
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
impl Index {
 | 
					impl Index {
 | 
				
			||||||
    pub fn create(tasks : &Vec<tasks::Task>) -> Index {
 | 
					    pub fn create(tasks : &Vec<tasks::Task>) -> Index {
 | 
				
			||||||
        let mut map : HashMap<String, Vec<Id>> = HashMap::with_capacity(tasks.len());
 | 
					        let mut map : BTreeMap<String, Vec<Id>> = BTreeMap::new();
 | 
				
			||||||
        for task in tasks {
 | 
					        for task in tasks {
 | 
				
			||||||
            match map.get_mut(&task.data.name) {
 | 
					            match map.get_mut(&task.data.name) {
 | 
				
			||||||
                Some(ids) => {
 | 
					                Some(ids) => {
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -11,7 +11,7 @@ use std::mem;
 | 
				
			|||||||
use std::cmp;
 | 
					use std::cmp;
 | 
				
			||||||
use std::path;
 | 
					use std::path;
 | 
				
			||||||
use std::io::{Write, Seek};
 | 
					use std::io::{Write, Seek};
 | 
				
			||||||
use std::collections::{HashSet, HashMap};
 | 
					use std::collections::{HashSet, HashMap, BTreeSet};
 | 
				
			||||||
use chrono::SubsecRound;
 | 
					use chrono::SubsecRound;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
pub type Id = u64;
 | 
					pub type Id = u64;
 | 
				
			||||||
@@ -49,7 +49,7 @@ pub struct InternalTask {
 | 
				
			|||||||
    pub id : Id,
 | 
					    pub id : Id,
 | 
				
			||||||
    pub name : String,
 | 
					    pub name : String,
 | 
				
			||||||
    pub tags : HashSet<String>,
 | 
					    pub tags : HashSet<String>,
 | 
				
			||||||
    pub dependencies : HashSet<Id>,
 | 
					    pub dependencies : BTreeSet<Id>,
 | 
				
			||||||
    pub priority : Priority,
 | 
					    pub priority : Priority,
 | 
				
			||||||
    pub due : Option<chrono::NaiveDateTime>,
 | 
					    pub due : Option<chrono::NaiveDateTime>,
 | 
				
			||||||
    pub created : chrono::NaiveDateTime,
 | 
					    pub created : chrono::NaiveDateTime,
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user