Created
November 10, 2020 20:19
-
-
Save badamczewski/9a5aa6fbec385061b430465ed043bf5b to your computer and use it in GitHub Desktop.
Bit Set
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class BitSet | |
| { | |
| private ulong[] bitset; | |
| public int Size { get; private set; } | |
| public BitSet(int size) | |
| { | |
| bitset = new ulong[(size / 64) + 1]; | |
| Size = size; | |
| } | |
| public void Add(int index) | |
| { | |
| bitset[index / 64] |= (1u << (index % 64)); | |
| } | |
| public bool Contains(int index) | |
| { | |
| return (bitset[index / 64] & (1u << (index % 64))) != 0; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment