inline tag added to small functions
@@ -37,7 +37,8 @@ struct Node {
right: Link,
}
-/// function to create a new node, (Like a Constructor function)
+/// Function to create a new node, (Like a Constructor function)
+#[inline]
fn new_node(freq: i32, ch: Option<char>) -> Node {
Node {
freq: freq,
@@ -49,6 +50,7 @@ fn new_node(freq: i32, ch: Option<char>) -> Node {
}
/// Count the frequency of occurence of each unique ASCII character in the input string
+#[inline]
fn frequency(s: &str) -> HashMap<char, i32> {
let mut hm = HashMap::new();
for ch in s.chars() {
@@ -74,6 +76,7 @@ fn assign_codes(p: &Node, hm: &mut HashMap<char, String>, s: String) {
}
/// Takes the huffman tree and input string, to return the encoded string
+#[inline]
fn encode_string<A>(s: A, hm: &HashMap<char, String>) -> String
where
A: AsRef<str>,
@@ -90,6 +93,7 @@ where
}
/// Takes the Huffman Tree and encoded string, to return the decoded string
+#[inline]
fn decode_string<A>(s: A, root: &Node) -> String
where
A: AsRef<str>,
