2 * Copyright (C) 2008, Francisco Claude, all rights reserved.
4 * wt_coder_binary definition
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
22 #include <wt_coder_binary.h>
24 wt_coder_binary::wt_coder_binary(uint * seq, uint n, alphabet_mapper * am) {
27 max_v = max(am->map(seq[i]),max_v);
31 wt_coder_binary::wt_coder_binary() {}
33 wt_coder_binary::~wt_coder_binary() {}
35 bool wt_coder_binary::is_set(uint symbol, uint l) {
36 if((1<<(h-l-1))&symbol) return true;
40 bool wt_coder_binary::done(uint symbol, uint l) {
41 if(l==h-1) return true;
45 uint wt_coder_binary::size() {
46 return sizeof(wt_coder_binary);
49 uint wt_coder_binary::save(FILE *fp) {
50 uint wr = WT_CODER_BINARY_HDR;
51 wr = fwrite(&wr,sizeof(uint),1,fp);
52 wr += fwrite(&h,sizeof(uint),1,fp);
56 wt_coder_binary * wt_coder_binary::load(FILE *fp) {
58 if(fread(&rd,sizeof(uint),1,fp)!=1) return NULL;
59 if(rd!=WT_CODER_BINARY_HDR) return NULL;
60 wt_coder_binary * ret = new wt_coder_binary();
61 if(fread(&ret->h,sizeof(uint),1,fp)!=1) {