Intersubjective / riblt-rust

Rust port of RIBLT library by yang1996
MIT License
16 stars 1 forks source link

riblt-rust

Rust port of RIBLT library by yang1996.

Implementation of Rateless Invertible Bloom Lookup Tables (Rateless IBLTs), as proposed in paper Practical Rateless Set Reconciliation by Lei Yang, Yossi Gilad, and Mohammad Alizadeh. Preprint available at arxiv.org/abs/2402.02668.

Library API

To use this library, implement a Symbol trait, and create Encoder or Decoder objects to encode and decode symbols.

Symbol trait

Example implementation for 64-bit integer symbols:

use riblt::*;
use std::hash::{SipHasher, Hasher};

pub type MyU64 = u64;

impl Symbol for MyU64 {
  fn zero() -> MyU64 {
    return 0;
  }

  fn xor(&self, other: &MyU64) -> MyU64 {
    return self ^ other;
  }

  fn hash(&self) -> u64 {
    let mut hasher = SipHasher::new_with_keys(123, 456);
    hasher.write_u64(*self);
    return hasher.finish();
  }
}

Encoder methods

Example usage

use riblt::*;

fn foo() {
  let mut enc                  = Encoder::<MyU64>::new();
  let     symbols : [MyU64; 5] = [ 1, 2, 3, 4, 5 ];
  for x in symbols {
    enc.add_symbol(&x);
  }

  let coded = enc.produce_next_coded_symbol();

  // send symbol to the decoder...
}

Decoder methods

Remote and local symbols can be accessed directly via Decoder properties:

Example usage

use riblt::*;

fn foo() {
  let symbols : [CodedSymbol<MyU64>; 5] = ...;

  let mut dec = Decoder::<MyU64>::new();
  for i in 0..symbols.len() {
    dec.add_coded_symbol(&symbols[i]);
  }

  if dec.try_decode().is_err() {
    // Decoding error...
  }

  if dec.decoded() {
    // Success...
  }
}

For the complete example see test example in src/tests.rs.