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 4.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. /*
  2. * Copyright (C) 2012, Google Inc. and others
  3. *
  4. * This program and the accompanying materials are made available under the
  5. * terms of the Eclipse Distribution License v. 1.0 which is available at
  6. * https://www.eclipse.org/org/documents/edl-v10.php.
  7. *
  8. * SPDX-License-Identifier: BSD-3-Clause
  9. */
  10. package org.eclipse.jgit.lib;
  11. import java.util.Iterator;
  12. import org.eclipse.jgit.internal.storage.file.PackBitmapIndex;
  13. /**
  14. * A compressed bitmap representation of the entire object graph.
  15. *
  16. * @since 3.0
  17. */
  18. public interface BitmapIndex {
  19. /**
  20. * Get the bitmap for the id. The returned bitmap is immutable and the
  21. * bitwise operations return the result of the operation in a new Bitmap.
  22. *
  23. * @param objectId
  24. * the object ID
  25. * @return the Bitmap for the objectId or null, if one does not exist.
  26. */
  27. Bitmap getBitmap(AnyObjectId objectId);
  28. /**
  29. * Create a new {@code BitmapBuilder} based on the values in the index.
  30. *
  31. * @return a new {@code BitmapBuilder} based on the values in the index.
  32. */
  33. BitmapBuilder newBitmapBuilder();
  34. /**
  35. * A bitmap representation of ObjectIds that can be iterated to return the
  36. * underlying {@code ObjectId}s or operated on with other {@code Bitmap}s.
  37. */
  38. public interface Bitmap extends Iterable<BitmapObject> {
  39. /**
  40. * Bitwise-OR the current bitmap with the value from the other
  41. * bitmap.
  42. *
  43. * @param other
  44. * the other bitmap
  45. * @return a bitmap that is the bitwise-OR.
  46. */
  47. Bitmap or(Bitmap other);
  48. /**
  49. * Bitwise-AND-NOT the current bitmap with the value from the other
  50. * bitmap.
  51. *
  52. * @param other
  53. * the other bitmap
  54. * @return a bitmap that is the bitwise-AND-NOT.
  55. */
  56. Bitmap andNot(Bitmap other);
  57. /**
  58. * Bitwise-XOR the current bitmap with the value from the other
  59. * bitmap.
  60. *
  61. * @param other
  62. * the other bitmap
  63. * @return a bitmap that is the bitwise-XOR.
  64. */
  65. Bitmap xor(Bitmap other);
  66. /**
  67. * Returns an iterator over a set of elements of type BitmapObject. The
  68. * BitmapObject instance is reused across calls to
  69. * {@link Iterator#next()} for performance reasons.
  70. *
  71. * @return an Iterator.
  72. */
  73. @Override
  74. Iterator<BitmapObject> iterator();
  75. }
  76. /**
  77. * A builder for a bitmap. The bitwise operations update the builder and
  78. * return a reference to the current builder.
  79. */
  80. public interface BitmapBuilder extends Bitmap {
  81. /**
  82. * Whether the bitmap has the id set.
  83. *
  84. * @param objectId
  85. * the object ID
  86. * @return whether the bitmap currently contains the object ID
  87. */
  88. boolean contains(AnyObjectId objectId);
  89. /**
  90. * Adds the id to the bitmap.
  91. *
  92. * @param objectId
  93. * the object ID
  94. * @param type
  95. * the Git object type. See {@link Constants}.
  96. * @return the current builder.
  97. * @since 4.2
  98. */
  99. BitmapBuilder addObject(AnyObjectId objectId, int type);
  100. /**
  101. * Remove the id from the bitmap.
  102. *
  103. * @param objectId
  104. * the object ID
  105. */
  106. void remove(AnyObjectId objectId);
  107. /**
  108. * Bitwise-OR the current bitmap with the value from the other bitmap.
  109. *
  110. * @param other
  111. * the other bitmap
  112. * @return the current builder.
  113. */
  114. @Override
  115. BitmapBuilder or(Bitmap other);
  116. /**
  117. * Bitwise-AND-NOT the current bitmap with the value from the other
  118. * bitmap.
  119. *
  120. * @param other
  121. * the other bitmap
  122. * @return the current builder.
  123. */
  124. @Override
  125. BitmapBuilder andNot(Bitmap other);
  126. /**
  127. * Bitwise-XOR the current bitmap with the value from the other bitmap.
  128. *
  129. * @param other
  130. * the other bitmap
  131. * @return the current builder.
  132. */
  133. @Override
  134. BitmapBuilder xor(Bitmap other);
  135. /** @return the fully built immutable bitmap */
  136. Bitmap build();
  137. /**
  138. * Determines if the entire bitmap index is contained in the bitmap. If
  139. * it is, the matching bits are removed from the bitmap and true is
  140. * returned. If the bitmap index is null, false is returned.
  141. *
  142. * @param bitmapIndex
  143. * the bitmap index to check if it is completely contained
  144. * inside of the current bitmap.
  145. * @return {@code true} if the bitmap index was a complete match.
  146. */
  147. boolean removeAllOrNone(PackBitmapIndex bitmapIndex);
  148. /** @return the number of elements in the bitmap. */
  149. int cardinality();
  150. /**
  151. * Get the BitmapIndex for this BitmapBuilder.
  152. *
  153. * @return the BitmapIndex for this BitmapBuilder
  154. *
  155. * @since 4.2
  156. */
  157. BitmapIndex getBitmapIndex();
  158. }
  159. }