Fork channel

Create a new channel as a copy of main.

Rename channel

Rename main to:

Delete channel

Delete main? This cannot be undone.

lib.rs
use rayon::prelude::*;
use std::cmp::Ordering;

#[derive(Debug, PartialEq)]
pub enum Comparison {
	Equal,
	Sublist,
	Superlist,
	Unequal,
}

/// Determines if `b` is a sublist of `a`.
///
/// # Arguments:
/// * `a`: Slice to test if is a superlist of `b`.
/// * `b`: Slice to test if is a sublist of `a`.
///
/// # Examples
/// ```rust
/// # use sublist::*;
/// assert!(is_sublist(&[1, 2, 3], &[1, 2]));
/// assert!(!is_sublist(&[1, 2, 3], &[1, 3]));
/// ```
pub fn is_sublist<T: PartialEq + Sync>(a: &[T], b: &[T]) -> bool {
	a.par_windows(b.len()).any(|sublist| sublist == b)
}

pub fn sublist<T: PartialEq + Sync>(_first_list: &[T], _second_list: &[T]) -> Comparison {
	match _first_list.len().cmp(&_second_list.len()) {
		Ordering::Less => {
			if _first_list.is_empty() || is_sublist(_second_list, _first_list) {
				return Comparison::Sublist;
			}
		}
		Ordering::Equal => {
			if _first_list == _second_list {
				return Comparison::Equal;
			}
		}
		Ordering::Greater => {
			if _second_list.is_empty() || is_sublist(_first_list, _second_list) {
				return Comparison::Superlist;
			}
		}
	}
	Comparison::Unequal
}