| 1 | // This file is part of A2Amapper. |
| 2 | // Copyright (c) 2005 J. Craig Venter Institute |
| 3 | // Author: Brian Walenz |
| 4 | // |
| 5 | // This program is free software; you can redistribute it and/or modify |
| 6 | // it under the terms of the GNU General Public License as published by |
| 7 | // the Free Software Foundation; either version 2 of the License, or |
| 8 | // (at your option) any later version. |
| 9 | // |
| 10 | // This program is distributed in the hope that it will be useful, |
| 11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | // GNU General Public License for more details. |
| 14 | // |
| 15 | // You should have received (LICENSE.txt) a copy of the GNU General Public |
| 16 | // License along with this program; if not, write to the Free Software |
| 17 | // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 18 | |
| 19 | #ifndef OVERLAP_SPAN_H |
| 20 | #define OVERLAP_SPAN_H |
| 21 | |
| 22 | #include "overlap.H" |
| 23 | |
| 24 | #define COLORSHIFT 24 |
| 25 | #define COLORMASK 0x00ffffff |
| 26 | |
| 27 | class span_t { |
| 28 | public: |
| 29 | uint32 _iid; |
| 30 | uint32 _beg; |
| 31 | uint32 _end; |
| 32 | uint32 _matchesLen; |
| 33 | uint32 _matchesMax; |
| 34 | uint32 *_matches; |
| 35 | |
| 36 | span_t(uint32 iid, uint32 beg, uint32 end) { |
| 37 | _iid = iid; |
| 38 | _beg = beg; |
| 39 | _end = end; |
| 40 | _matchesLen = 0; |
| 41 | _matchesMax = 0; |
| 42 | _matches = 0L; |
| 43 | }; |
| 44 | |
| 45 | ~span_t() { |
| 46 | delete [] _matches; |
| 47 | }; |
| 48 | |
| 49 | // The top X bits of the _matches is for storing the color. This |
| 50 | // does cut down the number of matches we can store. Human-Human |
| 51 | // is ~1 million matches. |
| 52 | |
| 53 | void addMatch(uint32 matchiid, uint32 color) { |
| 54 | if (_matchesLen >= _matchesMax) { |
| 55 | if (_matchesMax == 0) |
| 56 | _matchesMax = 2; |
| 57 | _matchesMax *= 2; |
| 58 | uint32 *X = new uint32 [_matchesMax]; |
| 59 | memcpy(X, _matches, sizeof(uint32) * _matchesLen); |
| 60 | delete [] _matches; |
| 61 | _matches = X; |
| 62 | } |
| 63 | |
| 64 | if (matchiid >> COLORSHIFT) |
| 65 | fprintf(stderr, "ERROR! span_t::addMatch()-- match id too big, decrease the color space.\n"), exit(1); |
| 66 | |
| 67 | _matches[_matchesLen++] = (color << COLORSHIFT) | (matchiid); |
| 68 | }; |
| 69 | |
| 70 | // Split this span at position, return two new spans |
| 71 | // |
| 72 | void split(uint32 position, span_t* &l, span_t* &r) { |
| 73 | |
| 74 | if ((position < _beg) || (_end < position)) { |
| 75 | fprintf(stderr, "span_t::split()-- _beg="uint32FMT" _end="uint32FMT" postition="uint32FMT"?\n", _beg, _end, position); |
| 76 | exit(1); |
| 77 | } |
| 78 | |
| 79 | l = new span_t(_iid, _beg, position); |
| 80 | r = new span_t(_iid, position, _end); |
| 81 | |
| 82 | l->_matchesLen = _matchesLen; |
| 83 | l->_matchesMax = _matchesMax; |
| 84 | l->_matches = new uint32 [_matchesMax]; |
| 85 | memcpy(l->_matches, _matches, sizeof(uint32) * _matchesLen); |
| 86 | |
| 87 | r->_matchesLen = _matchesLen; |
| 88 | r->_matchesMax = _matchesMax; |
| 89 | r->_matches = new uint32 [_matchesMax]; |
| 90 | memcpy(r->_matches, _matches, sizeof(uint32) * _matchesLen); |
| 91 | }; |
| 92 | }; |
| 93 | |
| 94 | #endif // OPERLAP_SPAN_H |