1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33 /
34
35
36
37
38
39
40
41
42
43
44 private byte[] smapVector;
45
46 public BucketObjectByte(){
47 super(-1);
48 smapVector = null;
49 }
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65 public BucketObjectByte(byte[] smapVector,
66 long id) {
67 this(smapVector,id,null);
68 }
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84 public BucketObjectByte(byte[] smapVector,
85 long id, O object) {
86 super(id, object);
87 this.smapVector = smapVector;
88 }
89
90 public boolean equals(Object other){
91 BucketObjectByte<O> another = (BucketObjectByte<O>) other;
92 boolean pivotVectorsEqual = comparePivotVectors(smapVector, another.smapVector);
93 boolean idsEqual = getId() == another.getId();
94 boolean objectsEqual = getObject().equals(another.getObject());
95 return pivotVectorsEqual && idsEqual && objectsEqual;
96 }
97
98 private boolean comparePivotVectors(byte[] a, byte[] b){
99 int la = 0;
100 int lb = 0;
101 if(a != null){
102 la = a.length;
103 }
104 if(b != null){
105 lb = b.length;
106 }
107 if(la == 0 && lb == 0){
108 return true;
109 }
110
111 return Arrays.equals(a,b);
112 }
113
114
115
116
117
118
119
120 public byte lInf(BucketObjectByte b){
121 return lInf(smapVector, b.getSmapVector());
122 }
123
124 private int pivotCount(){
125 if(smapVector == null){
126 return 0;
127 }else{
128 return smapVector.length;
129 }
130 }
131
132
133 public static byte lInf(byte[] smapVector, byte[] other){
134 int cx = 0;
135 byte max = 0;
136 byte t;
137
138 if(smapVector == null || smapVector.length == 0){
139 assert other == null || other.length == 0;
140 return max;
141 }
142
143 while (cx < smapVector.length) {
144 t = (byte) Math.abs(smapVector[cx] - other[cx]);
145 if (t > max) {
146 max = t;
147 }
148 cx++;
149 }
150 return max;
151 }
152
153
154 public static byte[] convertTuple(OBByte object, OBByte[] pivots) throws OBException{
155 int i = 0;
156 byte[] smapVector = new byte[pivots.length];
157 while (i < pivots.length) {
158 byte distance = pivots[i].distance(object);
159 smapVector[i] = distance;
160 i++;
161 }
162 return smapVector;
163 }
164
165
166
167
168
169 public byte[] getSmapVector() {
170 return smapVector;
171 }
172
173
174
175
176
177 public void write(ByteBuffer out){
178 if(getSmapVector() != null){
179 for (byte j : getSmapVector()) {
180 out.put(j);
181 }
182 }
183 out.putLong(getId());
184 }
185
186
187
188
189
190
191 public void read(ByteBuffer in, int pivots){
192 if(pivots != 0){
193 this.smapVector = new byte[pivots];
194 int i = 0;
195 while(i < pivots){
196 smapVector[i] = in.get();
197 i++;
198 }
199 }
200 smapVector = null;
201 super.setId(in.getLong());
202 }
203
204
205
206
207
208
209 public void setSmapVector(byte[] smapVector) {
210 this.smapVector = smapVector;
211 }
212
213 public int getPivotSize(){
214 if(smapVector == null){
215 return 0;
216 }else{
217 return smapVector.length;
218 }
219 }
220
221
222
223
224 @Override
225 public int compareTo(BucketObjectByte o) {
226 int i = 0;
227 assert smapVector.length == o.smapVector.length;
228 while(i < smapVector.length){
229 int res = compareDim(smapVector[i], o.smapVector[i]);
230 if(res != 0){
231 return res;
232 }
233 i++;
234 }
235
236 return 0;
237 }
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255 private final int compareDim(byte a, byte b){
256 if( a < b){
257 return -1;
258 }else if( a > b){
259 return 1;
260 }else{
261 return 0;
262 }
263 }
264
265 public String toString(){
266 return Arrays.toString(smapVector);
267 }
268 /
269
270
271
272
273