2 // Implements the Map data structure, which maps block ids to lztrie nodes
6 // creates a nodemap structure from a mapping array, not owning it
7 // n is number of blocks
8 // max is the number of trie nodes
10 nodemap createNodemap(uint *map, uint n, uint max)
14 M = malloc(sizeof(struct snodemap));
15 M->nbits = bits(2*max-1);
17 M->map = malloc(((n*M->nbits+W-1)/W)*sizeof(uint));
19 bitput(M->map,i*M->nbits,M->nbits,map[i]);
23 // frees revtrie structure, including the owned data
25 void destroyNodemap(nodemap M)
33 trieNode mapto(nodemap M, uint id)
35 return bitget(M->map,id*M->nbits,M->nbits);
38 void saveNodemap(FILE *f, nodemap M)
40 fwrite(&M->nbits, sizeof(uint), 1, f);
41 fwrite(&M->n, sizeof(uint), 1, f);
42 fwrite(M->map, sizeof(uint), (M->n*M->nbits+W-1)/W, f);
45 nodemap loadNodemap(FILE *f)
49 M = malloc(sizeof(struct snodemap));
50 fread(&M->nbits, sizeof(uint), 1, f);
51 fread(&M->n, sizeof(uint), 1, f);
52 M->map = malloc(((M->n*M->nbits+W-1)/W)*sizeof(uint));
53 fread(M->map, sizeof(uint), (M->n*M->nbits+W-1)/W, f);
57 uint sizeofNodemap(nodemap M)
59 return sizeof(struct snodemap) + ((M->n*M->nbits+W-1)/W)*sizeof(uint);