feat: hash is a public ext

This commit is contained in:
əlemi 2024-08-14 17:12:36 +02:00
parent d22446ee10
commit 97b7504098
Signed by: alemi
GPG key ID: A4895B84D311642C
3 changed files with 8 additions and 2 deletions

View file

@ -145,8 +145,7 @@ impl ControllerWorker<TextChange> 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 {

View file

@ -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<T> {

View file

@ -149,3 +149,5 @@ pub use errors::Result;
pub use client::Client;
pub use workspace::Workspace;
pub use ext::hash;