1 package nmp.util;
2
3 import java.util.*;
4
5 /***
6 * Similar to BitSet extended with a counter of the number of elements set to 1.
7 */
8 public class ExtBitSet
9 {
10 private int len;
11 public BitSet s;
12
13 public ExtBitSet( int size) {
14 s = new BitSet( size);
15 len = 0;
16 }
17
18 public ExtBitSet() {
19 s = new BitSet();
20 len = 0;
21 }
22
23 protected ExtBitSet( ExtBitSet s0) {
24 this.len = s0.len;
25 this.s = (BitSet)s0.s.clone();
26 }
27
28 public Object clone() {
29 return new ExtBitSet( this);
30 }
31 public boolean get( int pos) {
32 return s.get( pos);
33 }
34
35 public void set( int pos) {
36 if( ! s.get( pos)) {
37 s.set( pos);
38 len++;
39 }
40 }
41
42 public void clear( int pos) {
43 if( s.get( pos)) {
44 s.clear( pos);
45 len--;
46 }
47 }
48
49 public void and( BitSet s0) {
50 s.and( s0);
51 len = -30000;
52 }
53
54 public void xor( BitSet s0) {
55 s.xor( s0);
56 len = -30000;
57 }
58
59 public void or( BitSet s0) {
60 s.or( s0);
61 len = -30000;
62 }
63
64 public int size() {
65 return s.size();
66 }
67
68 public int numElems() {
69 if( len < 0) {
70 len = 0;
71 for( int i = 0; i < s.size(); i++)
72 if( s.get( i))
73 len++;
74 }
75 return len;
76 }
77 }
This page was automatically generated by Maven