Sets
Description
This crate defines Structs: Set, OrderedSet, IndexedSet, RankedSet
and methods acting on them. These Struct
s are type-safe wrappers for the more primitive imported functions and methods from crate indxvec
.
The main capabilities of sets
include: efficient sorting, ranking, merging, searching and indices manipulations. These methods work with generic vectors or slices of primitive end types. They will also work with any arbitrarily complex user end type, as long as the required traits PartialOrd
and Copy
, are implemented for it (by the user).
Usage
Insert into your Cargo.toml
file [dependencies] section: sets = "^1"
Import into your source file(s) the four Struct
s for the four different types of sets and the two traits SetOps
and MutSetOps
. The following 'use' declaration imports everything:
use ;
Initialisers and Converters
from_slice(), from_set(), from_indexed, from_ranked
Initialisers and converters are associated with their type Struct
s, hence the ::
syntax is necessary, e.g.:
// Unordered set from slice v
let s = from_slice;
// Automatically creates a descending sort index for v
let si = from_slice;
Example use of methods from the traits SetOps
, and MutSetOps
:
// Mutable set su with unique elements from s
let mut su = s.nonrepeat;
// su mutated-reversed into the opposite order
su.mreverse;
It is highly recommended to read and run tests/tests.rs
for many more examples of usage. Use a single thread to run them. It may be a bit slower but it will write the results in the right order:
Trait SetOps
Implements the following methods for all four types of sets (Struct
s):
Some of these methods are more efficient for the ordered and indexed sets, rather than for the unordered sets. For example, member
and search
are then able to use binary search. Union is like the classical merge but only one copy of items that were present in both input sets is kept. To remove repetitions from a single set at any other time, use nonrepeat
.
intersection
and difference
, when applied to IndexedSet(s) and RankedSet(s) return an OrderedSet as a result. This result can be explicitly converted to other types of sets when needed.
Union
returns the same type as the one to which it is applied. Thus, for example, union of two (unordered) Set
s will produce another unordered Set
(just their concatenation).
Trait MutSetOps
Here 'm' in the methods' names stands for 'mutable'. They overwrite the mutable set to which they are applied with the result. Thus they are not functional but in the context of handling large vectors, they are often simpler and more efficient. At the price of destroying the previous contents of self, of course.
Implements the following methods for all four types of sets:
Release Notes (Latest First)
Version 1.0.6 - Added mutable methods minsert
and mdelete
to MutSetOps
, that insert or remove one specific item to/from any of the sets. Added tests of them to tests/tests.rs
. Updated indxvec
dependency to its version 1.2.4
or greater.
Version 1.0.5 - Documentation improvements.
Version 1.0.4 - nonrepeat
now always returns an OrderedSet. Clarified settest
.
Version 1.0.3 - updated to be compatible with indxvec
version 1.2.1. Improved munion
.
Version 1.0.2 - some changes to printing to reflect changes to indxvec
.
Version 1.0.1 - some tidying up of code, no changes of functionality.
Version 1.0.0 - stable version with some minor improvements to README.md
(this document). Updated to indxvec = "^1"
and Rust edition 2021.