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,
impl<T> SQLiteSet<T>where
T: Type,
Sourcepub fn new() -> Result<Self, Error>
pub fn new() -> Result<Self, Error>
Creates a new, empty hash set with case-sensitive keys, backed by an in-memory SQLite database.
Sourcepub fn with_nocase() -> Result<Self, Error>where
T: CharType,
pub fn with_nocase() -> Result<Self, Error>where
T: CharType,
Creates a new, empty hash set with case-insensitive keys, backed by an in-memory SQLite database.
Only ASCII characters are case folded. SQLite does not attempt to do full UTF case folding!
Sourcepub fn from_file<P>(
path: P,
readonly: bool,
can_create: bool,
) -> Result<Self, Error>
pub fn from_file<P>( path: P, readonly: bool, can_create: bool, ) -> Result<Self, Error>
Creates a new or re-opens an existing hash set with case-sensitive keys, backed by a file-based SQLite database.
If readonly is true, the database file is opened in “read-only” mode.
If can_create is true (and if readonly is false), a new empty database file is created, if the file does not exist yet.
Returns Error::InvalidSchema, if the database file already exists but its schema does not match the schema expected by this type of set. This means that you must re-open a database file with the same type of set that was used to create it.
Sourcepub fn from_file_nocase<P>(
path: P,
readonly: bool,
can_create: bool,
) -> Result<Self, Error>
pub fn from_file_nocase<P>( path: P, readonly: bool, can_create: bool, ) -> Result<Self, Error>
Creates a new or re-opens an existing hash set with case-insensitive keys, backed by a file-based SQLite database.
If readonly is true, the database file is opened in “read-only” mode.
If can_create is true (and if readonly is false), a new empty database file is created, if the file does not exist yet.
Returns Error::InvalidSchema, if the database file already exists but its schema does not match the schema expected by this type of set. This means that you must re-open a database file with the same type of set that was used to create it.
Only ASCII characters are case folded. SQLite does not attempt to do full UTF case folding!
Sourcepub fn transaction(&mut self) -> Result<SQLiteSetTransaction<'_, T>, Error>
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.
Sourcepub fn insert<Q>(&mut self, key: &Q) -> Result<bool, Error>
pub fn insert<Q>(&mut self, key: &Q) -> Result<bool, Error>
Inserts the given key into the set.
Returns true, if the set did not already contain the key; otherwise returns false.
Sourcepub fn union(&mut self, other: &Self) -> Result<Size, Error>
pub fn union(&mut self, other: &Self) -> Result<Size, Error>
Inserts all keys from another set into this set, ignoring existing keys.
Returns the number of new keys that have been inserted.
Sourcepub fn contains<Q>(&self, key: &Q) -> Result<bool, Error>
pub fn contains<Q>(&self, key: &Q) -> Result<bool, Error>
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.
Sourcepub fn contains_nocase<Q>(&self, key: &Q) -> Result<bool, Error>
pub fn contains_nocase<Q>(&self, key: &Q) -> Result<bool, Error>
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.
Sourcepub fn remove<Q>(&mut self, key: &Q) -> Result<bool, Error>
pub fn remove<Q>(&mut self, key: &Q) -> Result<bool, Error>
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.
Sourcepub fn remove_nocase<Q>(&mut self, key: &Q) -> Result<bool, Error>
pub fn remove_nocase<Q>(&mut self, key: &Q) -> Result<bool, Error>
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.
Sourcepub fn for_each<F>(&self, callback: F) -> Result<(), Error>where
F: FnMut(T),
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.
Sourcepub fn find<P, Q>(&self, predicate: P) -> Result<Option<T>, Error>
pub fn find<P, Q>(&self, predicate: P) -> Result<Option<T>, Error>
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.
Sourcepub fn glob<F, Q>(
&self,
invert: bool,
pattern: &Q,
callback: F,
) -> Result<(), Error>
pub fn glob<F, Q>( &self, invert: bool, pattern: &Q, callback: F, ) -> Result<(), Error>
Invokes the given callback function for each key that matches the given pattern.
The pattern string is interpreted according to the UNIX globbing rules. Specifically, a ? character (not between brackets) matches any single character, and a * character (not between brackets) matches any string, including the empty string. Additionally, an expression […] where the first character after the leading [ is not an ! matches a single character that can be any of the characters enclosed by the brackets; and an expression [!…] matches a single character that is not matched by the expression.
This function is case-sensitive and does not guarantee a specific iteration order.
If invert is true, returns all keys that do not match the pattern; otherwise the matching keys are returned.