| 1 | // This file is part of A2Amapper.cxx . . $ `<file>/atac-driver/alignOverlap/overlap-matchTree.C`/ |
| 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 | #include "overlap.H"cxx . . $ `<file>/atac-driver/alignOverlap/overlap.H`/ |
| 20 | |
| 21 | matchTreecxx . . $ matchTree#::matchTreecxx . . $ matchTree#matchTree(9320de94943ce534).(atacMatchListcxx . . $ atacMatchList# *L, uint32cxx . . $ uint32# side) { |
| 22 | |
| 23 | // Construct a list of pointers to the atacMatchList data |
| 24 | // |
| 25 | // kazlib was modified to be qsort() compatible and so it passes a |
| 26 | // pointer to whatever it is sorting. Since kazlib operates on |
| 27 | // pointers anyway, this means that it passes the compare function |
| 28 | // a pointer to a pointer to the object. |
| 29 | // |
| 30 | // Which really fails in this case. We have a list of pointers to |
| 31 | // objects that we sort, then want to load. |
| 32 | // |
| 33 | // Uhhh, no, this is correct. We give kazlib a pointer to the |
| 34 | // object, it gives the compare function a pointer to that pointer. |
| 35 | // |
| 36 | // qsort() below sorts pointers to objects, and does the same. |
| 37 | |
| 38 | atacMatchcxx . . $ atacMatch# **matchPointers = new atacMatchcxx . . $ atacMatch# * [L->numberOfMatchescxx . . $ atacMatchList#numberOfMatches(db52760e79bf9054).()]; |
| 39 | for (uint32cxx . . $ uint32# i=0; i<L->numberOfMatchescxx . . $ atacMatchList#numberOfMatches(db52760e79bf9054).(); i++) |
| 40 | matchPointers[i] = L->getMatchcxx . . $ atacMatchList#getMatch(4b949e4d42dbfd78).(i); |
| 41 | |
| 42 | // Choose a comparison function based on the side we want |
| 43 | |
| 44 | int (*sortMatches)(const void *, const void *) = sortMatches1cxx . . $ sortMatches1(9148c8c3ff42c9d8).; |
| 45 | if (side == 1) |
| 46 | sortMatches = sortMatches2cxx . . $ sortMatches2(9148c8c3ff42c9d8).; |
| 47 | |
| 48 | // Sort |
| 49 | |
| 50 | qsortcxx . . $ qsort(ebb60b13a65e77d7).(matchPointers, L->numberOfMatchescxx . . $ atacMatchList#numberOfMatches(db52760e79bf9054).(), sizeof(atacMatchcxx . . $ atacMatch# *), sortMatches); |
| 51 | |
| 52 | // Load the tree (use DICTCOUNT_T_MAX for max nodes) |
| 53 | |
| 54 | _treecxx . . $ matchTree#_tree. = dict_create(L->numberOfMatchescxx . . $ atacMatchList#numberOfMatches(db52760e79bf9054).(), sortMatches); |
| 55 | dict_allow_dupes(_treecxx . . $ matchTree#_tree.); |
| 56 | |
| 57 | dict_load_begin(&_loadcxx . . $ matchTree#_load., _treecxx . . $ matchTree#_tree.); |
| 58 | |
| 59 | for (uint32cxx . . $ uint32# i=0; i<L->numberOfMatchescxx . . $ atacMatchList#numberOfMatches(db52760e79bf9054).(); i++) { |
| 60 | dnode_t *node = (dnode_t *)malloccxx . . $ malloc(9f008b2a9698428b).(sizeof(dnode_t)); |
| 61 | dnode_init(node, 0L); |
| 62 | dict_load_next(&_loadcxx . . $ matchTree#_load., node, matchPointers[i]); |
| 63 | } |
| 64 | |
| 65 | dict_load_end(&_loadcxx . . $ matchTree#_load.); |
| 66 | |
| 67 | // Clean up |
| 68 | delete [] matchPointers; |
| 69 | } |