equal
deleted
inserted
replaced
1 /* |
1 /* |
2 * Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 1999, 2011, 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 |
83 } |
83 } |
84 |
84 |
85 /** Include x in this set. |
85 /** Include x in this set. |
86 */ |
86 */ |
87 public void incl(int x) { |
87 public void incl(int x) { |
88 assert x >= 0; |
88 Assert.check(x >= 0); |
89 sizeTo((x >>> wordshift) + 1); |
89 sizeTo((x >>> wordshift) + 1); |
90 bits[x >>> wordshift] = bits[x >>> wordshift] | |
90 bits[x >>> wordshift] = bits[x >>> wordshift] | |
91 (1 << (x & wordmask)); |
91 (1 << (x & wordmask)); |
92 } |
92 } |
93 |
93 |
111 } |
111 } |
112 |
112 |
113 /** Exclude x from this set. |
113 /** Exclude x from this set. |
114 */ |
114 */ |
115 public void excl(int x) { |
115 public void excl(int x) { |
116 assert x >= 0; |
116 Assert.check(x >= 0); |
117 sizeTo((x >>> wordshift) + 1); |
117 sizeTo((x >>> wordshift) + 1); |
118 bits[x >>> wordshift] = bits[x >>> wordshift] & |
118 bits[x >>> wordshift] = bits[x >>> wordshift] & |
119 ~(1 << (x & wordmask)); |
119 ~(1 << (x & wordmask)); |
120 } |
120 } |
121 |
121 |
167 |
167 |
168 /** Count trailing zero bits in an int. Algorithm from "Hacker's |
168 /** Count trailing zero bits in an int. Algorithm from "Hacker's |
169 * Delight" by Henry S. Warren Jr. (figure 5-13) |
169 * Delight" by Henry S. Warren Jr. (figure 5-13) |
170 */ |
170 */ |
171 private static int trailingZeroBits(int x) { |
171 private static int trailingZeroBits(int x) { |
172 assert wordlen == 32; |
172 Assert.check(wordlen == 32); |
173 if (x == 0) return 32; |
173 if (x == 0) return 32; |
174 int n = 1; |
174 int n = 1; |
175 if ((x & 0xffff) == 0) { n += 16; x >>>= 16; } |
175 if ((x & 0xffff) == 0) { n += 16; x >>>= 16; } |
176 if ((x & 0x00ff) == 0) { n += 8; x >>>= 8; } |
176 if ((x & 0x00ff) == 0) { n += 8; x >>>= 8; } |
177 if ((x & 0x000f) == 0) { n += 4; x >>>= 4; } |
177 if ((x & 0x000f) == 0) { n += 4; x >>>= 4; } |