source: tags/arb_5.0/CONSENSUS_TREE/CT_dtree.cxx

Last change on this file was 5390, checked in by westram, 16 years ago
  • TAB-Ex
  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 1.6 KB
Line 
1/* destruct gbt-tree and build parts */
2/* insert afterwards in Hashtable */
3
4#include <stdio.h>
5#include <stdlib.h>
6#include <string.h>
7
8#include <arbdb.h>
9#include <arbdbt.h>
10
11#include "CT_part.hxx"
12#include "CT_hash.hxx"
13
14void destree_init(GB_HASH *hash)
15{
16    Name_hash = hash;
17}
18
19
20/* destruct GBT-Tree and build partitions. This is done recursive by concatenate
21   all sons to build the father partition. All partitions are iinserted in the
22   hashtable */
23/* caution: I use the fact that each inner node must have two sons. */
24PART *dtree(GBT_TREE *tree, int weight, GBT_LEN len)
25{
26    PART *p1, *p2, *ph;
27    int idx;
28
29    if(tree->is_leaf) {
30        ph = part_new();
31        idx = GBS_read_hash(Name_hash, tree->name);
32        part_setbit(ph, idx);
33        part_setlen(ph, len);
34        return ph;
35    }
36
37    /* In any possible case left and rightson always exist ... */
38    p1 = dtree(tree->leftson, weight, tree->leftlen);
39    ph = part_new();
40    part_copy(p1, ph);
41    hash_insert(ph, weight);
42
43    p2 = dtree(tree->rightson, weight, tree->rightlen);
44    part_or(p2, p1);
45    hash_insert(p2, weight);
46    part_setlen(p1, len);
47    return p1;
48}
49
50
51/* it is nessasary to destruct the left and the right side seperatly, because
52   the root is only a virtual node and must be ignored. Moreover the left and
53   rightson are the same partition. So I may only insert right son.            */
54void des_tree(GBT_TREE *tree, int weight)
55{
56    PART *p;
57
58    p = dtree(tree->leftson, weight, 0.0);
59    part_free(p);
60    p = dtree(tree->rightson, weight, 0.0);
61    part_setlen(p, (tree->leftlen + tree->rightlen));
62    hash_insert(p, weight);
63}
Note: See TracBrowser for help on using the repository browser.