1 /* This code is part of the tng compression routines.
2 *
3 * Written by Daniel Spangberg and Magnus Lundborg
4 * Copyright (c) 2010, 2013-2014 The GROMACS development team.
5 *
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the Revised BSD License.
9 */
10
11
12 #include <string.h>
13 #include "../../include/compression/dict.h"
14
Ptngc_comp_canonical_dict(unsigned int * dict,int * ndict)15 void Ptngc_comp_canonical_dict(unsigned int *dict, int *ndict)
16 {
17 int i;
18 for (i=0; i<0x20004; i++)
19 dict[i]=i;
20
21 *ndict=0x20004;
22 }
23
Ptngc_comp_make_dict_hist(unsigned int * vals,const int nvals,unsigned int * dict,int * ndict,unsigned int * hist)24 void Ptngc_comp_make_dict_hist(unsigned int *vals, const int nvals,
25 unsigned int *dict, int *ndict,
26 unsigned int *hist)
27 {
28 int i;
29 int j=0;
30
31 memset(hist, 0, sizeof(unsigned int)*0x20004);
32
33 for (i=0; i<nvals; i++)
34 hist[vals[i]]++;
35 for (i=0; i<0x20004; i++)
36 if (hist[i]!=0)
37 {
38 hist[j]=hist[i];
39 dict[j]=i;
40 j++;
41 if(j==nvals)
42 break;
43 }
44 *ndict=j;
45 }
46