port radixtree to rust

This commit is contained in:
Timur Gordon
2025-04-09 13:09:59 +02:00
parent e62e0a125a
commit dc8c887026
3 changed files with 427 additions and 341 deletions

View File

@@ -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()
}