1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#[cfg(test)]
mod tests;

pub fn distance(a: &[u8], b: &[u8]) -> Vec<u8> {
    let a_len: usize = a.len();
    if a_len != b.len() {
        panic!("inputs must be of same length");
    }
    let mut buf: Vec<u8> = Vec::with_capacity(a_len);
    for i in 0..a_len {
        buf.push(a[i] ^ b[i]);
    }
    buf
}

pub fn compare (a: &[u8], b: &[u8]) -> i8 {
    let a_len: usize = a.len();
    if a_len != b.len() {
        panic!("inputs must be of same length");
    }
    for i in 0..a_len {
        if a[i] == b[i] {
            continue;
        } else if a[i] < b[i] {
            return -1;
        } else {
            return 1;
        }
    }
    0
}

pub fn lt (a: &[u8], b: &[u8]) -> bool {
    compare(a, b) == -1
}

pub fn gt (a: &[u8], b: &[u8]) -> bool {
    compare(a, b) == 1
}

pub fn eq (a: &[u8], b: &[u8]) -> bool {
    compare(a, b) == 0
}