1
2
3
4
5
6
7
8
9
10
11 package org.eclipse.jgit.internal.storage.file;
12
13 import org.eclipse.jgit.lib.AnyObjectId;
14 import org.eclipse.jgit.lib.ObjectIdOwnerMap;
15
16 import com.googlecode.javaewah.EWAHCompressedBitmap;
17
18
19
20
21 abstract class BasePackBitmapIndex extends PackBitmapIndex {
22 private final ObjectIdOwnerMap<StoredBitmap> bitmaps;
23
24 BasePackBitmapIndex(ObjectIdOwnerMap<StoredBitmap> bitmaps) {
25 this.bitmaps = bitmaps;
26 }
27
28
29 @Override
30 public EWAHCompressedBitmap getBitmap(AnyObjectId objectId) {
31 StoredBitmap sb = bitmaps.get(objectId);
32 return sb != null ? sb.getBitmap() : null;
33 }
34
35 ObjectIdOwnerMap<StoredBitmap> getBitmaps() {
36 return bitmaps;
37 }
38
39
40
41
42
43 static final class StoredBitmap extends ObjectIdOwnerMap.Entry {
44 private volatile Object bitmapContainer;
45 private final int flags;
46
47 StoredBitmap(AnyObjectId objectId, EWAHCompressedBitmap bitmap,
48 StoredBitmap xorBitmap, int flags) {
49 super(objectId);
50 this.bitmapContainer = xorBitmap == null
51 ? bitmap
52 : new XorCompressedBitmap(bitmap, xorBitmap);
53 this.flags = flags;
54 }
55
56
57
58
59
60
61 EWAHCompressedBitmap getBitmap() {
62
63 Object r = bitmapContainer;
64 if (r instanceof EWAHCompressedBitmap)
65 return (EWAHCompressedBitmap) r;
66
67
68 XorCompressedBitmap xb = (XorCompressedBitmap) r;
69 EWAHCompressedBitmap out = xb.bitmap;
70 for (;;) {
71 r = xb.xorBitmap.bitmapContainer;
72 if (r instanceof EWAHCompressedBitmap) {
73 out = out.xor((EWAHCompressedBitmap) r);
74 out.trim();
75 bitmapContainer = out;
76 return out;
77 }
78 xb = (XorCompressedBitmap) r;
79 out = out.xor(xb.bitmap);
80 }
81 }
82
83
84 int getFlags() {
85 return flags;
86 }
87 }
88
89 private static final class XorCompressedBitmap {
90 final EWAHCompressedBitmap bitmap;
91 final StoredBitmap xorBitmap;
92
93 XorCompressedBitmap(EWAHCompressedBitmap b, StoredBitmap xb) {
94 bitmap = b;
95 xorBitmap = xb;
96 }
97 }
98 }