Coverage Report - org.galagosearch.core.index.ExtentListBuffer
 
Classes in this File Line Coverage Branch Coverage Complexity
ExtentListBuffer
92%
49/53
75%
3/4
1.182
 
 1  
 package org.galagosearch.core.index;
 2  
 
 3  
 import java.io.IOException;
 4  
 import java.io.OutputStream;
 5  
 
 6  
 public class ExtentListBuffer implements IndexElement {
 7  
     public ExtentListBuffer() {
 8  36
         super();
 9  36
         documentCount = 0;
 10  36
         extentCount = 0;
 11  36
         endCount = 0;
 12  36
         data = new CompressedByteBuffer();
 13  36
         header = new CompressedByteBuffer();
 14  36
         documentExtents = new CompressedByteBuffer();
 15  36
     }
 16  
 
 17  
     public long dataLength() {
 18  180
         long listLength = 0;
 19  180
         listLength += header.length();
 20  180
         listLength += data.length();
 21  180
         return listLength;
 22  
     }
 23  
 
 24  
     public void write(final OutputStream output) throws IOException {
 25  36
         output.write(header.getBytes(), 0, header.length());
 26  36
         output.write(data.getBytes(), 0, data.length());
 27  36
     }
 28  
 
 29  
     public byte[] key() {
 30  204
         return word;
 31  
     }
 32  
 
 33  
     public void setWord(byte[] word) {
 34  36
         this.word = word;
 35  36
         this.lastDocument = 0;
 36  36
         this.lastPosition = 0;
 37  36
         this.extentCount = 0;
 38  36
     }
 39  
 
 40  
     void setValue(long value) {
 41  0
         this.value = value;
 42  0
     }
 43  
 
 44  
     private void storePreviousDocument() {
 45  84
         if (data.position > 0) {
 46  48
             data.add(extentCount);
 47  48
             data.add(documentExtents);
 48  48
             documentExtents.clear();
 49  
         }
 50  84
     }
 51  
 
 52  
     public void addDocument(long documentID) {
 53  48
         storePreviousDocument();
 54  48
         data.add(documentID - lastDocument);
 55  48
         lastDocument = documentID;
 56  48
         lastStartExtent = 0;
 57  48
         extentCount = 0;
 58  48
         endCount = 0;
 59  48
         value = 0;
 60  48
         documentCount++;
 61  48
     }
 62  
 
 63  
     public void addBegin(int begin) {
 64  60
         extentCount++;
 65  60
         documentExtents.add(begin - lastStartExtent);
 66  60
         lastStartExtent = begin;
 67  60
     }
 68  
 
 69  
     public void addEnd(int end) {
 70  60
         endCount++;
 71  
         // Record multiple extents at the same begin location
 72  60
         if (endCount > extentCount) {
 73  0
             documentExtents.add(0);
 74  0
             extentCount++;
 75  
         }
 76  60
         documentExtents.add(end - lastStartExtent);
 77  60
         documentExtents.add(value);
 78  60
     }
 79  
 
 80  
     public void close() {
 81  36
         int options = 0;
 82  36
         storePreviousDocument();
 83  36
         header.add(options);
 84  36
         header.add(documentCount);
 85  36
     }
 86  
 
 87  
     private long value;
 88  
     private long lastDocument;
 89  
     private int lastStartExtent;
 90  
     private int lastPosition;
 91  
     private int extentCount;
 92  
     private int endCount;
 93  
     private int documentCount;
 94  
     public byte[] word;
 95  
     public CompressedByteBuffer header;
 96  
     public CompressedByteBuffer data;
 97  
     public CompressedByteBuffer documentExtents;
 98  
 }