This file is indexed.

/usr/include/kmer/bio/merCovering.H is in libkmer-dev 0~20150903+r2013-3.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  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
#ifndef MER_COVERING_H
#define MER_COVERING_H

//  This is an interval list, where the intervals are built using
//  fixed size pieces.
//
//  It's designed to accept pieces in roughly sorted order.
//
//  Intervals are stored c-style.
//

#include <stdio.h>
#include <stdlib.h>

class merCovering {
private:
  class interval {
  public:
    uint32      _lo;
    uint32      _hi;
    interval   *_next;

    interval(uint32 lo, uint32 hi, interval *n) {
      _lo   = lo;
      _hi   = hi;
      _next = n;
    }
  };

  interval    *_intervals;
  uint32       _width;
  uint32       _pieces;
#ifdef TEST_MERCOVERING
  uint32       _test[TEST_SIZE];
#endif

public:
  merCovering(uint32 w) {
    _intervals = 0L;
    _width     = w;
    _pieces    = 0;

#ifdef TEST_MERCOVERING
    for (uint32 i=0; i<TEST_SIZE; i++)
      _test[i] = 0;
#endif
  };

  ~merCovering() {
    clear();
  };

  void          clear(void) {
    interval *i = _intervals;

    while (i) {
      _intervals = i->_next;
      delete i;
      i = _intervals;
    }

    _intervals = 0L;
    _pieces    = 0;
  };

  uint32        sumOfLengths(void) {
    uint32 s=0;

    for (interval *i=_intervals; i; i = i->_next)
      s += i->_hi - i->_lo;

    return(s);
  };

  uint32        numberOfPieces(void) {
    return(_pieces);
  };

  void          addMer(uint32 lo) {
    _pieces++;

    uint32 hi = lo + _width;

    interval  *c;

#ifdef TEST_MERCOVERING
    for (uint32 i=lo; i<hi; i++)
      _test[i] = 1;
#endif

    //  Case:  No existing intervals, or the new interval extends
    //  the low range of the first interval
    //
    if ((_intervals == 0L) ||
        (hi < _intervals->_lo)) {
      _intervals = new interval(lo, hi, _intervals);
      return;
    }

    c = _intervals;

    while (c) {

      //  Case:  New interval is completely contained in the current interval.
      //
      if ((c->_lo <= lo) && (hi <= c->_hi))
        return;

      //  Case:  New interval overlaps the low end of the current interval,
      //  or is completely contained in an existing interval.
      //
      if ((lo <= c->_lo) && (hi <= c->_hi)) {
        c->_lo = lo;
        return;
      }

      if (c->_next) {

        //  Case: New interval overlaps the high end of the current interval...
        //
        if (lo <= c->_hi) {

          if (hi < c->_next->_lo) {
            //  but does not intersect the next interval.
            //
            c->_hi = hi;
            return;
          } else {
            //  and does intersect the next interval.
            //
            interval *p = c->_next;

            c->_hi   = c->_next->_hi;
            c->_next = c->_next->_next;

            delete p;
            return;
          }
        } else {
          //  Case: New interval is between two existing intervals
          //
          //  (lo > c->_hi) is given
          //
          if (hi < c->_next->_lo) {
            c->_next = new interval(lo, hi, c->_next);
            return;
          }
        }
      } else {
        //  Case:  New interval overlaps the high end of the current interval
        //
        if (lo <= c->_hi) {
            c->_hi = hi;
            return;
        } else {
          //  Otherwise, we just fell off the end of all intervals.
          //  Add one at the end.
          //
          c->_next = new interval(lo, hi,0L);
          return;
        }
      }

      c = c->_next;
    }

#ifdef TEST_MERCOVERING
    fprintf(stderr, "ERROR IN addInterval!\n");
#endif
  };

#ifdef TEST_MERCOVERING
  void         test(void) {
    for (uint32 i=0; i<TEST_SIZE; i++) {
      if (_test[i])
        _test[i] = 2;
    }
    for (interval *z=_intervals; z; z = z->_next) {
      for (uint32 i=z->_lo; i<z->_hi; i++) {
        if (_test[i] == 0) {
          fprintf(stderr, "INTERVAL CONTAINS SOMETHING NOT IN ARRAY! (%d)\n", i);
          exit(1);
        }
        if (_test[i] == 1) {
          fprintf(stderr, "INTERVAL HIT SOMETHING TWICE! (%d)\n", i);
          exit(1);
        }
        _test[i] = 1;
      }
    }
    for (uint32 i=0; i<TEST_SIZE; i++) {
      if (_test[i] == 2) {
        fprintf(stderr, "ARRAY CONTAINED SOMETHING NOT IN INTERVAL! (%d)\n", i);
        exit(1);
      }
    }
  };
#endif



  //  Incorporates the intervals in B into our list.
  //
  void         merge(merCovering *I = 0L) {
    interval *A, *B, *N, *L;

    if (I == 0L)
      return;

    A = _intervals;
    B = I->_intervals;
    N = 0L;
    L = 0L;

    while (A || B) {
      uint32 lo = 0;
      uint32 hi = 0;

      //  if either list is zero, we can just zip down the other list
      //  and add things.
      //
      if (!B) {
        while (A) {
          L->_next = new interval(A->_lo, A->_hi, 0L);
          L = L->_next;
          A = A->_next;
        }
      }

      if (!A) {
        while (B) {
          L->_next = new interval(B->_lo, B->_hi, 0L);
          L = L->_next;
          B = B->_next;
        }
      }

      if (A && B) {
        if (A->_lo == B->_lo) {
          //  A and B start at the same position
          //
          lo = A->_lo;
          hi = A->_hi;
          if (hi < B->_hi)
            hi = B->_hi;

          A = A->_next;
          B = B->_next;
        } else {
          //  A and B start at different positions.  Pick the first one.
          //
          if (A->_lo < B->_lo) {
            lo = A->_lo;
            hi = A->_hi;
            A = A->_next;
          } else {
            lo = B->_lo;
            hi = B->_hi;
            B = B->_next;
          }
        }

        //  We have an initial interval.  Add more stuff, while there
        //  are overlaps.

        bool modified = true;

        while ((A || B) && (modified)) {
          modified = false;

          if ((A) && (hi >= A->_lo)) {
            if (hi < A->_hi)
              hi = A->_hi;
            A = A->_next;
            modified = true;
          }

          if ((B) && (hi >= B->_lo)) {
            if (hi < B->_hi)
              hi = B->_hi;
            B = B->_next;
            modified = true;
          }
        }

        //  OK, got the new interval.  Save it.
        //
        if (N) {
          L->_next = new interval(lo, hi, 0L);
          L = L->_next;
        } else {
          N = L = new interval(lo, hi, 0L);
        }
      }
    }

    //  Save the number of mers in both intervals
    //
    uint32  p = _pieces + I->_pieces;

    clear();

    _intervals = N;
    _pieces    = p;
  }




#ifdef TEST_MERCOVERING
  void         dump(void) {
    for (interval *i=_intervals; i; i = i->_next)
      fprintf(stderr, "%5d-%5d ", i->_lo, i->_hi);
    fprintf(stderr, "\n");
  };

  void         compare(merCovering *B) {
    interval *i = _intervals;
    interval *j = B->_intervals;

    if (_pieces != B->_pieces) {
      fprintf(stderr, "Pieces differ (this=%d that=%d).\n", _pieces, B->_pieces);
      exit(1);
    }

    while (i && j) {
      if ((i->_lo != j->_lo) || (i->_hi != j->_hi)) {
        fprintf(stderr, "ERROR!\n");
        exit(1);
      }

      i = i->_next;
      j = j->_next;
    }

    if (i) {
      fprintf(stderr, "ERROR (i still exists)!\n");
      exit(1);
    }

    if (j) {
      fprintf(stderr, "ERROR (i still exists)!\n");
      exit(1);
    }
  };
#endif

};

#endif  //  MERCOVERING_H