// Returns the index of the next 'true' value greater than or equal to // start. If there is no such value, we return an index greater than // or equal to array.Count. // FIXME: It would be slightly nicer to provide some sort of enumerator // that returned the indexes of the bits that are set. public int GetNextTrueIndex(int start) { if (start >= _length || _contains_true == ContainsTrueState.No) { return(_length); } else if (start < 0) { start = 0; } int i, offset; i = start / 32; offset = start % 32; while (i < _array.Length) { int array_value; array_value = _array [i]; if (array_value != 0) { if (offset > 0) { array_value = array_value >> offset; } while (offset < 32) { if ((array_value & 1) != 0) { if (i * 32 + offset < _length) { _contains_true = ContainsTrueState.Yes; } else if (start == 0) { _contains_true = ContainsTrueState.No; } return(i * 32 + offset); } ++offset; array_value = array_value >> 1; } } ++i; offset = 0; } if (start == 0) { _contains_true = ContainsTrueState.No; } // Failed return(_length); }
public bool ContainsTrue() { if (_contains_true == ContainsTrueState.Maybe) { if (GetNextTrueIndex(0) < _length) { _contains_true = ContainsTrueState.Yes; } else { _contains_true = ContainsTrueState.No; } } return(_contains_true == ContainsTrueState.Yes); }
public bool ContainsTrue () { if (_contains_true == ContainsTrueState.Maybe) { if (GetNextTrueIndex (0) < _length) _contains_true = ContainsTrueState.Yes; else _contains_true = ContainsTrueState.No; } return _contains_true == ContainsTrueState.Yes; }
// Returns the index of the next 'true' value greater than or equal to // start. If there is no such value, we return an index greater than // or equal to array.Count. // FIXME: It would be slightly nicer to provide some sort of enumerator // that returned the indexes of the bits that are set. public int GetNextTrueIndex (int start) { if (start >= _length || _contains_true == ContainsTrueState.No) return _length; else if (start < 0) start = 0; int i, offset; i = start / 32; offset = start % 32; while (i < _array.Length) { int array_value; array_value = _array [i]; if (array_value != 0) { if (offset > 0) array_value = array_value >> offset; while (offset < 32) { if ((array_value & 1) != 0) { if (i * 32 + offset < _length) _contains_true = ContainsTrueState.Yes; else if (start == 0) _contains_true = ContainsTrueState.No; return i * 32 + offset; } ++offset; array_value = array_value >> 1; } } ++i; offset = 0; } if (start == 0) _contains_true = ContainsTrueState.No; // Failed return _length; }