Skip to main content

SQLiteSet

Struct SQLiteSet 

Source
pub struct SQLiteSet<T>
where T: Type,
{ /* private fields */ }
Expand description

A set that stores keys of type T, backed by an SQLite in-memory database.

It serves as a drop-in replacement for HashSet.

By default, SQLiteSet<String> treats its keys as case-sensitive, but a case-insensitive variant is available. Even when using the case-sensitive set variant, for some operations a dedicated “case-insensitive” version is provided.

 

For bulk inserts or updates, it is strongly recommended to use an explicit transaction. Without one, SQLite executes each insert or update in its own transaction, which can significantly degrade performance.

Implementations§

Source§

impl<T> SQLiteSet<T>
where T: Type,

Source

pub fn new() -> Result<Self, Error>

Creates a new, empty SQLite-backed hash set with case-sensitive keys.

Source

pub fn with_nocase() -> Result<Self, Error>
where T: CharType,

Creates a new, empty SQLite-backed hash set with case-insensitive keys.

Note that only ASCII characters are case folded. SQLite does not attempt to do full UTF case folding!

Source

pub fn transaction(&mut self) -> Result<SQLiteSetTransaction<'_, T>, Error>

Starts a new SQLite transaction for this set.

Please note that using an explicit SQLite transaction allows for much more efficient bulk inserts 🚀

Returns the new SQLiteSetTransaction instance.

Source

pub fn insert<Q>(&mut self, key: &Q) -> Result<bool, Error>
where T: Borrow<Q>, Q: ?Sized + ToSql,

Inserts the given key into the set.

Returns true, if the set did not already contain the key; otherwise returns false.

Source

pub fn contains<Q>(&self, key: &Q) -> Result<bool, Error>
where T: Borrow<Q>, Q: ?Sized + ToSql,

Checks whether the set contains the specified key.

For case-sensitive sets, the check is case-sensitive; for case-insensitive sets, the check is case-insensitive.

Returns true, if the set contains the key; otherwise returns false.

Source

pub fn contains_nocase<Q>(&self, key: &Q) -> Result<bool, Error>
where T: Borrow<Q> + CharType, Q: ?Sized + ToSql,

This is the “case-insensitive” version of the contains() function.

The check is always performed case-insensitive.

Returns true, if the set contains the key; otherwise returns false.

Source

pub fn remove<Q>(&mut self, key: &Q) -> Result<bool, Error>
where T: Borrow<Q>, Q: ?Sized + ToSql,

Removes the specified key from the set, if present.

For case-sensitive sets, the key is treated as case-sensitive; for case-insensitive sets, it is treated as case-insensitive.

Returns true, if the set contained the key; otherwise returns false.

Source

pub fn remove_nocase<Q>(&mut self, key: &Q) -> Result<bool, Error>
where T: Borrow<Q> + CharType, Q: ?Sized + ToSql,

This is the “case-insensitive” version of the remove() function.

The key is always treated as case-insensitive.

Returns true, if the set contained the key; otherwise returns false.

Source

pub fn for_each<F>(&self, callback: F) -> Result<(), Error>
where F: FnMut(T),

Invokes the given callback function for each key that is currently contained in the set.

This function does not guarantee a specific iteration order.

Source

pub fn find<P, Q>(&self, predicate: P) -> Result<Option<T>, Error>
where P: Fn(&Q) -> bool, T: Borrow<Q>, Q: ?Sized,

Searches the set for the first key that satisfies the given predicate.

Returns the first key that satisfies the given predicate, or None if no key satisfies the predicate or the set is empty.

This function does not guarantee a specific iteration order.

Also, the predicate is not always tested on all keys, because the function returns at the first match.

Source

pub fn filter<F, Q>(&self, pattern: &Q, callback: F) -> Result<(), Error>
where F: FnMut(T), T: Borrow<Q> + CharType, Q: ?Sized + ToSql,

Invokes the given callback function for each key that matches the given pattern.

In the pattern string, the special character % matches zero or more characters, the special character _ matches exactly one character, and the special character \ serves as an escape character. All other characters are literals.

Please note that SQLite’s pattern matching is always case-insensitive.

For example, the pattern A% matches all keys that begin with the character “A”, whereas the pattern H_nt matches all keys with a length of exactly four characters where the first character is “H” and the last two characters are “nt”.

This function does not guarantee a specific iteration order.

Source

pub fn len(&self) -> Result<Size, Error>

Returns the number of unique keys in the set.

Source

pub fn is_empty(&self) -> Result<bool, Error>

Returns true if the set contains no keys; otherwise returns false.

Source

pub fn clear(&mut self) -> Result<(), Error>

Removes all keys from the set.

Auto Trait Implementations§

§

impl<T> !Freeze for SQLiteSet<T>

§

impl<T> !RefUnwindSafe for SQLiteSet<T>

§

impl<T> !Sync for SQLiteSet<T>

§

impl<T> !UnwindSafe for SQLiteSet<T>

§

impl<T> Send for SQLiteSet<T>
where PhantomData<T>: Send,

§

impl<T> Unpin for SQLiteSet<T>
where PhantomData<T>: Unpin,

§

impl<T> UnsafeUnpin for SQLiteSet<T>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.