[−][src]Struct tag_vec::TagVec
This is the main star of this crate. It is an efficient model of a vector of elements, where each element is just a set of tags.
This datatype is intended to handle requests for a huge set of elements whose tags fulfill a requirement, i.e. "all elements with the tag 'fruit' but not with the tag 'apple'.
It is expected that the elements share a lot of tags, i.e. there are a lot fewer tags than elements.
It is not optimized for simply iterating over the tags of each element, hence it is not recommended to do such a thing with this datatype too much.
Methods
impl<T: Eq + Hash + Clone, F: BitField> TagVec<T, F>
[src]
pub fn new() -> TagVec<T, F>
[src]
Creates an empty, new bit vector.
pub fn len(&self) -> usize
[src]
The number of elements in the TagVec
pub fn push<'a, I, Q: ?Sized>(&mut self, tags: I) where
I: IntoIterator<Item = &'a Q>,
Q: Hash + Eq + 'a,
T: From<&'a Q> + Borrow<Q>,
[src]
I: IntoIterator<Item = &'a Q>,
Q: Hash + Eq + 'a,
T: From<&'a Q> + Borrow<Q>,
Pushes a new element onto the bitvec, where the new element is defined as an iterator of tags(borrows of tags specifically)
And OMG the generics on this function are crazy
pub fn query<'a, Q: ?Sized>(&'a self, expr: Expression<'a, Q>) -> Query<'a, F> where
Q: Hash + Eq + 'a,
T: Borrow<Q>,
[src]
Q: Hash + Eq + 'a,
T: Borrow<Q>,
Iterates over all elements who fulfill the given expression. The behind the scenes of this function are complete and utter black magic code, and that code is indeed very strange. Nonetheless, the use of this function is not strange, and in fact quite intuitive
use tag_vec::TagVec; // Make it easier to construct an expression use tag_vec::expressions::*; // Construct a tag_vec let mut tag_vec: TagVec<String> = TagVec::new(); tag_vec.push(vec!["hello", "world"]); tag_vec.push(vec!["rust", "is", "good"]); tag_vec.push(vec!["hello", "is", "good"]); tag_vec.push(vec!["hello", "rust"]); // Query something let mut query = tag_vec.query(tag("hello")); // The first element to contain the tag "hello" is number 0 assert_eq!(query.next(), Some(0)); // ... and so on assert_eq!(query.next(), Some(2)); assert_eq!(query.next(), Some(3)); assert_eq!(query.next(), None); // Oops, we ran out! // Query something more complicated let mut query = tag_vec.query(and(tag("rust"), tag("good"))); // Element "1" is the only element with both the "rust" and "good" tags assert_eq!(query.next(), Some(1)); assert_eq!(query.next(), None);
pub fn iter_element<'a>(&'a self, index: usize) -> IterElement<'a, T, F>
[src]
Iterates over each tag of an element(an element is considered to be its tags). The iterator is unordered, so be careful. Will panic if the index is out of bounds.
Examples:
use tag_vec::TagVec; // It is good to give the type of the key to // the type, as it may be difficult for the compiler // to infer it let mut tag_vec: TagVec<String> = TagVec::new(); tag_vec.push(vec!["hello", "world"]); // We should find a "hello" tag but not a "hi" tag // in the iterator let tags = tag_vec.iter_element(0); assert!(tags.clone().any(|v| *v == "hello")); assert!(!tags.clone().any(|v| *v == "hi"));
Auto Trait Implementations
impl<T, F> RefUnwindSafe for TagVec<T, F> where
F: RefUnwindSafe,
T: RefUnwindSafe,
F: RefUnwindSafe,
T: RefUnwindSafe,
impl<T, F> Send for TagVec<T, F> where
F: Send,
T: Send,
F: Send,
T: Send,
impl<T, F> Sync for TagVec<T, F> where
F: Sync,
T: Sync,
F: Sync,
T: Sync,
impl<T, F> Unpin for TagVec<T, F> where
F: Unpin,
T: Unpin,
F: Unpin,
T: Unpin,
impl<T, F> UnwindSafe for TagVec<T, F> where
F: UnwindSafe,
T: UnwindSafe,
F: UnwindSafe,
T: UnwindSafe,
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,