From 97b7504098ddffd8284da9a24b31b37afea9a9aa Mon Sep 17 00:00:00 2001 From: alemi Date: Wed, 14 Aug 2024 17:12:36 +0200 Subject: [PATCH] feat: hash is a public ext --- src/buffer/worker.rs | 3 +-- src/ext.rs | 5 +++++ src/lib.rs | 2 ++ 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/buffer/worker.rs b/src/buffer/worker.rs index 0967593..3f7dfeb 100644 --- a/src/buffer/worker.rs +++ b/src/buffer/worker.rs @@ -145,8 +145,7 @@ impl ControllerWorker for BufferWorker { let new_local_v = branch.local_version(); let hash = if timer.step() { - let hash = xxhash_rust::xxh3::xxh3_64(branch.content().to_string().as_bytes()); - Some(i64::from_ne_bytes(hash.to_ne_bytes())) + Some(crate::hash(branch.content().to_string())) } else { None }; let tc = crate::api::change::TextChange { diff --git a/src/ext.rs b/src/ext.rs index bee1cb4..4733b82 100644 --- a/src/ext.rs +++ b/src/ext.rs @@ -49,6 +49,11 @@ pub async fn select_buffer( } } +pub fn hash(data: impl AsRef<[u8]>) -> i64 { + let hash = xxhash_rust::xxh3::xxh3_64(data.as_ref()); + i64::from_ne_bytes(hash.to_ne_bytes()) +} + /// wraps sender and receiver to allow mutable field with immutable ref #[derive(Debug)] pub struct InternallyMutable { diff --git a/src/lib.rs b/src/lib.rs index 47107bd..964b64d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -149,3 +149,5 @@ pub use errors::Result; pub use client::Client; pub use workspace::Workspace; + +pub use ext::hash;