From: <ha...@us...> - 2010-02-08 19:29:43
|
Revision: 12344 http://jmol.svn.sourceforge.net/jmol/?rev=12344&view=rev Author: hansonr Date: 2010-02-08 19:29:32 +0000 (Mon, 08 Feb 2010) Log Message: ----------- limited cardinality Modified Paths: -------------- trunk/Jmol/src/org/jmol/geodesic/EnvelopeCalculation.java trunk/Jmol/src/org/jmol/util/FastBitSet.java trunk/Jmol/src/org/jmol/util/SlowBitSet.java Modified: trunk/Jmol/src/org/jmol/geodesic/EnvelopeCalculation.java =================================================================== --- trunk/Jmol/src/org/jmol/geodesic/EnvelopeCalculation.java 2010-02-08 18:58:19 UTC (rev 12343) +++ trunk/Jmol/src/org/jmol/geodesic/EnvelopeCalculation.java 2010-02-08 19:29:32 UTC (rev 12344) @@ -141,6 +141,7 @@ private AtomData atomData = new AtomData(); private AtomDataServer viewer; private int atomCount; + private FastBitSet emptySet; public EnvelopeCalculation(AtomDataServer viewer, int atomCount, short[] mads, boolean asJavaBitSet) { this.viewer = viewer; @@ -150,10 +151,12 @@ if (asJavaBitSet) { geodesicMap = SlowBitSet.allocateBitmap(geodesicCount); - mapT = SlowBitSet.allocateBitmap(geodesicCount); + mapT = SlowBitSet.allocateBitmap(geodesicCount); + emptySet = SlowBitSet.nullMap; } else { geodesicMap = FastBitSet.allocateBitmap(geodesicCount); mapT = FastBitSet.allocateBitmap(geodesicCount); + emptySet = FastBitSet.getEmptySet(); } } @@ -206,7 +209,7 @@ dotsConvexMaps = new FastBitSet[atomCount]; FastBitSet map; if (geodesicMap.isEmpty()) - map = FastBitSet.getEmptySet(); + map = emptySet; else map = new FastBitSet(geodesicMap); dotsConvexMaps[index] = map; @@ -289,7 +292,7 @@ int nPoints = 0; int dotCount = 42; for (int i = dotsConvexMax; --i >= 0;) - nPoints += dotsConvexMaps[i].cardinality(); + nPoints += dotsConvexMaps[i].cardinality(dotCount); Point3f[] points = new Point3f[nPoints]; if (nPoints == 0) return points; @@ -351,7 +354,7 @@ calcConvexBits(); FastBitSet map; if (geodesicMap.isEmpty()) - map = FastBitSet.getEmptySet(); + map = emptySet; else { bsSurface.set(indexI); if (isSurface) { Modified: trunk/Jmol/src/org/jmol/util/FastBitSet.java =================================================================== --- trunk/Jmol/src/org/jmol/util/FastBitSet.java 2010-02-08 18:58:19 UTC (rev 12343) +++ trunk/Jmol/src/org/jmol/util/FastBitSet.java 2010-02-08 19:29:32 UTC (rev 12344) @@ -79,6 +79,19 @@ return bitmapGetCardinality(bitmap); } + /** + * + * @param max + * @return n bits below max + */ + public int cardinality(int max) { + int n = bitmapGetCardinality(bitmap); + for (int i = length(); --i >= max;) + if (get(i)) + n--; + return n; + } + public void clear() { bitmapClear(bitmap); } @@ -479,16 +492,20 @@ // / testing: /* - * FastBitSet(BitSet bs) { bitmap = new - * int[getWordCountFromBitCount(bs.size())]; for (int i = bs.nextSetBit(0); i - * >= 0; i = bs.nextSetBit(i + 1)) set(i); } - * - * - * static { - * - * FastBitSet bs = new FastBitSet(Escape.unescapeBitset("{(33:45 75:80)}")); - * // ...do whatever here... System.out.println(bs); - * - * } - */ + FastBitSet(java.util.BitSet bs) { + bitmap = new int[getWordCountFromBitCount(bs.size())]; + for (int i = bs.nextSetBit(0); i >= 0; i = bs.nextSetBit(i + 1)) + set(i); + } + + static { + + FastBitSet bs = new FastBitSet(Escape.unescapeBitset("{(33:45 75:80)}")); + System.out.println(bs.cardinality()); + System.out.println(bs.cardinality(35)); + // ...do whatever here... System.out.println(bs); + + } + + */ } Modified: trunk/Jmol/src/org/jmol/util/SlowBitSet.java =================================================================== --- trunk/Jmol/src/org/jmol/util/SlowBitSet.java 2010-02-08 18:58:19 UTC (rev 12343) +++ trunk/Jmol/src/org/jmol/util/SlowBitSet.java 2010-02-08 19:29:32 UTC (rev 12344) @@ -31,75 +31,87 @@ public class SlowBitSet extends FastBitSet { - public SlowBitSet() { - super(); - } - + public final static SlowBitSet nullMap = new SlowBitSet(); + public static FastBitSet allocateBitmap(int count) { return new SlowBitSet(count, true); } - + private BitSet bs; + public SlowBitSet() { + bs = new BitSet(); + } + protected SlowBitSet(int count, boolean asBits) { bs = new BitSet(asBits ? count : count * 64 ); } - public FastBitSet copyFast() { - return (SlowBitSet) this.clone(); + public int cardinality() { + return bs.cardinality(); } - public boolean getBit(int i) { - return bs.get(i); + public int cartdinality(int dotCount) { + return bs.cardinality(); } - public int getPointCount(int dotCount) { - return bs.cardinality(); + public void clear() { + bs.clear(); } - public int getSize() { - return bs.size(); + public void clear(int i) { + bs.clear(i); } + + public void clear(int i, int j) { + bs.clear(i, j); + } - public void setBit(int i) { - bs.set(i); + public Object clone() { + SlowBitSet result = new SlowBitSet(); + result.bs = (BitSet) bs.clone(); + return result; } + + public FastBitSet copy() { + return (SlowBitSet) clone(); + } - public void clearBit(int i) { - bs.clear(i); + public boolean get(int i) { + return bs.get(i); } + /* public void setAllBits(int count) { bs.set(0, count); } + */ - public void clearBitmap() { - bs.clear(); - } - public int getMapStorageCount() { return bs.size() * 64; } - public int getCardinality() { - return bs.cardinality(); + public int hashCode() { + return bs.hashCode(); } - public BitSet toBitSet() { - return BitSetUtil.copy(bs); + public void set(int i) { + bs.set(i); } - public Object clone() { - SlowBitSet result = new SlowBitSet(); - result.bs = (BitSet) bs.clone(); - return result; + public void set(int i, int j) { + bs.set(i, j); } + public int size() { + return bs.size(); + } + + public BitSet toBitSet() { + return BitSetUtil.copy(bs); + } + public String toString() { return Escape.escape(bs); } - - public int hashCode() { - return bs.hashCode(); - } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |