CodecSearchTree.java.html
32.5 KB
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml" lang="en"><head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8"/><link rel="stylesheet" href="../jacoco-resources/report.css" type="text/css"/><link rel="shortcut icon" href="../jacoco-resources/report.gif" type="image/gif"/><title>CodecSearchTree.java</title><link rel="stylesheet" href="../jacoco-resources/prettify.css" type="text/css"/><script type="text/javascript" src="../jacoco-resources/prettify.js"></script></head><body onload="window['PR_TAB_WIDTH']=4;prettyPrint()"><div class="breadcrumb" id="breadcrumb"><span class="info"><a href="../jacoco-sessions.html" class="el_session">Sessions</a></span><a href="../index.html" class="el_report">MTAS</a> > <a href="index.source.html" class="el_package">mtas.codec.util</a> > <span class="el_source">CodecSearchTree.java</span></div><h1>CodecSearchTree.java</h1><pre class="source lang-java linenums">package mtas.codec.util;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicLong;
import mtas.codec.tree.IntervalTree;
import mtas.codec.tree.IntervalTreeNode;
import mtas.codec.tree.MtasTree;
import org.apache.lucene.store.IndexInput;
/**
* The Class CodecSearchTree.
*/
<span class="nc" id="L16">public class CodecSearchTree {</span>
/**
* Advance mtas tree.
*
* @param position the position
* @param in the in
* @param ref the ref
* @param objectRefApproxOffset the object ref approx offset
* @return the array list
* @throws IOException Signals that an I/O exception has occurred.
*/
public static ArrayList<MtasTreeHit<?>> advanceMtasTree(int position,
IndexInput in, long ref, long objectRefApproxOffset) throws IOException {
<span class="fc" id="L30"> ArrayList<MtasTreeHit<?>> list = new ArrayList<MtasTreeHit<?>>();</span>
<span class="fc" id="L31"> ArrayList<MtasTreeItem> checkList = new ArrayList<MtasTreeItem>();</span>
<span class="fc" id="L32"> AtomicBoolean isSinglePoint = new AtomicBoolean(false);</span>
<span class="fc" id="L33"> AtomicBoolean isStoreAdditonalId = new AtomicBoolean(false);</span>
<span class="fc" id="L34"> AtomicLong nodeRefApproxOffset = new AtomicLong(-1);</span>
<span class="fc" id="L35"> checkList.add(getMtasTreeItem(ref, isSinglePoint, isStoreAdditonalId,</span>
nodeRefApproxOffset, in, objectRefApproxOffset));
<span class="fc" id="L37"> ArrayList<Long> history = new ArrayList<Long>();</span>
do {
<span class="fc" id="L39"> MtasTreeItem checkItem = checkList.remove(checkList.size() - 1);</span>
<span class="fc" id="L40"> advanceMtasTree(checkItem, position, in, isSinglePoint,</span>
isStoreAdditonalId, objectRefApproxOffset, list, nodeRefApproxOffset,
checkList);
<span class="fc" id="L43"> history.add(checkItem.ref);</span>
<span class="pc bpc" id="L44" title="1 of 2 branches missed."> if (history.size() > 1000) {</span>
<span class="nc" id="L45"> throw new IOException(</span>
"ADVANCE " + position + " " + checkList + "\n" + history);
}
<span class="fc bfc" id="L48" title="All 2 branches covered."> } while (checkList.size() > 0);</span>
<span class="fc" id="L49"> return list;</span>
}
/**
* Advance mtas tree.
*
* @param treeItem the tree item
* @param position the position
* @param in the in
* @param isSinglePoint the is single point
* @param isStoreAdditionalId the is store additional id
* @param objectRefApproxOffset the object ref approx offset
* @param list the list
* @param nodeRefApproxOffset the node ref approx offset
* @param checkList the check list
* @throws IOException Signals that an I/O exception has occurred.
*/
private static void advanceMtasTree(MtasTreeItem treeItem, int position,
IndexInput in, AtomicBoolean isSinglePoint,
AtomicBoolean isStoreAdditionalId, long objectRefApproxOffset,
ArrayList<MtasTreeHit<?>> list, AtomicLong nodeRefApproxOffset,
ArrayList<MtasTreeItem> checkList) throws IOException {
<span class="fc bfc" id="L71" title="All 2 branches covered."> if (position <= treeItem.max) {</span>
// check current node
<span class="fc bfc" id="L73" title="All 2 branches covered."> if (position <= treeItem.left) {</span>
<span class="fc bfc" id="L74" title="All 2 branches covered."> if (list.size() > 0) {</span>
<span class="pc bpc" id="L75" title="1 of 2 branches missed."> if (list.get(0).startPosition > treeItem.left) {</span>
<span class="fc" id="L76"> list.clear();</span>
}
}
<span class="fc bfc" id="L79" title="All 2 branches covered."> for (int i = 0; i < treeItem.objectRefs.length; i++) {</span>
<span class="pc bpc" id="L80" title="2 of 4 branches missed."> list.add(new MtasTreeHit<>(treeItem.left, treeItem.right,</span>
treeItem.objectRefs[i],
treeItem.additionalIds == null ? 0 : treeItem.additionalIds[i],
treeItem.additionalRefs == null ? 0
: treeItem.additionalRefs[i]));
}
// check leftChild
<span class="fc bfc" id="L87" title="All 2 branches covered."> if (!treeItem.leftChild.equals(treeItem.ref)) {</span>
<span class="fc" id="L88"> MtasTreeItem treeItemLeft = getMtasTreeItem(treeItem.leftChild,</span>
isSinglePoint, isStoreAdditionalId, nodeRefApproxOffset, in,
objectRefApproxOffset);
<span class="fc bfc" id="L91" title="All 2 branches covered."> if (position <= treeItemLeft.max) {</span>
<span class="fc" id="L92"> checkList.add(treeItemLeft);</span>
}
<span class="fc" id="L94"> }</span>
} else {
// check right
<span class="pc bpc" id="L97" title="1 of 2 branches missed."> if (position <= treeItem.max) {</span>
<span class="pc bpc" id="L98" title="1 of 2 branches missed."> if (!treeItem.rightChild.equals(treeItem.ref)) {</span>
<span class="fc" id="L99"> MtasTreeItem treeItemRight = getMtasTreeItem(treeItem.rightChild,</span>
isSinglePoint, isStoreAdditionalId, nodeRefApproxOffset, in,
objectRefApproxOffset);
<span class="pc bpc" id="L102" title="1 of 2 branches missed."> if (position <= treeItemRight.max) {</span>
<span class="fc" id="L103"> checkList.add(treeItemRight);</span>
}
}
}
}
}
<span class="fc" id="L109"> }</span>
/**
* Search mtas tree.
*
* @param position the position
* @param in the in
* @param ref the ref
* @param objectRefApproxOffset the object ref approx offset
* @return the array list
* @throws IOException Signals that an I/O exception has occurred.
*/
public static ArrayList<MtasTreeHit<?>> searchMtasTree(int position,
IndexInput in, long ref, long objectRefApproxOffset) throws IOException {
<span class="fc" id="L123"> return searchMtasTree(position, position, in, ref, objectRefApproxOffset);</span>
}
/**
* Search mtas tree.
*
* @param startPosition the start position
* @param endPosition the end position
* @param in the in
* @param ref the ref
* @param objectRefApproxOffset the object ref approx offset
* @return the array list
* @throws IOException Signals that an I/O exception has occurred.
*/
public static ArrayList<MtasTreeHit<?>> searchMtasTree(int startPosition,
int endPosition, IndexInput in, long ref, long objectRefApproxOffset)
throws IOException {
<span class="fc" id="L140"> int boundary = 1000 + 10 * (endPosition - startPosition);</span>
<span class="fc" id="L141"> ArrayList<MtasTreeHit<?>> list = new ArrayList<MtasTreeHit<?>>();</span>
<span class="fc" id="L142"> ArrayList<MtasTreeItem> checkList = new ArrayList<MtasTreeItem>();</span>
<span class="fc" id="L143"> AtomicBoolean isSinglePoint = new AtomicBoolean(false);</span>
<span class="fc" id="L144"> AtomicBoolean isStoreAdditionalId = new AtomicBoolean(false);</span>
<span class="fc" id="L145"> AtomicLong nodeRefApproxOffset = new AtomicLong(-1);</span>
<span class="fc" id="L146"> checkList.add(getMtasTreeItem(ref, isSinglePoint, isStoreAdditionalId,</span>
nodeRefApproxOffset, in, objectRefApproxOffset));
<span class="fc" id="L148"> ArrayList<Long> history = new ArrayList<Long>();</span>
do {
<span class="fc" id="L150"> MtasTreeItem checkItem = checkList.remove(checkList.size() - 1); </span>
<span class="fc" id="L151"> searchMtasTree(checkItem, startPosition, endPosition, in, isSinglePoint,</span>
isStoreAdditionalId, objectRefApproxOffset, list, nodeRefApproxOffset,
checkList);
<span class="fc" id="L154"> history.add(checkItem.ref);</span>
<span class="pc bpc" id="L155" title="1 of 2 branches missed."> if (history.size() > boundary) {</span>
<span class="nc" id="L156"> throw new IOException("Too many items collected from tree");</span>
}
<span class="fc bfc" id="L158" title="All 2 branches covered."> } while (checkList.size() > 0);</span>
<span class="fc" id="L159"> return list;</span>
}
/**
* Search mtas tree.
*
* @param treeItem the tree item
* @param startPosition the start position
* @param endPosition the end position
* @param in the in
* @param isSinglePoint the is single point
* @param isStoreAdditionalId the is store additional id
* @param objectRefApproxOffset the object ref approx offset
* @param list the list
* @param nodeRefApproxOffset the node ref approx offset
* @param checkList the check list
* @throws IOException Signals that an I/O exception has occurred.
*/
private static void searchMtasTree(MtasTreeItem treeItem, int startPosition,
int endPosition, IndexInput in, AtomicBoolean isSinglePoint,
AtomicBoolean isStoreAdditionalId, long objectRefApproxOffset,
ArrayList<MtasTreeHit<?>> list, AtomicLong nodeRefApproxOffset,
ArrayList<MtasTreeItem> checkList) throws IOException {
<span class="pc bpc" id="L182" title="1 of 2 branches missed."> if (startPosition <= treeItem.max) { </span>
// match current node
<span class="fc bfc" id="L184" title="All 4 branches covered."> if ((endPosition >= treeItem.left) && (startPosition <= treeItem.right)) {</span>
<span class="fc bfc" id="L185" title="All 2 branches covered."> for (int i = 0; i < treeItem.objectRefs.length; i++) {</span>
<span class="pc bpc" id="L186" title="2 of 4 branches missed."> list.add(new MtasTreeHit<>(treeItem.left, treeItem.right,</span>
treeItem.objectRefs[i],
treeItem.additionalIds == null ? 0 : treeItem.additionalIds[i],
treeItem.additionalRefs == null ? 0
: treeItem.additionalRefs[i]));
}
}
// check leftChild
<span class="fc bfc" id="L194" title="All 2 branches covered."> if (!treeItem.leftChild.equals(treeItem.ref)) {</span>
<span class="fc" id="L195"> MtasTreeItem treeItemLeft = getMtasTreeItem(treeItem.leftChild,</span>
isSinglePoint, isStoreAdditionalId, nodeRefApproxOffset, in,
objectRefApproxOffset);
<span class="fc bfc" id="L198" title="All 2 branches covered."> if (treeItemLeft.max >= startPosition) {</span>
<span class="fc" id="L199"> checkList.add(treeItemLeft);</span>
}
}
// check rightChild
<span class="fc bfc" id="L203" title="All 2 branches covered."> if (treeItem.left <= endPosition) {</span>
<span class="fc bfc" id="L204" title="All 2 branches covered."> if (!treeItem.rightChild.equals(treeItem.ref)) {</span>
<span class="fc" id="L205"> MtasTreeItem treeItemRight = getMtasTreeItem(treeItem.rightChild,</span>
isSinglePoint, isStoreAdditionalId, nodeRefApproxOffset, in,
objectRefApproxOffset);
<span class="pc bpc" id="L208" title="3 of 4 branches missed."> if ((treeItemRight.left >= endPosition)</span>
|| (treeItemRight.max >= startPosition)) {
<span class="fc" id="L210"> checkList.add(treeItemRight);</span>
}
}
}
}
<span class="fc" id="L215"> }</span>
/**
* Gets the mtas tree item.
*
* @param ref the ref
* @param isSinglePoint the is single point
* @param isStoreAdditionalIdAndRef the is store additional id and ref
* @param nodeRefApproxOffset the node ref approx offset
* @param in the in
* @param objectRefApproxOffset the object ref approx offset
* @return the mtas tree item
* @throws IOException Signals that an I/O exception has occurred.
*/
private static MtasTreeItem getMtasTreeItem(Long ref,
AtomicBoolean isSinglePoint, AtomicBoolean isStoreAdditionalIdAndRef,
AtomicLong nodeRefApproxOffset, IndexInput in, long objectRefApproxOffset)
throws IOException {
try {
<span class="fc" id="L234"> Boolean isRoot = false;</span>
<span class="fc bfc" id="L235" title="All 2 branches covered."> if (nodeRefApproxOffset.get() < 0) {</span>
<span class="fc" id="L236"> isRoot = true;</span>
}
<span class="fc" id="L238"> in.seek(ref);</span>
<span class="fc bfc" id="L239" title="All 2 branches covered."> if (isRoot) {</span>
<span class="fc" id="L240"> nodeRefApproxOffset.set(in.readVLong());</span>
<span class="fc" id="L241"> Byte flag = in.readByte();</span>
<span class="fc bfc" id="L242" title="All 2 branches covered."> if ((flag</span>
& MtasTree.SINGLE_POSITION_TREE) == MtasTree.SINGLE_POSITION_TREE) {
<span class="fc" id="L244"> isSinglePoint.set(true);</span>
}
<span class="fc bfc" id="L246" title="All 2 branches covered."> if ((flag</span>
& MtasTree.STORE_ADDITIONAL_ID) == MtasTree.STORE_ADDITIONAL_ID) {
<span class="fc" id="L248"> isStoreAdditionalIdAndRef.set(true);</span>
}
}
<span class="fc" id="L251"> int left = in.readVInt();</span>
<span class="fc" id="L252"> int right = in.readVInt();</span>
<span class="fc" id="L253"> int max = in.readVInt();</span>
<span class="fc" id="L254"> Long leftChild = in.readVLong() + nodeRefApproxOffset.get();</span>
<span class="fc" id="L255"> Long rightChild = in.readVLong() + nodeRefApproxOffset.get();</span>
<span class="fc" id="L256"> int size = 1;</span>
<span class="fc bfc" id="L257" title="All 2 branches covered."> if (!isSinglePoint.get()) {</span>
<span class="fc" id="L258"> size = in.readVInt();</span>
}
// initialize
<span class="fc" id="L261"> long[] objectRefs = new long[size];</span>
<span class="fc" id="L262"> int[] objectAdditionalIds = null;</span>
<span class="fc" id="L263"> long[] objectAdditionalRefs = null;</span>
// get first
<span class="fc" id="L265"> long objectRef = in.readVLong();</span>
<span class="fc" id="L266"> long objectRefPrevious = objectRef + objectRefApproxOffset;</span>
<span class="fc" id="L267"> objectRefs[0] = objectRefPrevious;</span>
<span class="fc bfc" id="L268" title="All 2 branches covered."> if (isStoreAdditionalIdAndRef.get()) {</span>
<span class="fc" id="L269"> objectAdditionalIds = new int[size];</span>
<span class="fc" id="L270"> objectAdditionalRefs = new long[size];</span>
<span class="fc" id="L271"> objectAdditionalIds[0] = in.readVInt();</span>
<span class="fc" id="L272"> objectAdditionalRefs[0] = in.readVLong();</span>
}
// get others
<span class="fc bfc" id="L275" title="All 2 branches covered."> for (int t = 1; t < size; t++) {</span>
<span class="fc" id="L276"> objectRef = objectRefPrevious + in.readVLong();</span>
<span class="fc" id="L277"> objectRefs[t] = objectRef;</span>
<span class="fc" id="L278"> objectRefPrevious = objectRef;</span>
<span class="pc bpc" id="L279" title="1 of 2 branches missed."> if (isStoreAdditionalIdAndRef.get()) {</span>
<span class="fc" id="L280"> objectAdditionalIds[t] = in.readVInt();</span>
<span class="fc" id="L281"> objectAdditionalRefs[t] = in.readVLong();</span>
}
}
<span class="fc" id="L284"> return new MtasTreeItem(left, right, max, objectRefs, objectAdditionalIds,</span>
objectAdditionalRefs, ref, leftChild, rightChild);
<span class="nc" id="L286"> } catch (Exception e) {</span>
<span class="nc" id="L287"> throw new IOException(e.getMessage());</span>
}
}
/**
* The Class MtasTreeItem.
*/
private static class MtasTreeItem {
/** The max. */
public int left, right, max;
/** The object refs. */
public long[] objectRefs;
/** The additional ids. */
public int[] additionalIds;
/** The additional refs. */
public long[] additionalRefs;
/** The right child. */
public Long ref, leftChild, rightChild;
/**
* Instantiates a new mtas tree item.
*
* @param left the left
* @param right the right
* @param max the max
* @param objectRefs the object refs
* @param additionalIds the additional ids
* @param additionalRefs the additional refs
* @param ref the ref
* @param leftChild the left child
* @param rightChild the right child
*/
public MtasTreeItem(int left, int right, int max, long[] objectRefs,
int[] additionalIds, long[] additionalRefs, Long ref, Long leftChild,
<span class="fc" id="L326"> Long rightChild) {</span>
<span class="fc" id="L327"> this.left = left;</span>
<span class="fc" id="L328"> this.right = right;</span>
<span class="fc" id="L329"> this.max = max;</span>
<span class="fc" id="L330"> this.objectRefs = objectRefs;</span>
<span class="fc" id="L331"> this.additionalIds = additionalIds;</span>
<span class="fc" id="L332"> this.additionalRefs = additionalRefs;</span>
<span class="fc" id="L333"> this.ref = ref;</span>
<span class="fc" id="L334"> this.leftChild = leftChild;</span>
<span class="fc" id="L335"> this.rightChild = rightChild;</span>
<span class="fc" id="L336"> }</span>
}
/**
* The Class MtasTreeHit.
*
* @param <T> the generic type
*/
public static class MtasTreeHit<T> {
/** The start position. */
public int startPosition;
/** The end position. */
public int endPosition;
/** The ref. */
public long ref;
/** The additional id. */
public int additionalId;
/** The additional ref. */
public long additionalRef;
/** The ref data. */
public T data, idData, refData;
/**
* Instantiates a new mtas tree hit.
*
* @param startPosition the start position
* @param endPosition the end position
* @param ref the ref
* @param additionalId the additional id
* @param additionalRef the additional ref
*/
public MtasTreeHit(int startPosition, int endPosition, long ref,
<span class="fc" id="L374"> int additionalId, long additionalRef) {</span>
<span class="fc" id="L375"> this.startPosition = startPosition;</span>
<span class="fc" id="L376"> this.endPosition = endPosition;</span>
<span class="fc" id="L377"> this.ref = ref;</span>
<span class="fc" id="L378"> this.additionalId = additionalId;</span>
<span class="fc" id="L379"> this.additionalRef = additionalRef;</span>
<span class="fc" id="L380"> data = null;</span>
<span class="fc" id="L381"> idData = null;</span>
<span class="fc" id="L382"> refData = null;</span>
<span class="fc" id="L383"> }</span>
/**
* Instantiates a new mtas tree hit.
*
* @param startPosition the start position
* @param endPosition the end position
* @param ref the ref
* @param additionalId the additional id
* @param additionalRef the additional ref
* @param data the data
*/
public MtasTreeHit(int startPosition, int endPosition, long ref,
int additionalId, long additionalRef, T data) {
<span class="nc" id="L397"> this(startPosition, endPosition, ref, additionalId, additionalRef);</span>
<span class="nc" id="L398"> this.data = data;</span>
<span class="nc" id="L399"> this.idData = null;</span>
<span class="nc" id="L400"> this.refData = null;</span>
<span class="nc" id="L401"> }</span>
/*
* (non-Javadoc)
*
* @see java.lang.Object#toString()
*/
@Override
public String toString() {
<span class="nc" id="L410"> return "hit[" + startPosition + "," + endPosition + "," + ref + ","</span>
+ additionalId + "," + additionalRef + "] - " + idData + " - "
+ refData;
}
}
/**
* Search mtas tree with interval tree.
*
* @param <T> the generic type
* @param <N> the number type
* @param additionalIds the additional ids
* @param intervalTree the interval tree
* @param in the in
* @param ref the ref
* @param objectRefApproxOffset the object ref approx offset
* @throws IOException Signals that an I/O exception has occurred.
*/
public static <T, N extends IntervalTreeNode<T, N>> void searchMtasTreeWithIntervalTree(
Collection<Integer> additionalIds, IntervalTree<T, N> intervalTree,
IndexInput in, long ref, long objectRefApproxOffset) throws IOException {
<span class="fc" id="L431"> ArrayList<IntervalItem<T, N>> checkList = new ArrayList<IntervalItem<T, N>>();</span>
<span class="fc" id="L432"> AtomicBoolean isSinglePoint = new AtomicBoolean(false);</span>
<span class="fc" id="L433"> AtomicBoolean isStoreAdditionalId = new AtomicBoolean(false);</span>
<span class="fc" id="L434"> AtomicLong nodeRefApproxOffset = new AtomicLong(-1);</span>
<span class="fc" id="L435"> checkList.add(new IntervalItem<T, N>(</span>
<span class="fc" id="L436"> getMtasTreeItem(ref, isSinglePoint, isStoreAdditionalId,</span>
nodeRefApproxOffset, in, objectRefApproxOffset),
<span class="fc" id="L438"> intervalTree.getRoot()));</span>
do {
<span class="fc" id="L440"> IntervalItem<T, N> checkItem = checkList.remove(checkList.size() - 1);</span>
<span class="fc" id="L441"> searchMtasTreeWithIntervalTree(additionalIds, checkItem, in,</span>
isSinglePoint, isStoreAdditionalId, objectRefApproxOffset,
nodeRefApproxOffset, checkList);
<span class="fc bfc" id="L444" title="All 2 branches covered."> } while (checkList.size() > 0);</span>
<span class="fc" id="L445"> }</span>
/**
* Search mtas tree with interval tree.
*
* @param <T> the generic type
* @param <N> the number type
* @param additionalIds the additional ids
* @param checkItem the check item
* @param in the in
* @param isSinglePoint the is single point
* @param isStoreAdditionalId the is store additional id
* @param objectRefApproxOffset the object ref approx offset
* @param nodeRefApproxOffset the node ref approx offset
* @param checkList the check list
* @throws IOException Signals that an I/O exception has occurred.
*/
private static <T, N extends IntervalTreeNode<T, N>> void searchMtasTreeWithIntervalTree(
Collection<Integer> additionalIds, IntervalItem<T, N> checkItem,
IndexInput in, AtomicBoolean isSinglePoint,
AtomicBoolean isStoreAdditionalId, long objectRefApproxOffset,
AtomicLong nodeRefApproxOffset, ArrayList<IntervalItem<T, N>> checkList)
throws IOException {
<span class="fc" id="L468"> MtasTreeItem treeItem = checkItem.mtasTreeItem;</span>
<span class="fc" id="L469"> IntervalTreeNode<T, N> intervalTreeNode = checkItem.intervalTreeNode;</span>
<span class="fc bfc" id="L470" title="All 2 branches covered."> if (intervalTreeNode.min <= treeItem.max) {</span>
// advance intervalTree
<span class="fc bfc" id="L472" title="All 2 branches covered."> while (intervalTreeNode.left > treeItem.max) {</span>
<span class="pc bpc" id="L473" title="1 of 2 branches missed."> if (intervalTreeNode.rightChild == null) {</span>
<span class="nc bnc" id="L474" title="All 2 branches missed."> if (intervalTreeNode.leftChild == null) {</span>
<span class="nc" id="L475"> return;</span>
} else {
<span class="nc" id="L477"> intervalTreeNode = intervalTreeNode.leftChild;</span>
}
<span class="pc bpc" id="L479" title="1 of 2 branches missed."> } else if (intervalTreeNode.leftChild == null) {</span>
<span class="nc" id="L480"> intervalTreeNode = intervalTreeNode.rightChild;</span>
} else {
<span class="pc bpc" id="L482" title="1 of 2 branches missed."> if (intervalTreeNode.rightChild.min > treeItem.max) {</span>
<span class="fc" id="L483"> intervalTreeNode = intervalTreeNode.leftChild;</span>
} else {
break;
}
}
}
// find intervals matching current node
<span class="fc" id="L490"> searchMtasTreeItemWithIntervalTree(additionalIds, treeItem,</span>
intervalTreeNode);
// check leftChild
<span class="fc bfc" id="L493" title="All 2 branches covered."> if (!treeItem.leftChild.equals(treeItem.ref)) {</span>
<span class="fc" id="L494"> MtasTreeItem treeItemLeft = getMtasTreeItem(treeItem.leftChild,</span>
isSinglePoint, isStoreAdditionalId, nodeRefApproxOffset, in,
objectRefApproxOffset);
<span class="fc" id="L497"> checkList.add(new IntervalItem<T, N>(treeItemLeft, intervalTreeNode));</span>
}
// check rightChild
<span class="fc bfc" id="L500" title="All 2 branches covered."> if (!treeItem.rightChild.equals(treeItem.ref)) {</span>
<span class="fc" id="L501"> MtasTreeItem treeItemRight = getMtasTreeItem(treeItem.rightChild,</span>
isSinglePoint, isStoreAdditionalId, nodeRefApproxOffset, in,
objectRefApproxOffset);
<span class="fc" id="L504"> checkList.add(new IntervalItem<T, N>(treeItemRight, intervalTreeNode));</span>
}
}
<span class="fc" id="L507"> }</span>
/**
* Search mtas tree item with interval tree.
*
* @param <T> the generic type
* @param <N> the number type
* @param additionalIds the additional ids
* @param treeItem the tree item
* @param intervalTreeNode the interval tree node
*/
private static <T, N extends IntervalTreeNode<T, N>> void searchMtasTreeItemWithIntervalTree(
Collection<Integer> additionalIds, MtasTreeItem treeItem,
IntervalTreeNode<T, N> intervalTreeNode) {
<span class="fc" id="L521"> ArrayList<IntervalTreeNode<T, N>> checkList = new ArrayList<IntervalTreeNode<T, N>>();</span>
<span class="fc" id="L522"> checkList.add(intervalTreeNode);</span>
do {
<span class="fc" id="L524"> IntervalTreeNode<T, N> checkItem = checkList.remove(checkList.size() - 1);</span>
<span class="fc" id="L525"> searchMtasTreeItemWithIntervalTree(additionalIds, checkItem,</span>
treeItem.left, treeItem.right, treeItem.objectRefs,
treeItem.additionalIds, treeItem.additionalRefs, checkList);
<span class="fc bfc" id="L528" title="All 2 branches covered."> } while (checkList.size() > 0);</span>
<span class="fc" id="L529"> }</span>
/**
* Search mtas tree item with interval tree.
*
* @param <T> the generic type
* @param <N> the number type
* @param requiredAdditionalIds the required additional ids
* @param intervalTreeItem the interval tree item
* @param startPosition the start position
* @param endPosition the end position
* @param refs the refs
* @param additionalIds the additional ids
* @param additionalRefs the additional refs
* @param checkList the check list
*/
private static <T, N extends IntervalTreeNode<T, N>> void searchMtasTreeItemWithIntervalTree(
Collection<Integer> requiredAdditionalIds,
IntervalTreeNode<T, N> intervalTreeItem, int startPosition,
int endPosition, long[] refs, int[] additionalIds, long[] additionalRefs,
ArrayList<IntervalTreeNode<T, N>> checkList) {
<span class="fc bfc" id="L550" title="All 2 branches covered."> if (startPosition <= intervalTreeItem.max) {</span>
// match current node
<span class="fc bfc" id="L552" title="All 4 branches covered."> if ((endPosition >= intervalTreeItem.left)</span>
&& (startPosition <= intervalTreeItem.right)) {
// System.out.print("[" + startPosition + "-" + endPosition + "] ");
<span class="pc bpc" id="L555" title="2 of 4 branches missed."> if (requiredAdditionalIds == null || additionalIds == null) {</span>
<span class="nc bnc" id="L556" title="All 2 branches missed."> for (int i = 0; i < refs.length; i++) {</span>
<span class="nc" id="L557"> MtasTreeHit<T> hit = new MtasTreeHit<T>(startPosition, endPosition,</span>
refs[i], 0, 0);
<span class="nc bnc" id="L559" title="All 2 branches missed."> for (ArrayList<MtasTreeHit<T>> list : intervalTreeItem.lists) {</span>
<span class="nc" id="L560"> list.add(hit);</span>
<span class="nc" id="L561"> }</span>
}
} else {
<span class="fc bfc" id="L564" title="All 2 branches covered."> for (int i = 0; i < refs.length; i++) {</span>
<span class="fc" id="L565"> MtasTreeHit<T> hit = new MtasTreeHit<T>(startPosition, endPosition,</span>
refs[i], additionalIds[i], additionalRefs[i]);
<span class="fc bfc" id="L567" title="All 2 branches covered."> for (ArrayList<MtasTreeHit<T>> list : intervalTreeItem.lists) {</span>
<span class="fc bfc" id="L568" title="All 2 branches covered."> if (requiredAdditionalIds.contains(hit.additionalId)) {</span>
<span class="fc" id="L569"> list.add(hit);</span>
}
<span class="fc" id="L571"> }</span>
}
}
}
// check leftChild
<span class="fc bfc" id="L576" title="All 2 branches covered."> if (intervalTreeItem.leftChild != null) {</span>
<span class="fc" id="L577"> IntervalTreeNode<T, N> treeItemLeft = intervalTreeItem.leftChild;</span>
<span class="fc bfc" id="L578" title="All 2 branches covered."> if (treeItemLeft.max >= startPosition) {</span>
<span class="fc" id="L579"> checkList.add(treeItemLeft);</span>
}
}
// check rightChild
<span class="fc bfc" id="L583" title="All 2 branches covered."> if (intervalTreeItem.left < endPosition) {</span>
<span class="fc bfc" id="L584" title="All 2 branches covered."> if (intervalTreeItem.rightChild != null) {</span>
<span class="fc" id="L585"> IntervalTreeNode<T, N> treeItemRight = intervalTreeItem.rightChild;</span>
<span class="pc bpc" id="L586" title="1 of 4 branches missed."> if ((treeItemRight.left >= endPosition)</span>
|| (treeItemRight.max >= startPosition)) {
<span class="fc" id="L588"> checkList.add(treeItemRight);</span>
}
}
}
}
<span class="fc" id="L594"> }</span>
/**
* The Class IntervalItem.
*
* @param <T> the generic type
* @param <N> the number type
*/
<span class="nc" id="L602"> private static class IntervalItem<T, N extends IntervalTreeNode<T, N>> {</span>
/** The mtas tree item. */
public MtasTreeItem mtasTreeItem;
/** The interval tree node. */
public IntervalTreeNode<T, N> intervalTreeNode;
/**
* Instantiates a new interval item.
*
* @param mtasTreeItem the mtas tree item
* @param intervalTreeNode the interval tree node
*/
public IntervalItem(MtasTreeItem mtasTreeItem,
<span class="fc" id="L617"> IntervalTreeNode<T, N> intervalTreeNode) {</span>
<span class="fc" id="L618"> this.mtasTreeItem = mtasTreeItem;</span>
<span class="fc" id="L619"> this.intervalTreeNode = intervalTreeNode;</span>
<span class="fc" id="L620"> }</span>
}
}
</pre><div class="footer"><span class="right">Created with <a href="http://www.jacoco.org/jacoco">JaCoCo</a> 0.7.9.201702052155</span></div></body></html>