1 /*
2 * Copyright (C) 2012, Google Inc.
3 * and other copyright owners as documented in the project's IP log.
4 *
5 * This program and the accompanying materials are made available
6 * under the terms of the Eclipse Distribution License v1.0 which
7 * accompanies this distribution, is reproduced below, and is
8 * available at http://www.eclipse.org/org/documents/edl-v10.php
9 *
10 * All rights reserved.
11 *
12 * Redistribution and use in source and binary forms, with or
13 * without modification, are permitted provided that the following
14 * conditions are met:
15 *
16 * - Redistributions of source code must retain the above copyright
17 * notice, this list of conditions and the following disclaimer.
18 *
19 * - Redistributions in binary form must reproduce the above
20 * copyright notice, this list of conditions and the following
21 * disclaimer in the documentation and/or other materials provided
22 * with the distribution.
23 *
24 * - Neither the name of the Eclipse Foundation, Inc. nor the
25 * names of its contributors may be used to endorse or promote
26 * products derived from this software without specific prior
27 * written permission.
28 *
29 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
30 * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
31 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
32 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
33 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
34 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
35 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
36 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
37 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
38 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
40 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
41 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
42 */
43
44 package org.eclipse.jgit.lib;
45
46 import java.util.Iterator;
47
48 import org.eclipse.jgit.internal.storage.file.PackBitmapIndex;
49
50 /**
51 * A compressed bitmap representation of the entire object graph.
52 *
53 * @since 3.0
54 */
55 public interface BitmapIndex {
56 /**
57 * Get the bitmap for the id. The returned bitmap is immutable and the
58 * bitwise operations return the result of the operation in a new Bitmap.
59 *
60 * @param objectId
61 * the object ID
62 * @return the Bitmap for the objectId or null, if one does not exist.
63 */
64 Bitmap getBitmap(AnyObjectId objectId);
65
66 /**
67 * Create a new {@code BitmapBuilder} based on the values in the index.
68 *
69 * @return a new {@code BitmapBuilder} based on the values in the index.
70 */
71 BitmapBuilder newBitmapBuilder();
72
73 /**
74 * A bitmap representation of ObjectIds that can be iterated to return the
75 * underlying {@code ObjectId}s or operated on with other {@code Bitmap}s.
76 */
77 public interface Bitmap extends Iterable<BitmapObject> {
78 /**
79 * Bitwise-OR the current bitmap with the value from the other
80 * bitmap.
81 *
82 * @param other
83 * the other bitmap
84 * @return a bitmap that is the bitwise-OR.
85 */
86 Bitmap or(Bitmap other);
87
88 /**
89 * Bitwise-AND-NOT the current bitmap with the value from the other
90 * bitmap.
91 *
92 * @param other
93 * the other bitmap
94 * @return a bitmap that is the bitwise-AND-NOT.
95 */
96 Bitmap andNot(Bitmap other);
97
98 /**
99 * Bitwise-XOR the current bitmap with the value from the other
100 * bitmap.
101 *
102 * @param other
103 * the other bitmap
104 * @return a bitmap that is the bitwise-XOR.
105 */
106 Bitmap xor(Bitmap other);
107
108 /**
109 * Returns an iterator over a set of elements of type BitmapObject. The
110 * BitmapObject instance is reused across calls to
111 * {@link Iterator#next()} for performance reasons.
112 *
113 * @return an Iterator.
114 */
115 @Override
116 Iterator<BitmapObject> iterator();
117 }
118
119 /**
120 * A builder for a bitmap. The bitwise operations update the builder and
121 * return a reference to the current builder.
122 */
123 public interface BitmapBuilder extends Bitmap {
124
125 /**
126 * Whether the bitmap has the id set.
127 *
128 * @param objectId
129 * the object ID
130 * @return whether the bitmap currently contains the object ID
131 */
132 boolean contains(AnyObjectId objectId);
133
134 /**
135 * Adds the id to the bitmap.
136 *
137 * @param objectId
138 * the object ID
139 * @param type
140 * the Git object type. See {@link Constants}.
141 * @return the current builder.
142 * @since 4.2
143 */
144 BitmapBuilder addObject(AnyObjectId objectId, int type);
145
146 /**
147 * Remove the id from the bitmap.
148 *
149 * @param objectId
150 * the object ID
151 */
152 void remove(AnyObjectId objectId);
153
154 /**
155 * Bitwise-OR the current bitmap with the value from the other bitmap.
156 *
157 * @param other
158 * the other bitmap
159 * @return the current builder.
160 */
161 @Override
162 BitmapBuilder or(Bitmap other);
163
164 /**
165 * Bitwise-AND-NOT the current bitmap with the value from the other
166 * bitmap.
167 *
168 * @param other
169 * the other bitmap
170 * @return the current builder.
171 */
172 @Override
173 BitmapBuilder andNot(Bitmap other);
174
175 /**
176 * Bitwise-XOR the current bitmap with the value from the other bitmap.
177 *
178 * @param other
179 * the other bitmap
180 * @return the current builder.
181 */
182 @Override
183 BitmapBuilder xor(Bitmap other);
184
185 /** @return the fully built immutable bitmap */
186 Bitmap build();
187
188 /**
189 * Determines if the entire bitmap index is contained in the bitmap. If
190 * it is, the matching bits are removed from the bitmap and true is
191 * returned. If the bitmap index is null, false is returned.
192 *
193 * @param bitmapIndex
194 * the bitmap index to check if it is completely contained
195 * inside of the current bitmap.
196 * @return {@code true} if the bitmap index was a complete match.
197 */
198 boolean removeAllOrNone(PackBitmapIndex bitmapIndex);
199
200 /** @return the number of elements in the bitmap. */
201 int cardinality();
202
203 /**
204 * Get the BitmapIndex for this BitmapBuilder.
205 *
206 * @return the BitmapIndex for this BitmapBuilder
207 *
208 * @since 4.2
209 */
210 BitmapIndex getBitmapIndex();
211 }
212 }