| ... | @@ -4,10 +4,6 @@ | ... | @@ -4,10 +4,6 @@ |
| 4 | // The MIT license requires this copyright notice to be included in all copies | 4 | // The MIT license requires this copyright notice to be included in all copies |
| 5 | // and substantial portions of the software. | 5 | // and substantial portions of the software. |
| 6 | | 6 | |
| 7 | const std = @import("std"); | | |
| 8 | const assert = std.debug.assert; | | |
| 9 | const Allocator = std.mem.Allocator; | | |
| 10 | | | |
| 11 | //! This file defines several variants of bit sets. A bit set | 7 | //! This file defines several variants of bit sets. A bit set |
| 12 | //! is a densely stored set of integers with a known maximum, | 8 | //! is a densely stored set of integers with a known maximum, |
| 13 | //! in which each integer gets a single bit. Bit sets have very | 9 | //! in which each integer gets a single bit. Bit sets have very |
| ... | @@ -40,6 +36,10 @@ const Allocator = std.mem.Allocator; | ... | @@ -40,6 +36,10 @@ const Allocator = std.mem.Allocator; |
| 40 | //! A variant of DynamicBitSet which does not store a pointer to its | 36 | //! A variant of DynamicBitSet which does not store a pointer to its |
| 41 | //! allocator, in order to save space. | 37 | //! allocator, in order to save space. |
| 42 | | 38 | |
| | 39 | const std = @import("std"); |
| | 40 | const assert = std.debug.assert; |
| | 41 | const Allocator = std.mem.Allocator; |
| | 42 | |
| 43 | /// Returns the optimal static bit set type for the specified number | 43 | /// Returns the optimal static bit set type for the specified number |
| 44 | /// of elements. The returned type will perform no allocations, | 44 | /// of elements. The returned type will perform no allocations, |
| 45 | /// can be copied by value, and does not require deinitialization. | 45 | /// can be copied by value, and does not require deinitialization. |
| ... | @@ -83,7 +83,7 @@ pub fn IntegerBitSet(comptime size: u16) type { | ... | @@ -83,7 +83,7 @@ pub fn IntegerBitSet(comptime size: u16) type { |
| 83 | } | 83 | } |
| 84 | | 84 | |
| 85 | /// Returns the number of bits in this bit set | 85 | /// Returns the number of bits in this bit set |
| 86 | pub inline fn capacity(self: Self) usize { | 86 | pub fn capacity(self: Self) callconv(.Inline) usize { |
| 87 | return bit_length; | 87 | return bit_length; |
| 88 | } | 88 | } |
| 89 | | 89 | |
| ... | @@ -168,7 +168,7 @@ pub fn IntegerBitSet(comptime size: u16) type { | ... | @@ -168,7 +168,7 @@ pub fn IntegerBitSet(comptime size: u16) type { |
| 168 | const mask = self.mask; | 168 | const mask = self.mask; |
| 169 | if (mask == 0) return null; | 169 | if (mask == 0) return null; |
| 170 | const index = @ctz(MaskInt, mask); | 170 | const index = @ctz(MaskInt, mask); |
| 171 | self.mask = mask & (mask-1); | 171 | self.mask = mask & (mask - 1); |
| 172 | return index; | 172 | return index; |
| 173 | } | 173 | } |
| 174 | | 174 | |
| ... | @@ -306,7 +306,7 @@ pub fn ArrayBitSet(comptime MaskIntType: type, comptime size: usize) type { | ... | @@ -306,7 +306,7 @@ pub fn ArrayBitSet(comptime MaskIntType: type, comptime size: usize) type { |
| 306 | } | 306 | } |
| 307 | | 307 | |
| 308 | /// Returns the number of bits in this bit set | 308 | /// Returns the number of bits in this bit set |
| 309 | pub inline fn capacity(self: Self) usize { | 309 | pub fn capacity(self: Self) callconv(.Inline) usize { |
| 310 | return bit_length; | 310 | return bit_length; |
| 311 | } | 311 | } |
| 312 | | 312 | |
| ... | @@ -566,7 +566,7 @@ pub const DynamicBitSetUnmanaged = struct { | ... | @@ -566,7 +566,7 @@ pub const DynamicBitSetUnmanaged = struct { |
| 566 | } | 566 | } |
| 567 | | 567 | |
| 568 | /// Returns the number of bits in this bit set | 568 | /// Returns the number of bits in this bit set |
| 569 | pub inline fn capacity(self: Self) usize { | 569 | pub fn capacity(self: Self) callconv(.Inline) usize { |
| 570 | return self.bit_length; | 570 | return self.bit_length; |
| 571 | } | 571 | } |
| 572 | | 572 | |
| ... | @@ -691,7 +691,7 @@ pub const DynamicBitSetUnmanaged = struct { | ... | @@ -691,7 +691,7 @@ pub const DynamicBitSetUnmanaged = struct { |
| 691 | offset += @bitSizeOf(MaskInt); | 691 | offset += @bitSizeOf(MaskInt); |
| 692 | } else return null; | 692 | } else return null; |
| 693 | const index = @ctz(MaskInt, mask[0]); | 693 | const index = @ctz(MaskInt, mask[0]); |
| 694 | mask[0] &= (mask[0]-1); | 694 | mask[0] &= (mask[0] - 1); |
| 695 | return offset + index; | 695 | return offset + index; |
| 696 | } | 696 | } |
| 697 | | 697 | |
| ... | @@ -777,7 +777,7 @@ pub const DynamicBitSet = struct { | ... | @@ -777,7 +777,7 @@ pub const DynamicBitSet = struct { |
| 777 | } | 777 | } |
| 778 | | 778 | |
| 779 | /// Returns the number of bits in this bit set | 779 | /// Returns the number of bits in this bit set |
| 780 | pub inline fn capacity(self: Self) usize { | 780 | pub fn capacity(self: Self) callconv(.Inline) usize { |
| 781 | return self.unmanaged.capacity(); | 781 | return self.unmanaged.capacity(); |
| 782 | } | 782 | } |
| 783 | | 783 | |
| ... | @@ -955,7 +955,7 @@ fn BitSetIterator(comptime MaskInt: type, comptime options: IteratorOptions) typ | ... | @@ -955,7 +955,7 @@ fn BitSetIterator(comptime MaskInt: type, comptime options: IteratorOptions) typ |
| 955 | // isn't a next word. If the next word is the | 955 | // isn't a next word. If the next word is the |
| 956 | // last word, mask off the padding bits so we | 956 | // last word, mask off the padding bits so we |
| 957 | // don't visit them. | 957 | // don't visit them. |
| 958 | inline fn nextWord(self: *Self, comptime is_first_word: bool) void { | 958 | fn nextWord(self: *Self, comptime is_first_word: bool) callconv(.Inline) void { |
| 959 | var word = switch (direction) { | 959 | var word = switch (direction) { |
| 960 | .forward => self.words_remain[0], | 960 | .forward => self.words_remain[0], |
| 961 | .reverse => self.words_remain[self.words_remain.len - 1], | 961 | .reverse => self.words_remain[self.words_remain.len - 1], |
| ... | @@ -1114,8 +1114,9 @@ fn testBitSet(a: anytype, b: anytype, len: usize) void { | ... | @@ -1114,8 +1114,9 @@ fn testBitSet(a: anytype, b: anytype, len: usize) void { |
| 1114 | } | 1114 | } |
| 1115 | | 1115 | |
| 1116 | const test_bits = [_]usize{ | 1116 | const test_bits = [_]usize{ |
| 1117 | 0, 1, 2, 3, 4, 5, 6, 7, 9, 10, 11, 22, 31, 32, 63, 64, | 1117 | 0, 1, 2, 3, 4, 5, 6, 7, 9, 10, 11, 22, 31, 32, 63, 64, |
| 1118 | 66, 95, 127, 160, 192, 1000 }; | 1118 | 66, 95, 127, 160, 192, 1000, |
| | 1119 | }; |
| 1119 | for (test_bits) |i| { | 1120 | for (test_bits) |i| { |
| 1120 | if (i < a.capacity()) { | 1121 | if (i < a.capacity()) { |
| 1121 | a.set(i); | 1122 | a.set(i); |