@ -90,7 +90,7 @@ public class BitmapIndexImpl implements BitmapIndex {
EWAHCompressedBitmap compressed = packIndex . getBitmap ( objectId ) ;
EWAHCompressedBitmap compressed = packIndex . getBitmap ( objectId ) ;
if ( compressed = = null )
if ( compressed = = null )
return null ;
return null ;
return new CompressedBitmap ( compressed ) ;
return new CompressedBitmap ( compressed , this ) ;
}
}
public CompressedBitmap toBitmap ( PackBitmapIndex i ,
public CompressedBitmap toBitmap ( PackBitmapIndex i ,
@ -101,12 +101,12 @@ public class BitmapIndexImpl implements BitmapIndex {
if ( b = = null ) {
if ( b = = null ) {
return null ;
return null ;
}
}
return new CompressedBitmap ( b ) ;
return new CompressedBitmap ( b , this ) ;
}
}
@Override
@Override
public CompressedBitmapBuilder newBitmapBuilder ( ) {
public CompressedBitmapBuilder newBitmapBuilder ( ) {
return new CompressedBitmapBuilder ( ) ;
return new CompressedBitmapBuilder ( this ) ;
}
}
int findPosition ( AnyObjectId objectId ) {
int findPosition ( AnyObjectId objectId ) {
@ -210,16 +210,22 @@ public class BitmapIndexImpl implements BitmapIndex {
}
}
}
}
private final class CompressedBitmapBuilder implements BitmapBuilder {
private static final class CompressedBitmapBuilder implements BitmapBuilder {
private ComboBitset bitset = new ComboBitset ( ) ;
private ComboBitset bitset ;
private final BitmapIndexImpl bitmapIndex ;
CompressedBitmapBuilder ( BitmapIndexImpl bitmapIndex ) {
this . bitset = new ComboBitset ( ) ;
this . bitmapIndex = bitmapIndex ;
}
@Override
@Override
public boolean add ( AnyObjectId objectId , int type ) {
public boolean add ( AnyObjectId objectId , int type ) {
int position = findOrInsert ( objectId , type ) ;
int position = bitmapIndex . findOrInsert ( objectId , type ) ;
if ( bitset . contains ( position ) )
if ( bitset . contains ( position ) )
return false ;
return false ;
Bitmap entry = getBitmap ( objectId ) ;
Bitmap entry = bitmapIndex . getBitmap ( objectId ) ;
if ( entry ! = null ) {
if ( entry ! = null ) {
or ( entry ) ;
or ( entry ) ;
return false ;
return false ;
@ -231,66 +237,45 @@ public class BitmapIndexImpl implements BitmapIndex {
@Override
@Override
public boolean contains ( AnyObjectId objectId ) {
public boolean contains ( AnyObjectId objectId ) {
int position = findPosition ( objectId ) ;
int position = bitmapIndex . findPosition ( objectId ) ;
return 0 < = position & & bitset . contains ( position ) ;
return 0 < = position & & bitset . contains ( position ) ;
}
}
@Override
@Override
public BitmapBuilder addObject ( AnyObjectId objectId , int type ) {
public BitmapBuilder addObject ( AnyObjectId objectId , int type ) {
bitset . set ( findOrInsert ( objectId , type ) ) ;
bitset . set ( bitmapIndex . findOrInsert ( objectId , type ) ) ;
return this ;
return this ;
}
}
@Override
@Override
public void remove ( AnyObjectId objectId ) {
public void remove ( AnyObjectId objectId ) {
int position = findPosition ( objectId ) ;
int position = bitmapIndex . findPosition ( objectId ) ;
if ( 0 < = position )
if ( 0 < = position )
bitset . remove ( position ) ;
bitset . remove ( position ) ;
}
}
@Override
@Override
public CompressedBitmapBuilder or ( Bitmap other ) {
public CompressedBitmapBuilder or ( Bitmap other ) {
if ( isSameCompressedBitmap ( other ) ) {
bitset . or ( ewahBitmap ( other ) ) ;
bitset . or ( ( ( CompressedBitmap ) other ) . bitmap ) ;
} else if ( isSameCompressedBitmapBuilder ( other ) ) {
CompressedBitmapBuilder b = ( CompressedBitmapBuilder ) other ;
bitset . or ( b . bitset . combine ( ) ) ;
} else {
throw new IllegalArgumentException ( ) ;
}
return this ;
return this ;
}
}
@Override
@Override
public CompressedBitmapBuilder andNot ( Bitmap other ) {
public CompressedBitmapBuilder andNot ( Bitmap other ) {
if ( isSameCompressedBitmap ( other ) ) {
bitset . andNot ( ewahBitmap ( other ) ) ;
bitset . andNot ( ( ( CompressedBitmap ) other ) . bitmap ) ;
} else if ( isSameCompressedBitmapBuilder ( other ) ) {
CompressedBitmapBuilder b = ( CompressedBitmapBuilder ) other ;
bitset . andNot ( b . bitset . combine ( ) ) ;
} else {
throw new IllegalArgumentException ( ) ;
}
return this ;
return this ;
}
}
@Override
@Override
public CompressedBitmapBuilder xor ( Bitmap other ) {
public CompressedBitmapBuilder xor ( Bitmap other ) {
if ( isSameCompressedBitmap ( other ) ) {
bitset . xor ( ewahBitmap ( other ) ) ;
bitset . xor ( ( ( CompressedBitmap ) other ) . bitmap ) ;
} else if ( isSameCompressedBitmapBuilder ( other ) ) {
CompressedBitmapBuilder b = ( CompressedBitmapBuilder ) other ;
bitset . xor ( b . bitset . combine ( ) ) ;
} else {
throw new IllegalArgumentException ( ) ;
}
return this ;
return this ;
}
}
/** @return the fully built immutable bitmap */
/** @return the fully built immutable bitmap */
@Override
@Override
public CompressedBitmap build ( ) {
public CompressedBitmap build ( ) {
return new CompressedBitmap ( bitset . combine ( ) ) ;
return new CompressedBitmap ( bitset . combine ( ) , bitmapIndex ) ;
}
}
@Override
@Override
@ -305,14 +290,14 @@ public class BitmapIndexImpl implements BitmapIndex {
@Override
@Override
public boolean removeAllOrNone ( PackBitmapIndex index ) {
public boolean removeAllOrNone ( PackBitmapIndex index ) {
if ( ! packIndex . equals ( index ) )
if ( ! bitmapIndex . packIndex . equals ( index ) )
return false ;
return false ;
EWAHCompressedBitmap curr = bitset . combine ( )
EWAHCompressedBitmap curr = bitset . combine ( )
. xor ( ones ( indexObjectCount ) ) ;
. xor ( ones ( bitmapIndex . indexObjectCount ) ) ;
IntIterator ii = curr . intIterator ( ) ;
IntIterator ii = curr . intIterator ( ) ;
if ( ii . hasNext ( ) & & ii . next ( ) < indexObjectCount )
if ( ii . hasNext ( ) & & ii . next ( ) < bitmapIndex . indexObjectCount )
return false ;
return false ;
bitset = new ComboBitset ( curr ) ;
bitset = new ComboBitset ( curr ) ;
return true ;
return true ;
@ -320,49 +305,59 @@ public class BitmapIndexImpl implements BitmapIndex {
@Override
@Override
public BitmapIndexImpl getBitmapIndex ( ) {
public BitmapIndexImpl getBitmapIndex ( ) {
return BitmapIndexImpl . this ;
return bitmapIndex ;
}
private EWAHCompressedBitmap ewahBitmap ( Bitmap other ) {
if ( other instanceof CompressedBitmap ) {
CompressedBitmap b = ( CompressedBitmap ) other ;
if ( b . bitmapIndex ! = bitmapIndex ) {
throw new IllegalArgumentException ( ) ;
}
return b . bitmap ;
}
if ( other instanceof CompressedBitmapBuilder ) {
CompressedBitmapBuilder b = ( CompressedBitmapBuilder ) other ;
if ( b . bitmapIndex ! = bitmapIndex ) {
throw new IllegalArgumentException ( ) ;
}
return b . bitset . combine ( ) ;
}
throw new IllegalArgumentException ( ) ;
}
}
}
}
final class CompressedBitmap implements Bitmap {
static final class CompressedBitmap implements Bitmap {
final EWAHCompressedBitmap bitmap ;
final EWAHCompressedBitmap bitmap ;
final BitmapIndexImpl bitmapIndex ;
CompressedBitmap ( EWAHCompressedBitmap bitmap ) {
CompressedBitmap ( EWAHCompressedBitmap bitmap , BitmapIndexImpl bitmapIndex ) {
this . bitmap = bitmap ;
this . bitmap = bitmap ;
this . bitmapIndex = bitmapIndex ;
}
}
@Override
@Override
public CompressedBitmap or ( Bitmap other ) {
public CompressedBitmap or ( Bitmap other ) {
return new CompressedBitmap ( bitmap . or ( bitmapOf ( other ) ) ) ;
return new CompressedBitmap ( bitmap . or ( ewahBitmap ( other ) ) , bitmapIndex ) ;
}
}
@Override
@Override
public CompressedBitmap andNot ( Bitmap other ) {
public CompressedBitmap andNot ( Bitmap other ) {
return new CompressedBitmap ( bitmap . andNot ( bitmapOf ( other ) ) ) ;
return new CompressedBitmap ( bitmap . andNot ( ewahBitmap ( other ) ) , bitmapIndex ) ;
}
}
@Override
@Override
public CompressedBitmap xor ( Bitmap other ) {
public CompressedBitmap xor ( Bitmap other ) {
return new CompressedBitmap ( bitmap . xor ( bitmapOf ( other ) ) ) ;
return new CompressedBitmap ( bitmap . xor ( ewahBitmap ( other ) ) , bitmapIndex ) ;
}
private EWAHCompressedBitmap bitmapOf ( Bitmap other ) {
if ( isSameCompressedBitmap ( other ) )
return ( ( CompressedBitmap ) other ) . bitmap ;
if ( isSameCompressedBitmapBuilder ( other ) )
return ( ( CompressedBitmapBuilder ) other ) . build ( ) . bitmap ;
CompressedBitmapBuilder builder = newBitmapBuilder ( ) ;
builder . or ( other ) ;
return builder . build ( ) . bitmap ;
}
}
private final IntIterator ofObjectType ( int type ) {
private final IntIterator ofObjectType ( int type ) {
return packIndex . ofObjectType ( bitmap , type ) . intIterator ( ) ;
return bitmapIndex . packIndex . ofObjectType ( bitmap , type ) . intIterator ( ) ;
}
}
@Override
@Override
public Iterator < BitmapObject > iterator ( ) {
public Iterator < BitmapObject > iterator ( ) {
final IntIterator dynamic = bitmap . andNot ( ones ( indexObjectCount ) )
final IntIterator dynamic = bitmap . andNot ( ones ( bitmapIndex . indexObjectCount ) )
. intIterator ( ) ;
. intIterator ( ) ;
final IntIterator commits = ofObjectType ( Constants . OBJ_COMMIT ) ;
final IntIterator commits = ofObjectType ( Constants . OBJ_COMMIT ) ;
final IntIterator trees = ofObjectType ( Constants . OBJ_TREE ) ;
final IntIterator trees = ofObjectType ( Constants . OBJ_TREE ) ;
@ -399,12 +394,12 @@ public class BitmapIndexImpl implements BitmapIndex {
throw new NoSuchElementException ( ) ;
throw new NoSuchElementException ( ) ;
int position = cached . next ( ) ;
int position = cached . next ( ) ;
if ( position < indexObjectCount ) {
if ( position < bitmapIndex . indexObjectCount ) {
out . type = type ;
out . type = type ;
out . objectId = packIndex . getObject ( position ) ;
out . objectId = bitmapIndex . packIndex . getObject ( position ) ;
} else {
} else {
position - = indexObjectCount ;
position - = bitmapIndex . indexObjectCount ;
MutableEntry entry = mutableIndex . getObject ( position ) ;
MutableEntry entry = bitmapIndex . mutableIndex . getObject ( position ) ;
out . type = entry . type ;
out . type = entry . type ;
out . objectId = entry ;
out . objectId = entry ;
}
}
@ -421,8 +416,22 @@ public class BitmapIndexImpl implements BitmapIndex {
return bitmap ;
return bitmap ;
}
}
BitmapIndexImpl getPackBitmapIndex ( ) {
private EWAHCompressedBitmap ewahBitmap ( Bitmap other ) {
return BitmapIndexImpl . this ;
if ( other instanceof CompressedBitmap ) {
CompressedBitmap b = ( CompressedBitmap ) other ;
if ( b . bitmapIndex ! = bitmapIndex ) {
throw new IllegalArgumentException ( ) ;
}
return b . bitmap ;
}
if ( other instanceof CompressedBitmapBuilder ) {
CompressedBitmapBuilder b = ( CompressedBitmapBuilder ) other ;
if ( b . bitmapIndex ! = bitmapIndex ) {
throw new IllegalArgumentException ( ) ;
}
return b . bitset . combine ( ) ;
}
throw new IllegalArgumentException ( ) ;
}
}
}
}
@ -490,22 +499,6 @@ public class BitmapIndexImpl implements BitmapIndex {
}
}
}
}
boolean isSameCompressedBitmap ( Bitmap other ) {
if ( other instanceof CompressedBitmap ) {
CompressedBitmap b = ( CompressedBitmap ) other ;
return this = = b . getPackBitmapIndex ( ) ;
}
return false ;
}
boolean isSameCompressedBitmapBuilder ( Bitmap other ) {
if ( other instanceof CompressedBitmapBuilder ) {
CompressedBitmapBuilder b = ( CompressedBitmapBuilder ) other ;
return this = = b . getBitmapIndex ( ) ;
}
return false ;
}
static final EWAHCompressedBitmap ones ( int sizeInBits ) {
static final EWAHCompressedBitmap ones ( int sizeInBits ) {
EWAHCompressedBitmap mask = new EWAHCompressedBitmap ( ) ;
EWAHCompressedBitmap mask = new EWAHCompressedBitmap ( ) ;
mask . addStreamOfEmptyWords (
mask . addStreamOfEmptyWords (