equal
deleted
inserted
replaced
1 /* |
1 /* |
2 * Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 1999, 2012, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * |
4 * |
5 * This code is free software; you can redistribute it and/or modify it |
5 * This code is free software; you can redistribute it and/or modify it |
6 * under the terms of the GNU General Public License version 2 only, as |
6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. Oracle designates this |
7 * published by the Free Software Foundation. Oracle designates this |
125 return |
125 return |
126 0 <= x && x < (bits.length << wordshift) && |
126 0 <= x && x < (bits.length << wordshift) && |
127 (bits[x >>> wordshift] & (1 << (x & wordmask))) != 0; |
127 (bits[x >>> wordshift] & (1 << (x & wordmask))) != 0; |
128 } |
128 } |
129 |
129 |
130 /** this set = this set & xs. |
130 /** {@literal this set = this set & xs}. |
131 */ |
131 */ |
132 public Bits andSet(Bits xs) { |
132 public Bits andSet(Bits xs) { |
133 sizeTo(xs.bits.length); |
133 sizeTo(xs.bits.length); |
134 for (int i = 0; i < xs.bits.length; i++) |
134 for (int i = 0; i < xs.bits.length; i++) |
135 bits[i] = bits[i] & xs.bits[i]; |
135 bits[i] = bits[i] & xs.bits[i]; |
177 if ((x & 0x000f) == 0) { n += 4; x >>>= 4; } |
177 if ((x & 0x000f) == 0) { n += 4; x >>>= 4; } |
178 if ((x & 0x0003) == 0) { n += 2; x >>>= 2; } |
178 if ((x & 0x0003) == 0) { n += 2; x >>>= 2; } |
179 return n - (x&1); |
179 return n - (x&1); |
180 } |
180 } |
181 |
181 |
182 /** Return the index of the least bit position >= x that is set. |
182 /** Return the index of the least bit position ≥ x that is set. |
183 * If none are set, returns -1. This provides a nice way to iterate |
183 * If none are set, returns -1. This provides a nice way to iterate |
184 * over the members of a bit set: |
184 * over the members of a bit set: |
185 * <pre> |
185 * <pre>{@code |
186 * for (int i = bits.nextBit(0); i>=0; i = bits.nextBit(i+1)) ... |
186 * for (int i = bits.nextBit(0); i>=0; i = bits.nextBit(i+1)) ... |
187 * </pre> |
187 * }</pre> |
188 */ |
188 */ |
189 public int nextBit(int x) { |
189 public int nextBit(int x) { |
190 int windex = x >>> wordshift; |
190 int windex = x >>> wordshift; |
191 if (windex >= bits.length) return -1; |
191 if (windex >= bits.length) return -1; |
192 int word = bits[windex] & ~((1 << (x & wordmask))-1); |
192 int word = bits[windex] & ~((1 << (x & wordmask))-1); |