2 * Copyright (C) 2008, Francisco Claude, all rights reserved.
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
23 #include "table_offset.h"
26 // Interface for old implementation
27 void genera(ushort * bch, uint u, ushort * F, uint lF);
28 uint generaClase(ushort * bch, uint u, uint clase, uint puestos, uint pos_ini, uint generado);
29 uint offset_func(uint u, uint busca);
30 uint offsetRecursivo(uint u, uint busca, uint clase, uint puestos, uint pos_ini, uint generado);
34 // End interface old implementation
37 table_offset::table_offset(uint u) {
40 short_bitmaps = new ushort[((1<<u)+1)];
41 offset_class = new ushort[u+2];
42 binomial = new uint*[u+1];
43 log2binomial = new ushort*[u+1];
44 for(uint i=0;i<u+1;i++) {
45 binomial[i] = new uint[u+1];
46 log2binomial[i] = new ushort[u+1];
47 for(uint j=0;j<u+1;j++) {
49 log2binomial[i][j] = 0;
52 for(uint i=0;i<u+1;i++) {
56 log2binomial[i][0] = 0;
57 log2binomial[i][1] = 0;
58 log2binomial[i][i] = 0;
60 for(uint j=1;j<u+1;j++) {
61 for(uint i=j+1;i<u+1;i++) {
62 binomial[i][j] = binomial[i-1][j-1]+binomial[i-1][j];
63 log2binomial[i][j] = bits(binomial[i][j]-1);
69 void table_offset::fill_tables() {
70 genera(short_bitmaps, u, offset_class, u);
75 table_offset::~table_offset() {
76 delete [] short_bitmaps;
77 delete [] offset_class;
78 for(uint i=0;i<u+1;i++) {
79 delete [] binomial[i];
80 delete [] log2binomial[i];
83 delete [] log2binomial;
87 uint table_offset::size() {
88 uint ret = sizeof(ushort)*(((1<<u)+1)+u+1);
89 ret += (sizeof(uint)+sizeof(ushort))*((u+1)*(u+1));
90 ret += sizeof(ushort)*(2<<(u+1));
91 ret += sizeof(ushort)*(u+2);
95 // OLD implementation, replace
97 void genera(ushort * bch, uint u, ushort * F, uint lF) {
101 __Lis = new ushort[(2<<(u+1))]; //(uint *)malloc((2<<u+1)*sizeof(uint));
102 for (uint i=0;i<=u;i++) {
103 __indAcumulado += generaClase(bch, u, i, 0, 0, 0);
104 F[i+1] = __indiceFunc;
108 uint generaClase(ushort * bch, uint u, uint clase, uint puestos, uint pos_ini, uint generado) {
110 if (clase==puestos) {
111 bch[__indiceFunc] = generado;
112 __Lis[generado] = __indiceFunc-__indAcumulado;
118 for (uint i=pos_ini;i<u;i++) {
119 uint tmp = generado | (1<<i);
120 ret += generaClase(bch, u, clase, puestos+1, i+1, tmp);