Files @ 85419b0950c7
Branch filter:

Location: CSY/reowolf/src/collections/sets.rs

85419b0950c7 1.2 KiB application/rls-services+xml Show Annotation Show as Raw Download as Raw
MH
Rewrote typing to use indices.

Currently it is slower than before, because we do a HashMap lookup
followed up by actually using the index. But it serves as the basis
for a faster type inferencer.

The main goal, however, is to fix the manner in which polymorph
types are determined. The typing queue of functions still needs to
correctly write this data to the type table.
use std::collections::VecDeque;

/// Simple double ended queue that ensures that all elements are unique. Queue
/// elements are not ordered (use case is that the queue should be rather
/// small).
pub struct DequeSet<T: Eq> {
    inner: VecDeque<T>,
}

impl<T: Eq> DequeSet<T> {
    pub fn new() -> Self {
        Self{ inner: VecDeque::new() }
    }

    #[inline]
    pub fn pop_front(&mut self) -> Option<T> {
        self.inner.pop_front()
    }

    #[inline]
    pub fn pop_back(&mut self) -> Option<T> {
        self.inner.pop_back()
    }

    #[inline]
    pub fn push_back(&mut self, to_push: T) {
        for element in self.inner.iter() {
            if *element == to_push {
                return;
            }
        }

        self.inner.push_back(to_push);
    }

    #[inline]
    pub fn push_front(&mut self, to_push: T) {
        for element in self.inner.iter() {
            if *element == to_push {
                return;
            }
        }

        self.inner.push_front(to_push);
    }

    #[inline]
    pub fn clear(&mut self) {
        self.inner.clear();
    }

    #[inline]
    pub fn is_empty(&self) -> bool {
        self.inner.is_empty()
    }
}