port radixtree to rust
This commit is contained in:
@@ -2,8 +2,7 @@
|
||||
|
||||
use crate::error::Error;
|
||||
use crate::node::{Node, NodeRef};
|
||||
use std::convert::TryInto;
|
||||
use std::io::{Cursor, Read, Write};
|
||||
use std::io::{Cursor, Read};
|
||||
use std::mem::size_of;
|
||||
|
||||
/// Current binary format version.
|
||||
@@ -142,3 +141,16 @@ fn read_u32(cursor: &mut Cursor<&[u8]>) -> std::io::Result<u32> {
|
||||
|
||||
Ok(u32::from_le_bytes(bytes))
|
||||
}
|
||||
|
||||
/// Helper function to get the common prefix of two strings.
|
||||
pub fn get_common_prefix(a: &str, b: &str) -> String {
|
||||
let mut i = 0;
|
||||
let a_bytes = a.as_bytes();
|
||||
let b_bytes = b.as_bytes();
|
||||
|
||||
while i < a.len() && i < b.len() && a_bytes[i] == b_bytes[i] {
|
||||
i += 1;
|
||||
}
|
||||
|
||||
a[..i].to_string()
|
||||
}
|
||||
|
Reference in New Issue
Block a user