FlagSet
HashSet
only implements the normal set. HashSet
can not represent its complementary set when the complementary set is an infinite set.
FlagSet
implemented as a tuple of a HashSet
and a bool
value. When the bool
value is true, FlagSet
represents the HashSet
. When the bool
value is true, FlagSet
represents the the complementary set of HashSet
.
As with the HashSet
type, a FlagSet
requires that the elements implement the Eq
and Hash
traits. In addition to operations of FlagSet
, the elements also implement the Clone
trait.
FlagSet
also defines five kinds of operations of sets based on Binary Operations
.
A ∪B -> A + B
A ∩ B -> A & B
A - B -> A - B
A Xor B -> A ^ B
CuA -> !A
Examples
use HashSet;
use FlagSet;
let a: = vec!.into_iter.collect;
let b: = vec!.into_iter.collect;
let flag_ap = FlagSet;
let flag_an = FlagSet;
let flag_bp = FlagSet;
let flag_bn = FlagSet;
// 用new方法创建实例
// use new method create an instance
assert_eq!;
// 测试并
// test union
assert_eq!;
assert_eq!;
assert_eq!;
assert_eq!;
// 测试交
// test intersection
assert_eq!;
assert_eq!;
assert_eq!;
assert_eq!;
// 测试减
// test substraction
assert_eq!;
assert_eq!;
assert_eq!;
assert_eq!;
// 测试否
// test not
assert_eq!;
// 测试对称差
// test symmetric difference
assert_eq!;