| ... | @@ -775,6 +775,18 @@ pub fn IndexedSet(comptime I: type, comptime Ext: fn (type) type) type { | ... | @@ -775,6 +775,18 @@ pub fn IndexedSet(comptime I: type, comptime Ext: fn (type) type) type { |
| 775 | return .{ .bits = BitSet.initFull() }; | 775 | return .{ .bits = BitSet.initFull() }; |
| 776 | } | 776 | } |
| 777 | | 777 | |
| | 778 | /// Returns a set containing multiple keys. |
| | 779 | pub fn initMany(keys: []const Key) Self { |
| | 780 | var set = initEmpty(); |
| | 781 | for (keys) |key| set.insert(key); |
| | 782 | return set; |
| | 783 | } |
| | 784 | |
| | 785 | /// Returns a set containing a single key. |
| | 786 | pub fn initOne(key: Key) Self { |
| | 787 | return initMany(&[_]Key{key}); |
| | 788 | } |
| | 789 | |
| 778 | /// Returns the number of keys in the set. | 790 | /// Returns the number of keys in the set. |
| 779 | pub fn count(self: Self) usize { | 791 | pub fn count(self: Self) usize { |
| 780 | return self.bits.count(); | 792 | return self.bits.count(); |
| ... | @@ -900,20 +912,8 @@ test "pure EnumSet fns" { | ... | @@ -900,20 +912,8 @@ test "pure EnumSet fns" { |
| 900 | | 912 | |
| 901 | const empty = EnumSet(Suit).initEmpty(); | 913 | const empty = EnumSet(Suit).initEmpty(); |
| 902 | const full = EnumSet(Suit).initFull(); | 914 | const full = EnumSet(Suit).initFull(); |
| 903 | | 915 | const black = EnumSet(Suit).initMany(&[_]Suit{ .spades, .clubs }); |
| 904 | const black = black: { | 916 | const red = EnumSet(Suit).initMany(&[_]Suit{ .hearts, .diamonds }); |
| 905 | var set = EnumSet(Suit).initEmpty(); | | |
| 906 | set.insert(.spades); | | |
| 907 | set.insert(.clubs); | | |
| 908 | break :black set; | | |
| 909 | }; | | |
| 910 | | | |
| 911 | const red = red: { | | |
| 912 | var set = EnumSet(Suit).initEmpty(); | | |
| 913 | set.insert(.hearts); | | |
| 914 | set.insert(.diamonds); | | |
| 915 | break :red set; | | |
| 916 | }; | | |
| 917 | | 917 | |
| 918 | try testing.expect(empty.eql(empty)); | 918 | try testing.expect(empty.eql(empty)); |
| 919 | try testing.expect(full.eql(full)); | 919 | try testing.expect(full.eql(full)); |