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(uchar * seq, uint n, alphabet_mapper * am) {
34 max_v = max(am->map((uint)seq[i]),max_v);
38 wt_coder_binary::wt_coder_binary() {}
40 wt_coder_binary::~wt_coder_binary() {}
42 bool wt_coder_binary::is_set(uint symbol, uint l) {
43 if((1<<(h-l-1))&symbol) return true;
47 bool wt_coder_binary::done(uint symbol, uint l) {
52 uint wt_coder_binary::size() {
53 return sizeof(wt_coder_binary);
56 uint wt_coder_binary::save(FILE *fp) {
57 uint wr = WT_CODER_BINARY_HDR;
58 wr = fwrite(&wr,sizeof(uint),1,fp);
59 wr += fwrite(&h,sizeof(uint),1,fp);
63 wt_coder_binary * wt_coder_binary::load(FILE *fp) {
65 if(fread(&rd,sizeof(uint),1,fp)!=1) return NULL;
66 if(rd!=WT_CODER_BINARY_HDR) return NULL;
67 wt_coder_binary * ret = new wt_coder_binary();
68 if(fread(&ret->h,sizeof(uint),1,fp)!=1) {