You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

BitmapIndex.java 6.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  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. package org.eclipse.jgit.lib;
  44. import java.util.Iterator;
  45. import org.eclipse.jgit.internal.storage.file.PackBitmapIndex;
  46. /**
  47. * A compressed bitmap representation of the entire object graph.
  48. *
  49. * @since 3.0
  50. */
  51. public interface BitmapIndex {
  52. /**
  53. * Get the bitmap for the id. The returned bitmap is immutable and the
  54. * bitwise operations return the result of the operation in a new Bitmap.
  55. *
  56. * @param objectId
  57. * the object ID
  58. * @return the Bitmap for the objectId or null, if one does not exist.
  59. */
  60. Bitmap getBitmap(AnyObjectId objectId);
  61. /** @return a new {@code BitmapBuilder} based on the values in the index. */
  62. BitmapBuilder newBitmapBuilder();
  63. /**
  64. * A bitmap representation of ObjectIds that can be iterated to return the
  65. * underlying {@code ObjectId}s or operated on with other {@code Bitmap}s.
  66. */
  67. public interface Bitmap extends Iterable<BitmapObject> {
  68. /**
  69. * Bitwise-OR the current bitmap with the value from the other
  70. * bitmap.
  71. *
  72. * @param other
  73. * the other bitmap
  74. * @return a bitmap that is the bitwise-OR.
  75. */
  76. Bitmap or(Bitmap other);
  77. /**
  78. * Bitwise-AND-NOT the current bitmap with the value from the other
  79. * bitmap.
  80. *
  81. * @param other
  82. * the other bitmap
  83. * @return a bitmap that is the bitwise-AND-NOT.
  84. */
  85. Bitmap andNot(Bitmap other);
  86. /**
  87. * Bitwise-XOR the current bitmap with the value from the other
  88. * bitmap.
  89. *
  90. * @param other
  91. * the other bitmap
  92. * @return a bitmap that is the bitwise-XOR.
  93. */
  94. Bitmap xor(Bitmap other);
  95. /**
  96. * Returns an iterator over a set of elements of type BitmapObject. The
  97. * BitmapObject instance is reused across calls to
  98. * {@link Iterator#next()} for performance reasons.
  99. *
  100. * @return an Iterator.
  101. */
  102. Iterator<BitmapObject> iterator();
  103. }
  104. /**
  105. * A builder for a bitmap. The bitwise operations update the builder and
  106. * return a reference to the current builder.
  107. */
  108. public interface BitmapBuilder extends Bitmap {
  109. /**
  110. * Adds the id and the existing bitmap for the id, if one exists, to the
  111. * bitmap.
  112. *
  113. * @param objectId
  114. * the object ID
  115. * @param type
  116. * the Git object type. See {@link Constants}.
  117. * @return true if the value was not contained or able to be loaded.
  118. * @deprecated use {@link #or} or {@link #addObject} instead.
  119. */
  120. @Deprecated
  121. boolean add(AnyObjectId objectId, int type);
  122. /**
  123. * Whether the bitmap has the id set.
  124. *
  125. * @param objectId
  126. * the object ID
  127. * @return whether the bitmap currently contains the object ID
  128. */
  129. boolean contains(AnyObjectId objectId);
  130. /**
  131. * Adds the id to the bitmap.
  132. *
  133. * @param objectId
  134. * the object ID
  135. * @param type
  136. * the Git object type. See {@link Constants}.
  137. * @return the current builder.
  138. * @since 4.2
  139. */
  140. BitmapBuilder addObject(AnyObjectId objectId, int type);
  141. /**
  142. * Remove the id from the bitmap.
  143. *
  144. * @param objectId
  145. * the object ID
  146. */
  147. void remove(AnyObjectId objectId);
  148. /**
  149. * Bitwise-OR the current bitmap with the value from the other bitmap.
  150. *
  151. * @param other
  152. * the other bitmap
  153. * @return the current builder.
  154. */
  155. BitmapBuilder or(Bitmap other);
  156. /**
  157. * Bitwise-AND-NOT the current bitmap with the value from the other
  158. * bitmap.
  159. *
  160. * @param other
  161. * the other bitmap
  162. * @return the current builder.
  163. */
  164. BitmapBuilder andNot(Bitmap other);
  165. /**
  166. * Bitwise-XOR the current bitmap with the value from the other bitmap.
  167. *
  168. * @param other
  169. * the other bitmap
  170. * @return the current builder.
  171. */
  172. BitmapBuilder xor(Bitmap other);
  173. /** @return the fully built immutable bitmap */
  174. Bitmap build();
  175. /**
  176. * Determines if the entire bitmap index is contained in the bitmap. If
  177. * it is, the matching bits are removed from the bitmap and true is
  178. * returned. If the bitmap index is null, false is returned.
  179. *
  180. * @param bitmapIndex
  181. * the bitmap index to check if it is completely contained
  182. * inside of the current bitmap.
  183. * @return {@code true} if the bitmap index was a complete match.
  184. */
  185. boolean removeAllOrNone(PackBitmapIndex bitmapIndex);
  186. /** @return the number of elements in the bitmap. */
  187. int cardinality();
  188. /**
  189. * Get the BitmapIndex for this BitmapBuilder.
  190. *
  191. * @return the BitmapIndex for this BitmapBuilder
  192. *
  193. * @since 4.2
  194. */
  195. BitmapIndex getBitmapIndex();
  196. }
  197. }