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
22 #include <wt_node_leaf.h>
24 wt_node_leaf::wt_node_leaf(uint symbol, uint count) {
25 this->symbol = symbol;
29 wt_node_leaf::wt_node_leaf() {}
31 wt_node_leaf::~wt_node_leaf() {}
33 uint wt_node_leaf::rank(uint symbol, uint pos, uint l, wt_coder * c) {
34 if(symbol!=this->symbol) return 0;
39 uint wt_node_leaf::select(uint symbol, uint pos, uint l, wt_coder * c) {
40 if(symbol!=this->symbol) return (uint)-1;
41 if(pos==0 || pos>count) return (uint)-1;
45 uint wt_node_leaf::access(uint pos) {
49 uint wt_node_leaf::size() {
50 return sizeof(wt_node_leaf);
53 uint wt_node_leaf::save(FILE *fp) {
54 uint wr = WT_NODE_LEAF_HDR;
55 wr = fwrite(&wr,sizeof(uint),1,fp);
56 wr += fwrite(&count,sizeof(uint),1,fp);
57 wr += fwrite(&symbol,sizeof(uint),1,fp);
61 wt_node_leaf * wt_node_leaf::load(FILE *fp) {
63 if(fread(&rd,sizeof(uint),1,fp)!=1) return NULL;
64 if(rd!=WT_NODE_LEAF_HDR) return NULL;
65 wt_node_leaf * ret = new wt_node_leaf();
66 rd = fread(&(ret->count),sizeof(uint),1,fp);
67 rd += fread(&(ret->symbol),sizeof(uint),1,fp);
68 if(rd!=2) { delete ret; return NULL; }