Add TNG writing and reading support
[alexxy/gromacs.git] / src / external / tng_io / src / compression / dict.c
1 /* This code is part of the tng compression routines.
2  *
3  * Written by Daniel Spangberg
4  * Copyright (c) 2010, 2013, 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
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   *ndict=0x20004;
21 }
22
23 void Ptngc_comp_make_dict_hist(unsigned int *vals, int nvals,
24                          unsigned int *dict, int *ndict,
25                          unsigned int *hist)
26 {
27   int i;
28   int j=0;
29   for (i=0; i<0x20004; i++)
30     hist[i]=0;
31   for (i=0; i<0x20004; i++)
32     dict[i]=i;
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]=dict[i];
40         j++;
41       }
42   *ndict=j;
43 }