diff --git a/src/BitSet.ts b/src/BitSet.ts index 9d9cd1e..a63ceb0 100644 --- a/src/BitSet.ts +++ b/src/BitSet.ts @@ -489,7 +489,7 @@ export default class BitSet { index = index|0; - return ((this.words[index >>> WORD_LOG] >>> index) & ONE)|0 + return (index >= this._length ? ZERO : (this.words[index >>> WORD_LOG] >>> index) & ONE)|0 } /** @@ -910,7 +910,7 @@ export default class BitSet * * @returns this. */ - public trimTrailingBits(): BitSet + private trimTrailingBits(): BitSet { const wordsLength = this.words.length|0; const diff = (wordsLength*WORD_SIZE - this._length)|0; diff --git a/test/unit/BitSet.spec.ts b/test/unit/BitSet.spec.ts index c344516..6578caf 100644 --- a/test/unit/BitSet.spec.ts +++ b/test/unit/BitSet.spec.ts @@ -1046,26 +1046,6 @@ describe('trim', () => }); }); -describe('trimTrailingBits', () => -{ - it('should return set, bitstring or full bitstring depending on mode', () => - { - const bs = BitSet.create(55).add(9).add(14).add(50); - - bs.words[1] |= (1 << 60); // set a 1 at index 60 the unofficial way :-) - - const str = bs.toString(-1); - - expect(str).to.eql('0001000000000100000000000000000000000000000000000100001000000000'); - expect(str.length).to.eql(64); - expect(bs.length).to.eql(55); - - bs.trimTrailingBits(); - - expect(bs.toString(-1)).to.eql('0000000000000100000000000000000000000000000000000100001000000000'); - }); -}); - describe('union', () => { it('should calculate the union of 2 sets', () =>