We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 55c8337 commit 5922942Copy full SHA for 5922942
03-DataStructures/BitSet.js
@@ -0,0 +1,29 @@
1
+class BitSet {
2
+ constructor(size = 32) {
3
+ this.size = size;
4
+ this.bits = new Uint32Array(Math.ceil(size / 32));
5
+ }
6
+
7
+ add(value) {
8
+ const index = Math.floor(value / 32);
9
+ const position = value % 32;
10
+ this.bits[index] |= 1 << position;
11
12
13
+ has(value) {
14
15
16
+ return (this.bits[index] & (1 << position)) !== 0;
17
18
19
20
+ // Example usage:
21
+ const bitSet = new BitSet();
22
23
+ bitSet.add(10);
24
+ bitSet.add(32);
25
+ bitSet.add(50);
26
27
+ console.log(bitSet.has(10)); // Output: true
28
+ console.log(bitSet.has(15)); // Output: false
29
0 commit comments