-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathTable.cpp
165 lines (140 loc) · 3.84 KB
/
Table.cpp
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
/*
* Argus Open Source
* Software to apply Statistical Disclosure Control techniques
*
* Copyright 2014 Statistics Netherlands
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the European Union Public Licence
* (EUPL) version 1.1, as published by the European Commission.
*
* You can find the text of the EUPL v1.1 on
* https://joinup.ec.europa.eu/software/page/eupl/licence-eupl
*
* This software is distributed on an "AS IS" basis without
* warranties or conditions of any kind, either express or implied.
*/
#include "Table.h"
#include <assert.h>
#include <string.h>
bool CTable::SetVariables(long lnDim, long *ExplVar, long BirVarnr)
{
nDim = lnDim;
for (int i = 0; i < nDim; i++) {
Varnr[i] = ExplVar[i] - 1;
}
BIRWeightVar = BirVarnr-1;
return true;
}
bool CTable::CheckVarSequence()
{
int i;
unsigned int v = Varnr[0];
for (i = 1; i < nDim; i++) {
if (Varnr[i] <= (int) v) return false;
v = Varnr[i];
}
return true;
}
long CTable::GetMemSize()
{
long MemSizeTable,j;
MemSizeTable = 1;
for (j = 0; j < nDim; j++) {
MemSizeTable *= SizeDim[j]; // number of codes of variable
}
return MemSizeTable;
}
bool CTable::PrepareTable()
{
long MemSizeTable;
MemSizeTable = GetMemSize();
//Cell = (long *) malloc(MemSizeTable * sizeof(long) );
Cell = new long [MemSizeTable];
if (Cell == 0) {
return false;
}
if (IsBIR) {
//m_tab[i].BIRCell = (double *) malloc(MemSizeTable * sizeof(double) );
BIRCell = new double [MemSizeTable];
if (BIRCell == 0) {
return false;
}
}
nCell = MemSizeTable; // for ASSERT
// make all cells zero
memset(Cell, 0, MemSizeTable * sizeof(long) );
if (IsBIR) {
memset(BIRCell, 0, MemSizeTable * sizeof(double) );
}
return true;
}
void CTable::FreeRecodedTable()
{
if (Cell != 0) {
delete[] Cell;
}
if (BIRCell != 0) {
delete[] BIRCell;
}
Cell = 0;
BIRCell = 0;
}
long CTable::GetCellNr(int *DimNr)
{
long c = 0;
for (int i = 0; i < nDim; i++) {
assert(DimNr[i] >= 0 && DimNr[i] < SizeDim[i]);
c *= SizeDim[i];
c += DimNr[i];
}
return c;
}
/*
void CTable:: operator = (CTable & table2)
{
bool tempreturn;
int i;
Threshold = table2.Threshold;
nDim= table2.nDim; // number of variables (= dimensions) in table
//SizeDim[MAXDIM]; // = nCode of corresponding variable
//Varnr[MAXDIM]; // index of each dimension variable
for (i=0; i<MAXDIM; i++) {
SizeDim[i] = table2.SizeDim[i];
}
for (i=0; i<MAXDIM; i++) {
Varnr[i] = table2.Varnr[i];
}
//long *Cell; // counting space for frequency
nCell = table2.nCell; // number of cells
BaseTable = table2.BaseTable; // is a permanent table, specified bij SetTable?
HasRecode= table2.HasRecode; // toggle for Recode Table (index at i + m_ntab)
IsBIR = table2.IsBIR; // toggle for BaseIndividualRisk table
//double *BIRCell; // counting space for weight (BIR)
BIRThreshold= table2.BIRThreshold; // Threshold for BIR
BIRWeightVar = table2.BIRWeightVar; // index weight variable
BIRMinValue =table2.BIRMinValue;
BIRMaxValue = table2.BIRMaxValue;
BIRClassWidth = table2.BIRClassWidth ;
BIRnClasses = table2.BIRnClasses;
BIRUnsafe = table2.BIRUnsafe;
if (table2.Cell != 0) {
if (Cell != 0) {
delete[] Cell;
}
if (BIRCell != 0) {
delete[] BIRCell;
}
Cell = 0;
BIRCell = 0;
tempreturn = PrepareTable();
for (i=0; i<nCell; i++) {
Cell[i] = table2.Cell[i];
if (IsBIR)
{
BIRCell[i] = table2.BIRCell[i];
}
}
}
}
*/