diff --git a/rust/indexes/src/lib.rs b/rust/indexes/src/lib.rs --- a/rust/indexes/src/lib.rs +++ b/rust/indexes/src/lib.rs @@ -13,6 +13,7 @@ pub mod errors; pub mod nodemap; +mod utils; mod pybuf; #[allow(non_camel_case_types)] diff --git a/rust/indexes/src/nodemap.rs b/rust/indexes/src/nodemap.rs --- a/rust/indexes/src/nodemap.rs +++ b/rust/indexes/src/nodemap.rs @@ -8,6 +8,7 @@ radix_insert_with_key, KeyReader}; use radixbuf::key::KeyId; use radixbuf::errors as rerrors; +use utils::{changelog_next_rev,rev_to_node}; /// An index for node to rev lookups. /// @@ -162,16 +163,6 @@ } } -/// Return the minimal revision number the changelog does not have. -fn changelog_next_rev>(changelog: &T) -> u32 { - let changelog = changelog.as_ref(); - let rev = changelog.len() as u64 / 64; - if rev > (1u64 << 31) { - panic!("rev exceeds 32 bit integers") - } - rev as u32 -} - /// Read the given range of revisions (from `start_rev` (inclusive) to /// `end_rev` (exclusive)) from changelog. Insert them to a "forked" /// index and return that index. @@ -189,20 +180,6 @@ Ok(()) } -/// Helper method similar to `radixbuf::key::FixedKey::read`, but takes a revision number instead. -#[inline] -fn rev_to_node(changelog: &[u8], rev: KeyId) -> rerrors::Result<&[u8]> { - let buf = changelog; - let rev_usize: usize = rev.into(); - let start_pos = rev_usize * 64 + 32; - let end_pos = start_pos + 20; - if buf.len() < end_pos { - Err(rerrors::ErrorKind::InvalidKeyId(rev).into()) - } else { - Ok(&buf[start_pos..end_pos]) - } -} - /// Convert hex base16 sequence to binary base16 sequence. fn hex_to_bin_base16>(base16: T) -> Option> { let base16 = base16.as_ref(); diff --git a/rust/indexes/src/utils.rs b/rust/indexes/src/utils.rs new file mode 100644 --- /dev/null +++ b/rust/indexes/src/utils.rs @@ -0,0 +1,31 @@ +// Copyright 2017 Facebook, Inc. +// +// This software may be used and distributed according to the terms of the +// GNU General Public License version 2 or any later version. + +use radixbuf::key::KeyId; +use radixbuf::errors as rerrors; + +/// Return the minimal revision number the changelog does not have. +pub fn changelog_next_rev>(changelog: &T) -> u32 { + let changelog = changelog.as_ref(); + let rev = changelog.len() as u64 / 64; + if rev > (1u64 << 31) { + panic!("rev exceeds 32 bit integers") + } + rev as u32 +} + +/// Helper method similar to `radixbuf::key::FixedKey::read`, but takes a revision number instead. +#[inline] +pub fn rev_to_node(changelog: &[u8], rev: KeyId) -> rerrors::Result<&[u8]> { + let buf = changelog; + let rev_usize: usize = rev.into(); + let start_pos = rev_usize * 64 + 32; + let end_pos = start_pos + 20; + if buf.len() < end_pos { + Err(rerrors::ErrorKind::InvalidKeyId(rev).into()) + } else { + Ok(&buf[start_pos..end_pos]) + } +}