commit 8203a612910a1879d052abc0104fb5aa72cfac0d
parent 2cea8f772eaa2c8e015438e6cff16ac7188efbdd
Author: lash <dev@holbrook.no>
Date: Sun, 30 Jun 2024 19:10:06 +0100
add timestamp to sort key
Diffstat:
4 files changed, 177 insertions(+), 6 deletions(-)
diff --git a/Cargo.lock b/Cargo.lock
@@ -12,6 +12,21 @@ dependencies = [
]
[[package]]
+name = "android-tzdata"
+version = "0.1.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "e999941b234f3131b00bc13c22d06e8c5ff726d1b6318ac7eb276997bbb4fef0"
+
+[[package]]
+name = "android_system_properties"
+version = "0.1.5"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "819e7219dbd41043ac279b19830f2efc897156490d7fd6ea916720117ee66311"
+dependencies = [
+ "libc",
+]
+
+[[package]]
name = "ansi_term"
version = "0.12.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -59,12 +74,24 @@ dependencies = [
]
[[package]]
+name = "bumpalo"
+version = "3.16.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "79296716171880943b8470b5f8d03aa55eb2e645a4874bdbb28adb49162e012c"
+
+[[package]]
name = "bytes"
version = "1.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "514de17de45fdb8dc022b1a7975556c53c86f9f0aa5f534b98977b171857c2c9"
[[package]]
+name = "cc"
+version = "1.0.98"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "41c270e7540d725e65ac7f1b212ac8ce349719624d7bcff99f8e2e488e8cf03f"
+
+[[package]]
name = "cfg-if"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -76,7 +103,12 @@ version = "0.4.38"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a21f936df1771bf62b77f047b726c4625ff2e8aa607c01ec06e5a05bd8463401"
dependencies = [
+ "android-tzdata",
+ "iana-time-zone",
+ "js-sys",
"num-traits",
+ "wasm-bindgen",
+ "windows-targets",
]
[[package]]
@@ -95,9 +127,16 @@ dependencies = [
]
[[package]]
+name = "core-foundation-sys"
+version = "0.8.6"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "06ea2b9bc92be3c2baa9334a323ebca2d6f074ff852cd1d7b11064035cd3868f"
+
+[[package]]
name = "crier"
version = "0.0.1"
dependencies = [
+ "chrono",
"clap",
"digest",
"feed-rs",
@@ -225,6 +264,29 @@ dependencies = [
]
[[package]]
+name = "iana-time-zone"
+version = "0.1.60"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "e7ffbb5a1b541ea2561f8c41c087286cc091e21e556a4f09a8f6cbf17b69b141"
+dependencies = [
+ "android_system_properties",
+ "core-foundation-sys",
+ "iana-time-zone-haiku",
+ "js-sys",
+ "wasm-bindgen",
+ "windows-core",
+]
+
+[[package]]
+name = "iana-time-zone-haiku"
+version = "0.1.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "f31827a206f56af32e590ba56d5d2d085f558508192593743f16b2306495269f"
+dependencies = [
+ "cc",
+]
+
+[[package]]
name = "idna"
version = "0.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -241,6 +303,15 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b"
[[package]]
+name = "js-sys"
+version = "0.3.69"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "29c15563dc2726973df627357ce0c9ddddbea194836909d655df6a75d2cf296d"
+dependencies = [
+ "wasm-bindgen",
+]
+
+[[package]]
name = "libc"
version = "0.2.155"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -253,6 +324,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "78b3ae25bc7c8c38cec158d1f2757ee79e9b3740fbc7ccf0e59e4b08d793fa89"
[[package]]
+name = "log"
+version = "0.4.21"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "90ed8c1e510134f979dbc4f070f87d4313098b704861a105fe34231c70a3901c"
+
+[[package]]
name = "mediatype"
version = "0.19.18"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -274,6 +351,12 @@ dependencies = [
]
[[package]]
+name = "once_cell"
+version = "1.19.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92"
+
+[[package]]
name = "percent-encoding"
version = "2.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -565,6 +648,60 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423"
[[package]]
+name = "wasm-bindgen"
+version = "0.2.92"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "4be2531df63900aeb2bca0daaaddec08491ee64ceecbee5076636a3b026795a8"
+dependencies = [
+ "cfg-if",
+ "wasm-bindgen-macro",
+]
+
+[[package]]
+name = "wasm-bindgen-backend"
+version = "0.2.92"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "614d787b966d3989fa7bb98a654e369c762374fd3213d212cfc0251257e747da"
+dependencies = [
+ "bumpalo",
+ "log",
+ "once_cell",
+ "proc-macro2",
+ "quote",
+ "syn",
+ "wasm-bindgen-shared",
+]
+
+[[package]]
+name = "wasm-bindgen-macro"
+version = "0.2.92"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "a1f8823de937b71b9460c0c34e25f3da88250760bec0ebac694b49997550d726"
+dependencies = [
+ "quote",
+ "wasm-bindgen-macro-support",
+]
+
+[[package]]
+name = "wasm-bindgen-macro-support"
+version = "0.2.92"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "e94f17b526d0a461a191c78ea52bbce64071ed5c04c9ffe424dcb38f74171bb7"
+dependencies = [
+ "proc-macro2",
+ "quote",
+ "syn",
+ "wasm-bindgen-backend",
+ "wasm-bindgen-shared",
+]
+
+[[package]]
+name = "wasm-bindgen-shared"
+version = "0.2.92"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "af190c94f2773fdb3729c55b007a722abb5384da03bc0986df4c289bf5567e96"
+
+[[package]]
name = "winapi"
version = "0.3.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -587,6 +724,15 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
[[package]]
+name = "windows-core"
+version = "0.52.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "33ab640c8d7e35bf8ba19b884ba838ceb4fba93a4e8c65a9059d08afcfc683d9"
+dependencies = [
+ "windows-targets",
+]
+
+[[package]]
name = "windows-sys"
version = "0.52.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
diff --git a/Cargo.toml b/Cargo.toml
@@ -17,6 +17,7 @@ clap = "2.34.0"
#quick-xml = "^0.28.2"
rs_sha512 = "^0.1.3"
http = "^1.0"
+chrono = "^0.4"
[dev-dependencies]
tempfile = "3.3.0"
diff --git a/src/lib.rs b/src/lib.rs
@@ -4,16 +4,17 @@ use std::hash::Hash;
use std::iter::Iterator;
use feed_rs::model::Entry;
use rs_sha512::Sha512Hasher;
+use chrono::DateTime;
mod io;
pub struct Sequencer {
- pub items: HashMap<u32, Vec<u8>>,
- item_keys: Vec<u32>,
+ pub items: HashMap<u64, Vec<u8>>,
+ item_keys: Vec<u64>,
crsr: usize,
}
pub struct SequencerEntry {
- pub digest: u32,
+ pub digest: u64,
entry: Entry,
}
@@ -22,7 +23,7 @@ impl Sequencer {
Sequencer {
items: HashMap::new(),
crsr: 0,
- item_keys: Vec::<u32>::new(),
+ item_keys: Vec::<u64>::new(),
}
}
@@ -40,7 +41,7 @@ impl Iterator for Sequencer {
type Item = Vec<u8>;
fn next(&mut self) -> Option<Self::Item> {
- let c: u32;
+ let c: u64;
c = self.item_keys[self.crsr];
return Some(self.items[&c].clone());
@@ -49,13 +50,25 @@ impl Iterator for Sequencer {
impl SequencerEntry {
pub fn new(entry: Entry) -> SequencerEntry {
+ let mut id_part: u32;
let mut o = SequencerEntry {
entry: entry,
digest: 0,
};
+ match &o.entry.published {
+ Some(v) => {
+ id_part = v.timestamp() as u32;
+ o.digest = id_part as u64;
+ o.digest <<= 32;
+ },
+ None => {
+ },
+ }
+
let mut h = Sha512Hasher::default();
o.hash(&mut h);
- o.digest = h.finish() as u32;
+ id_part = h.finish() as u32;
+ o.digest += id_part as u64;
o
}
}
diff --git a/src/tests.rs b/src/tests.rs
@@ -1,6 +1,8 @@
use super::Sequencer;
use feed_rs::model::Entry;
use super::io::FeedGet;
+use chrono::DateTime;
+use chrono::offset::Utc;
#[cfg(feature = "fs")]
use super::io::fs::Fs;
@@ -11,13 +13,22 @@ fn test_entry_guard() {
let mut seq = Sequencer::new();
let mut src = Entry::default();
src.id = String::from("foo");
+ //src.published = Some(DateTime::<Utc>::default());
+ src.published = Some(DateTime::parse_from_rfc3339("2024-06-25T20:46:00+02:00").unwrap().into());
r = seq.add(src);
assert!(r);
let mut src_two = Entry::default();
src_two.id = String::from("foo");
+ src_two.published = Some(DateTime::parse_from_rfc3339("2024-06-25T20:46:00+02:00").unwrap().into());
r = seq.add(src_two);
assert!(!r);
+
+ let mut src_three = Entry::default();
+ src_three.id = String::from("foo");
+ src_three.published = Some(DateTime::parse_from_rfc3339("2024-06-25T20:46:00+03:00").unwrap().into());
+ r = seq.add(src_three);
+ assert!(r);
}
#[test]