Main Page   Packages   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members  

ArrayBSet.java

00001 package gov.nasa.arc.ase.util;
00002 
00003 public class ArrayBSet implements BSet {
00004   private static final int SHIFT = 5;
00005   private static final int REMIDER = 32;
00006 
00007   private int[] array;
00008   private int size;
00009 
00010   public ArrayBSet(boolean[] values) {
00011     size = values.length;
00012     array = new int[(size + 31) >> SHIFT];
00013 
00014     for(int i = 0; i < size; i++)
00015       if(values[i])
00016     set(i);
00017   }  
00018   public boolean equals(Object o) {
00019     if(o == null) return false;
00020     if(!(o instanceof ArrayBSet)) return false;
00021 
00022     ArrayBSet s = (ArrayBSet)o;
00023 
00024     if(size != s.size) return false;
00025 
00026     for(int i = 0, l = array.length; i < l; i++)
00027       if(array[i] != s.array[i])
00028     return false;
00029 
00030     return true;
00031   }  
00032   public boolean get(int index) {
00033     if(index < 0)
00034       throw new IndexOutOfBoundsException(index + " < 0");
00035 
00036     if(index >= size)
00037       throw new IndexOutOfBoundsException(index + " >= " + size);
00038 
00039     return (array[index >> SHIFT] & (1 << index % REMIDER)) != 0;
00040   }  
00041   private void set(int index) {
00042     array[index >> SHIFT] |= 1 << index % REMIDER;
00043   }  
00044   public String toString() {
00045     StringBuffer sb = new StringBuffer();
00046 
00047     for(int i = 0, l = size; i < l; i++)
00048       if(get(i))
00049     sb.append('R');
00050       else
00051     sb.append('-');
00052 
00053     return sb.toString();
00054   }  
00055 }

Generated at Thu Feb 7 06:39:27 2002 for Bandera by doxygen1.2.10 written by Dimitri van Heesch, © 1997-2001