class BitSet(capacity: Int) { var data: Array[Int] = nil; var capacity: Int = 0; if capacity > 0 { let entries = (capacity + 31) / 32; self.data = Array[Int](entries); self.capacity = capacity; } fun contains(idx: Int) -> Bool { if idx < 0 || idx >= self.capacity { fatalError("index out of bounds"); } let entry_idx = idx / 32; let value = self.data.get(entry_idx); let value_idx = idx - entry_idx; return value & (1 << value_idx) != 0; } fun insert(idx: Int) { if idx < 0 || idx >= self.capacity { fatalError("index out of bounds"); } let entry_idx = idx / 32; var value = self.data.get(entry_idx); let value_idx = idx - entry_idx; value = value | (1 << value_idx); self.data.set(entry_idx, value); } fun remove(idx: Int) { if idx < 0 || idx >= self.capacity { fatalError("index out of bounds"); } let entry_idx = idx / 32; var value = self.data.get(entry_idx); let value_idx = idx - entry_idx; value = value & !(1 << value_idx); self.data.set(entry_idx, value); } }