diff options
author | Colby Ranger <cranger@google.com> | 2012-08-28 09:08:20 -0700 |
---|---|---|
committer | Colby Ranger <cranger@google.com> | 2013-03-05 11:09:44 -0800 |
commit | 3b325917a5c928caadd88a0ec718b1632f088fd5 (patch) | |
tree | 07608fe74199d7ffec96524aa89299deb020155c /org.eclipse.jgit/src/org/eclipse/jgit/lib/BitmapIndex.java | |
parent | 234b4e0432bc376964fe753eeb1119ef08cefe49 (diff) | |
download | jgit-3b325917a5c928caadd88a0ec718b1632f088fd5.tar.gz jgit-3b325917a5c928caadd88a0ec718b1632f088fd5.zip |
Added read/write support for pack bitmap index.
A pack bitmap index is an additional index of compressed
bitmaps of the object graph. Furthermore, a logical API of the index
functionality is included, as it is expected to be used by the
PackWriter.
Compressed bitmaps are created using the javaewah library, which is a
word-aligned compressed variant of the Java bitset class based on
run-length encoding. The library only works with positive integer
values. Thus, the maximum number of ObjectIds in a pack file that
this index can currently support is limited to Integer.MAX_VALUE.
Every ObjectId is given an integer mapping. The integer is the
position of the ObjectId in the complete ObjectId list, sorted
by offset, for the pack file. That integer is what the bitmaps
use to reference the ObjectId. Currently, the new index format can
only be used with pack files that contain a complete closure of the
object graph e.g. the result of a garbage collection.
The index file includes four bitmaps for the Git object types i.e.
commits, trees, blobs, and tags. In addition, a collection of
bitmaps keyed by an ObjectId is also included. The bitmap for each entry
in the collection represents the full closure of ObjectIds reachable
from the keyed ObjectId (including the keyed ObjectId itself). The
bitmaps are further compressed by XORing the current bitmaps against
prior bitmaps in the index, and selecting the smallest representation.
The XOR'd bitmap and offset from the current entry to the position
of the bitmap to XOR against is the actual representation of the entry
in the index file. Each entry contains one byte, which is currently
used to note whether the bitmap should be blindly reused.
Change-Id: Id328724bf6b4c8366a088233098c18643edcf40f
Diffstat (limited to 'org.eclipse.jgit/src/org/eclipse/jgit/lib/BitmapIndex.java')
-rw-r--r-- | org.eclipse.jgit/src/org/eclipse/jgit/lib/BitmapIndex.java | 190 |
1 files changed, 190 insertions, 0 deletions
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/lib/BitmapIndex.java b/org.eclipse.jgit/src/org/eclipse/jgit/lib/BitmapIndex.java new file mode 100644 index 0000000000..0905980dcf --- /dev/null +++ b/org.eclipse.jgit/src/org/eclipse/jgit/lib/BitmapIndex.java @@ -0,0 +1,190 @@ +/* + * Copyright (C) 2012, Google Inc. + * and other copyright owners as documented in the project's IP log. + * + * This program and the accompanying materials are made available + * under the terms of the Eclipse Distribution License v1.0 which + * accompanies this distribution, is reproduced below, and is + * available at http://www.eclipse.org/org/documents/edl-v10.php + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or + * without modification, are permitted provided that the following + * conditions are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * + * - Neither the name of the Eclipse Foundation, Inc. nor the + * names of its contributors may be used to endorse or promote + * products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND + * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package org.eclipse.jgit.lib; + +import java.util.Iterator; + +import org.eclipse.jgit.storage.file.PackBitmapIndex; + +/** A compressed bitmap representation of the entire object graph. */ +public interface BitmapIndex { + /** + * Get the bitmap for the id. The returned bitmap is immutable and the + * bitwise operations return the result of the operation in a new Bitmap. + * + * @param objectId + * the object ID + * @return the Bitmap for the objectId or null, if one does not exist. + */ + Bitmap getBitmap(AnyObjectId objectId); + + /** @return a new {@code BitmapBuilder} based on the values in the index. */ + BitmapBuilder newBitmapBuilder(); + + /** + * A bitmap representation of ObjectIds that can be iterated to return the + * underlying {@code ObjectId}s or operated on with other {@code Bitmap}s. + */ + public interface Bitmap extends Iterable<BitmapObject> { + /** + * Bitwise-OR the current bitmap with the value from the other + * bitmap. + * + * @param other + * the other bitmap + * @return a bitmap that is the bitwise-OR. + */ + Bitmap or(Bitmap other); + + /** + * Bitwise-AND-NOT the current bitmap with the value from the other + * bitmap. + * + * @param other + * the other bitmap + * @return a bitmap that is the bitwise-AND-NOT. + */ + Bitmap andNot(Bitmap other); + + /** + * Bitwise-XOR the current bitmap with the value from the other + * bitmap. + * + * @param other + * the other bitmap + * @return a bitmap that is the bitwise-XOR. + */ + Bitmap xor(Bitmap other); + + /** + * Returns an iterator over a set of elements of type BitmapObject. The + * BitmapObject instance is reused across calls to + * {@link Iterator#next()} for performance reasons. + * + * @return an Iterator. + */ + Iterator<BitmapObject> iterator(); + } + + /** + * A builder for a bitmap. The bitwise operations update the builder and + * return a reference to the current builder. + */ + public interface BitmapBuilder extends Bitmap { + /** + * Adds the id and the existing bitmap for the id, if one exists, to the + * bitmap. + * + * @param objectId + * the object ID + * @param type + * the Git object type. See {@link Constants}. + * @return true if the value was not contained or able to be loaded. + */ + boolean add(AnyObjectId objectId, int type); + + /** + * Whether the bitmap has the id set. + * + * @param objectId + * the object ID + * @return whether the bitmap currently contains the object ID + */ + boolean contains(AnyObjectId objectId); + + /** + * Remove the id from the bitmap. + * + * @param objectId + * the object ID + */ + void remove(AnyObjectId objectId); + + /** + * Bitwise-OR the current bitmap with the value from the other bitmap. + * + * @param other + * the other bitmap + * @return the current builder. + */ + BitmapBuilder or(Bitmap other); + + /** + * Bitwise-AND-NOT the current bitmap with the value from the other + * bitmap. + * + * @param other + * the other bitmap + * @return the current builder. + */ + BitmapBuilder andNot(Bitmap other); + + /** + * Bitwise-XOR the current bitmap with the value from the other bitmap. + * + * @param other + * the other bitmap + * @return the current builder. + */ + BitmapBuilder xor(Bitmap other); + + /** @return the fully built immutable bitmap */ + Bitmap build(); + + /** + * Determines if the entire bitmap index is contained in the bitmap. If + * it is, the matching bits are removed from the bitmap and true is + * returned. If the bitmap index is null, false is returned. + * + * @param bitmapIndex + * the bitmap index to check if it is completely contained + * inside of the current bitmap. + * @return {@code true} if the bitmap index was a complete match. + */ + boolean removeAllOrNone(PackBitmapIndex bitmapIndex); + + /** @return the number of elements in the bitmap. */ + int cardinality(); + } +} |