Initial import of XMLTree
[SXSI/XMLTree.git] / libcds / src / static_sequence / wt_node_leaf.cpp
1
2 #include <wt_node_leaf.h>
3
4 wt_node_leaf::wt_node_leaf(uint symbol, uint count) {
5         this->symbol = symbol;
6         this->count = count;
7 }
8
9 wt_node_leaf::wt_node_leaf() {}
10
11 wt_node_leaf::~wt_node_leaf() {}
12
13 uint wt_node_leaf::rank(uint symbol, uint pos, uint l, wt_coder * c) {
14         assert(symbol==this->symbol);
15         pos++;
16         assert(pos<=count);
17         return pos;
18 }
19
20 uint wt_node_leaf::select(uint symbol, uint pos, uint l, wt_coder * c) {
21         assert(symbol==this->symbol);
22         assert(pos<=count && pos>0);
23         return pos;
24 }
25
26 uint wt_node_leaf::access(uint pos) {
27         assert(pos<count);
28         return symbol;
29 }
30
31 uint wt_node_leaf::size() {
32         return sizeof(wt_node_leaf);
33 }
34
35 uint wt_node_leaf::save(FILE *fp) {
36   uint wr = WT_NODE_LEAF_HDR;
37   wr = fwrite(&wr,sizeof(uint),1,fp);
38   wr += fwrite(&count,sizeof(uint),1,fp);
39   wr += fwrite(&symbol,sizeof(uint),1,fp);
40   return wr-3;
41 }
42
43 wt_node_leaf * wt_node_leaf::load(FILE *fp) {
44   uint rd;
45   if(fread(&rd,sizeof(uint),1,fp)!=1) return NULL;
46   if(rd!=WT_NODE_LEAF_HDR) return NULL;
47   wt_node_leaf * ret = new wt_node_leaf();
48   rd = fread(&(ret->count),sizeof(uint),1,fp);
49   rd += fread(&(ret->symbol),sizeof(uint),1,fp);
50   if(rd!=2) { delete ret; return NULL; }
51   return ret;
52 }