algoxcc 0.1.2

A solver for an exact cover with colors problem
Documentation
#[derive(Debug, PartialEq)]

/// Either an item within an option or a separator between options
pub(crate) enum NodeType {
    Item,
    Separator,
}

/// A node in the list of nodes
#[derive(Debug)]
pub(crate) struct Node {
    /// Type either Item or Separator
    pub(crate) node_type: NodeType,
    /// Link to first option item in sets (or length of an option if Separator)
    pub(crate) item: usize,
    /// Link to option item in sets
    pub(crate) loc: usize,
    /// The option an item belongs to
    pub(crate) option: usize,
    /// Color of a secondary item
    pub(crate) color: usize,
}

impl Node {
    /// New separator node
    pub(crate) fn separator(length: usize) -> Self {
        Self {
            node_type: NodeType::Separator,
            item: length,
            loc: 0,
            option: 0,
            color: 0,
        }
    }
    /// New item node
    pub(crate) fn item(item: usize, loc: usize, option: usize, color: usize) -> Self {
        Self {
            node_type: NodeType::Item,
            item,
            loc,
            option,
            color,
        }
    }

    /// True if node is a separator
    pub(crate) fn is_separator(&self) -> bool {
        self.node_type == NodeType::Separator
    }

    /// Number of items in an option
    pub(crate) fn lenght(&self) -> &usize {
        if !self.is_separator() {
            panic!("Never use this on item nodes!")
        }
        &self.item
    }
}