Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private boolean[] bits;
- public BitVector and(BitVector anotherVector) {
- if (this == anotherVector) return (BitVector) clone();
- if (size() != anotherVector.size())
- throw new IllegalArgumentException("Incompatible sizes: size="+size()+", other.size()="+anotherVector.size());
- BitVector intersectionVector = new BitVector(size());
- for (int i = 0; i < size(); i++){
- if (get(i) & anotherVector.get(i))
- intersectionVector.set(i);
- }
- return intersectionVector;
- }
- public Object clone() {
- BitVector clone = null;
- try {
- clone = (BitVector) super.clone();
- } catch (CloneNotSupportedException e) {
- e.printStackTrace();
- }
- if (this.bits != null) clone.bits = this.bits.clone();
- return clone;
- }
- public void set(int index){
- bits[index] = true;
- }
- public boolean get(int index){
- return bits[index];
- }
- public int size() {
- return this.bits.length;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement