[go: up one dir, main page]

File: node.cc

package info (click to toggle)
lttoolbox 3.5.0-3
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 1,328 kB
  • sloc: cpp: 12,761; ansic: 3,589; python: 391; makefile: 71; sh: 24
file content (84 lines) | stat: -rw-r--r-- 1,710 bytes parent folder | download | duplicates (2)
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
/*
 * Copyright (C) 2005 Universitat d'Alacant / Universidad de Alicante
 *
 * 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, see <http://www.gnu.org/licenses/>.
 */
#include <lttoolbox/node.h>

Node::Node()
{
}

Node::~Node()
{
  destroy();
}

Node::Node(Node const &n)
{
  copy(n);
}

Node &
Node::operator =(Node const &n)
{
  if(this != &n)
  {
    destroy();
    copy(n);
  }
  return *this;
}

void
Node::copy(Node const &n)
{
  transitions = n.transitions;
}

void
Node::destroy()
{
}

void
Node::addTransition(int const i, int const o, Node * const d, double const wt)
{
  Dest &aux = transitions[i];
  aux.size++;
  int *out_tag = new int[aux.size];
  Node **dest = new Node*[aux.size];
  double *out_weight = new double[aux.size];

  for(int i = 0; i<aux.size-1; i++)
  {
    out_tag[i] = aux.out_tag[i];
    dest[i] = aux.dest[i];
    out_weight[i] = aux.out_weight[i];
  }

  if(aux.size > 1)
  {
    delete[] aux.out_tag;
    delete[] aux.dest;
    delete[] aux.out_weight;
  }

  out_tag[aux.size-1] = o;
  dest[aux.size-1] = d;
  out_weight[aux.size-1] = wt;
  aux.out_tag = out_tag;
  aux.dest = dest;
  aux.out_weight = out_weight;
}