File: memslot.h

package info (click to toggle)
iqtree 1.6.12%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 12,140 kB
  • sloc: cpp: 111,752; ansic: 53,619; python: 242; sh: 195; makefile: 52
file content (111 lines) | stat: -rw-r--r-- 3,848 bytes parent folder | download | duplicates (5)
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
/***************************************************************************
 *   Copyright (C) 2009-2016 by                                            *
 *   BUI Quang Minh <minh.bui@univie.ac.at>                                *
 *                                                                         *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
 ***************************************************************************/

#ifndef MEMSLOT_H
#define MEMSLOT_H

#ifndef PHYLOTREE_H
#error "Please #include phylotree.h before including this header file" 
#endif

/**
    one memory slot, used for memory saving technique
*/
struct MemSlot {
    int status; // status of this slot
    PhyloNeighbor *nei; // neighbor assigned to this slot
    double *partial_lh; // partial_lh assigned to this slot
    UBYTE *scale_num; // scale_num assigned to this slot

    PhyloNeighbor *saved_nei;
};

/**
    all memory slots, used for memory saving technique
*/
class MemSlotVector : public vector<MemSlot> {
public:

    /** initialize with a specified number of slots */
    void init(PhyloTree *tree, int num_slot);

    /** 
        lock the memory assigned to nei
        @param nei neighbor to lock
        @return TRUE if successfully locked, FALSE otherwise 
    */
    bool lock(PhyloNeighbor *nei);

    /** unlock the memory assigned to nei */
    void unlock(PhyloNeighbor *nei);

    /** test if the memory assigned to nei is locked or not */
    bool locked(PhyloNeighbor *nei);

    /** allocate free or unlocked memory to nei */
    int allocate(PhyloNeighbor *nei);

    /** update neighbor */
    void update(PhyloNeighbor *nei);

    /** find ID the a neighbor */
    iterator findNei(PhyloNeighbor *nei);

    /** add neighbor into a specified iterator */
    void addNei(PhyloNeighbor *nei, iterator it);

    /** reset everything */
    void reset();

    /** clean up all neighbors where partial_lh_computed = 0 */
    void cleanup();

    /** take over neighbor from another one */
    void takeover(PhyloNeighbor *nei, PhyloNeighbor *taken_nei);

    /** add special neihbor e.g. for NNI */
    void addSpecialNei(PhyloNeighbor *nei);

    /** erase special neihbor e.g. for NNI */
    void eraseSpecialNei();

    /** replace a neighbor, used for NNI */
    void replace(PhyloNeighbor *new_nei, PhyloNeighbor *old_nei);

    /** restore neighbor, after calling replace */
    void restore(PhyloNeighbor *new_nei, PhyloNeighbor *old_nei);

protected:


    /** 
        map from neighbor to slot ID for fast lookup
        IMPORTANT: mapping to ID instead of (unsafe) iterator
    */
    unordered_map<PhyloNeighbor*, int> nei_id_map;

    /** counter of free slot ID */
    int free_count;

};


#endif // MEMSLOT_H